Vector operations optimization.

2012-03-21 Thread Comrad
I'd like to try d in computational physics. One of the most appealing features of the d is implementation of arrays, but to be really usable this has to work FAST. So here http://dlang.org/arrays.html it is stated, that: "Im­ple­men­ta­tion note: many of the more com­mon vec­tor op­er­a­tions

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Jesse Phillips
On Wednesday, 21 March 2012 at 20:13:37 UTC, Jesse Phillips wrote: Note, I commented out reduce as it uses the array type instead of the calculation type. I think I'll file than as a bug. Also the reduce version would not give you a double back even if it did work, need a cast in there. Neve

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Jesse Phillips
On Wednesday, 21 March 2012 at 17:02:05 UTC, Brian Brady wrote: As per the commented section, I want to be able to dynamically figure out, which member of the struct to average across, for all the structs in the array. Timon has given you an good example to get D to generate some code for yo

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Brian Brady
Thanks for the replies. Timons reply answers my question ... now I just have to figure out how :P

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
David Nadlinger: I don't think this will ever be supported (without using opDispatch) – para is a runtime value here… David Right, right, sorry, I meant a compile time argument. And even that, it's not clear what arr[].foo means. Maybe a lazy Range of that field, that is a lazy column. B

Re: Calculating/Averaging over a struct value

2012-03-21 Thread David Nadlinger
On Wednesday, 21 March 2012 at 18:11:11 UTC, bearophile wrote: Brian Brady: // but if I write x[].para if throws an error This is a quite natural syntax, and I think it's handy, but it's not supported yet. I don't think this will ever be supported (without using opDispatch) – para is a ru

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
Brian Brady: // but if I write x[].para if throws an error This is a quite natural syntax, and I think it's handy, but it's not supported yet. Bye, bearophile

Re: anonymous static array

2012-03-21 Thread Stephan
Thanks everyone. OK, so a temporary variable seems to be the most obvious workaround, thanks Jesse. Thanks also to the others in pointing out this issue. All the best, Stephan On Wednesday, 21 March 2012 at 14:19:03 UTC, Jesse Phillips wrote: On Wednesday, 21 March 2012 at 10:51:05 UTC, Ste

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Timon Gehr
#! /usr/bin/rdmd import std.array; import std.csv; import std.stdio; import std.string; struct Data{ string Date; double d1; double d2; int i4; } double average(Data[] x, string para){ double result = 0.0; theswitch:switch(strip(para)){ foreach(member;__trait

Re: Question about using regex

2012-03-21 Thread Dmitry Olshansky
On 21.03.2012 21:13, Dmitry Olshansky wrote: On 21.03.2012 20:05, James Oliphant wrote: While following the regex discussion, I have been compiling the examples to help with my understanding of how it works. From Dmitry's example page: http://blackwhale.github.com/regular-expression.html and fr

Re: Question about using regex

2012-03-21 Thread Dmitry Olshansky
On 21.03.2012 20:05, James Oliphant wrote: While following the regex discussion, I have been compiling the examples to help with my understanding of how it works. From Dmitry's example page: http://blackwhale.github.com/regular-expression.html and from the dlang.org website: htt

Calculating/Averaging over a struct value

2012-03-21 Thread Brian Brady
All This might be relatively trivial so please point me at documentation to read if it is. I am creating an array of Structs(is this the best thing to do) as per the example below. #! /usr/bin/rdmd import std.array; import std.csv; import std.stdio; import std.string; struct Data { string Dat

Re: anonymous static array

2012-03-21 Thread H. S. Teoh
On Wed, Mar 21, 2012 at 04:15:18PM +0100, bearophile wrote: > Jesse Phillips: > > >int[100][string] counts; > >int[100] a; > >counts["some_key"] = a; > >counts["some_key"][20]++; > > Someone is currently trying to improve/fix AAs, this seems a > problem that is worth trying removi

Re: Converting C .h Files to D Modules

2012-03-21 Thread Timon Gehr
On 03/20/2012 07:01 PM, Pedro Lacerda wrote: Hi all, How to convert the following struct to D? typedef struct S { int type; void *obj; } S; I didn't found anything at http://dlang.org/htomodule.html. (Assuming your 'int' is 32 bits) struct S{ int type; void* obj; }

Question about using regex

2012-03-21 Thread James Oliphant
While following the regex discussion, I have been compiling the examples to help with my understanding of how it works. >From Dmitry's example page: http://blackwhale.github.com/regular-expression.html and from the dlang.org website: http://dlang.org/phobos/std_regex.html std.reg

Re: anonymous static array

2012-03-21 Thread bearophile
Jesse Phillips: int[100][string] counts; int[100] a; counts["some_key"] = a; counts["some_key"][20]++; Someone is currently trying to improve/fix AAs, this seems a problem that is worth trying removing. Bye, bearophile

Re: anonymous static array

2012-03-21 Thread Vijay Nayar
Jesse's solution is correct, but I thought I'd throw in a comment or two. You are correct that the associative array is uninitialized by default, and that you must initialize it. For very small static arrays, a simple array literal like [1, 2, 3] would suffice, but for larger arrays, this is a p

Re: anonymous static array

2012-03-21 Thread Jesse Phillips
On Wednesday, 21 March 2012 at 10:51:05 UTC, Stephan wrote: Hi, I have an associative array with strings as keys and static arrays as values. When I access a new key, it gives me Range Error, so I think I should initialise the associative array, but how? here is the code that fails: int[10

Re: anonymous static array

2012-03-21 Thread David
Am 21.03.2012 11:51, schrieb Stephan: Hi, I have an associative array with strings as keys and static arrays as values. When I access a new key, it gives me Range Error, so I think I should initialise the associative array, but how? here is the code that fails: int[100][string] counts; counts[

anonymous static array

2012-03-21 Thread Stephan
Hi, I have an associative array with strings as keys and static arrays as values. When I access a new key, it gives me Range Error, so I think I should initialise the associative array, but how? here is the code that fails: int[100][string] counts; counts["some_key"][20]++; // core.exceptio