Re: Casting MapResult

2015-06-23 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 10:50:51 UTC, John Colvin wrote: If I remember correctly, core.simd should work with every compiler on every supported OS. What did you try that didn't work? I figured out the issue! You have to compile using the -m64 flag to get it to work on Windows (this works

Re: Casting MapResult

2015-06-23 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 01:27:21 UTC, jmh530 wrote: On Tuesday, 16 June 2015 at 16:37:35 UTC, John Colvin wrote: If you want really fast exponentiation of an array though, you want to use SIMD. Something like http://www.yeppp.info would be easy to use from D. I've been looking into SIMD a

Re: Casting MapResult

2015-06-22 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 16:37:35 UTC, John Colvin wrote: If you want really fast exponentiation of an array though, you want to use SIMD. Something like http://www.yeppp.info would be easy to use from D. I've been looking into SIMD a little. It turns out that core.simd only works for DMD

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
Err...vectors not matrices.

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 16:38:55 UTC, John Colvin wrote: What OS are you on? See http://wiki.dlang.org/Compilers I'm on Windows 7 at work, and I have both Win7 and linux at home. I figure I can try it on linux at home. Sometimes the work computer is a bit funky with installing things, so

Re: Casting MapResult

2015-06-16 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 14:43:17 UTC, jmh530 wrote: On Tuesday, 16 June 2015 at 13:15:05 UTC, John Colvin wrote: *consistent as in different implementations performing very similarly instead of seeing big differences like you have here. That's a good point. I tried numpy's exp (which us

Re: Casting MapResult

2015-06-16 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 14:43:17 UTC, jmh530 wrote: On Tuesday, 16 June 2015 at 13:15:05 UTC, John Colvin wrote: *consistent as in different implementations performing very similarly instead of seeing big differences like you have here. That's a good point. I tried numpy's exp (which us

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 13:15:05 UTC, John Colvin wrote: *consistent as in different implementations performing very similarly instead of seeing big differences like you have here. That's a good point. I tried numpy's exp (which uses C at a low level, I think) and found it takes about a

Re: Casting MapResult

2015-06-16 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 13:06:58 UTC, jmh530 wrote: On Monday, 15 June 2015 at 22:40:31 UTC, Baz wrote: Right, my bad. This one whould work: --- float[] test(float[] x) { auto result = x.dup; result.each!((ref a) => (a = exp(a))); return result; } --- That works. Thanks. I d

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 22:40:31 UTC, Baz wrote: Right, my bad. This one whould work: --- float[] test(float[] x) { auto result = x.dup; result.each!((ref a) => (a = exp(a))); return result; } --- That works. Thanks. I did some benchmarking and found that map tended to be fast

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 12:44 PM, jmh530 wrote: > On Monday, 15 June 2015 at 19:32:12 UTC, Baz wrote: >> Ah sorry it's you the OP. just get it. So you wanted greedy, didn't you ? > > I suppose I would want whichever has the best performance. Without > testing, I'm not sure which one would be better. Tho

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 20:10:30 UTC, jmh530 wrote: I suppose I would want whichever has the best performance. Without testing, I'm not sure which one would be better. Thoughts? I had been fighting with the map results because I didn't realize there was an easy way to get just the array.

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I suppose I would want whichever has the best performance. Without testing, I'm not sure which one would be better. Thoughts? I had been fighting with the map results because I didn't realize there was an easy way to get just the array. I'm actually not having much luck with your original fu

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:32:12 UTC, Baz wrote: On Monday, 15 June 2015 at 19:30:08 UTC, Baz wrote: On Monday, 15 June 2015 at 19:22:31 UTC, jmh530 wrote: On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): ---

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:22:31 UTC, jmh530 wrote: On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): --- float[] _exp(float[] x) { auto result = x.dup; result.each!(a => exp(a)); return result; } ---

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:30:08 UTC, Baz wrote: On Monday, 15 June 2015 at 19:22:31 UTC, jmh530 wrote: On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): --- float[] _exp(float[] x) { auto result = x.dup;

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): --- float[] _exp(float[] x) { auto result = x.dup; result.each!(a => exp(a)); return result; } --- Am I right that the difference is that map is lazy an

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: I wrote a simple function to apply map to a float dynamic array auto exp(float[] x) { auto y = x.map!(a => exp(a)); return y; } However, the type of the result is MapResult!(__lambda2, float[]). It seems like some of the th

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 17:07:55 +, jmh530 wrote: > I have a little bit of a follow up. > > After making the recommended changes, the function seems to work with > both static and dynamic arrays. I then noticed that all of the examples > for functions that pass arrays in http://dlang.org/function

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I have a little bit of a follow up. After making the recommended changes, the function seems to work with both static and dynamic arrays. I then noticed that all of the examples for functions that pass arrays in http://dlang.org/function.html use the dynamic array notation like my function ab

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 09:39 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= " wrote: writeln(y.sum);// same as sum(y) } An equivalent of the last line: writeln(reduce!((result, a) => result + a)(y)); `sum` is better for floating-point ranges, because it uses pair-wise or Kahan summation if possible

Re: Casting MapResult

2015-06-15 Thread via Digitalmars-d-learn
On Monday, 15 June 2015 at 16:16:00 UTC, Ali Çehreli wrote: On 06/15/2015 08:21 AM, Adam D. Ruppe wrote: > don't call .array if you don't have to, chaining calls to > map and such, even foreach(item; some_map_result) can be done without > actually building the array and can give more efficiency.

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 08:21 AM, Adam D. Ruppe wrote: > don't call .array if you don't have to, chaining calls to > map and such, even foreach(item; some_map_result) can be done without > actually building the array and can give more efficiency. To add, the OP can use 'sum' or 'reduce' for "adding them t

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
Thank you all for the very fast answers. It looks like that works.

Re: Casting MapResult

2015-06-15 Thread wobbles via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: float[] exp(float[] x) { auto y = x.map!(a => exp(a)); cast(float[]) y; return y; } Also, I dont think your functions will work? Your recursively calling "exp" in your map, but with a 'float' instead of 'float[]'

Re: Casting MapResult

2015-06-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: So I suppose I have two questions: 1) am I screwing up the cast, or is there no way to convert the MapResult to float[] Don't cast it, just slap a .array on the end after importing std.range. Like so: import std.algorithm; import std.ran

Re: Casting MapResult

2015-06-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: > So I suppose I have two questions: 1) am I screwing up the cast, or is > there no way to convert the MapResult to float[], 2) should I just not > bother with map (I wrote an alternate, longer, version that doesn't use > map but returns float[] pr

Re: Casting MapResult

2015-06-15 Thread anonymous via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: float[] exp(float[] x) { auto y = x.map!(a => exp(a)); cast(float[]) y; return y; } But I get an error that I can't convert MapResult!(__lambda2, float[]) to float[]. So I suppose I have two questions: 1) am I scre

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: you shouldn't cast it like that. use `std.array.array` to get the actual array. like this: import std.array; auto y = x.map!(a => exp(a)).array; the thing is that `map` returns so-called "lazy range". lazy ranges trying to not do any work

Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I wrote a simple function to apply map to a float dynamic array auto exp(float[] x) { auto y = x.map!(a => exp(a)); return y; } However, the type of the result is MapResult!(__lambda2, float[]). It seems like some of the things that I might do to a float[], I can't do to this t