Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 02:43:37 UTC, data pulverizer wrote: How do I unravel a sliced item T[].sliced(...) to an array T[]? For instance: import std.experimental.ndslice; auto slice = new int[12].sliced(3, 4); int[] x = ??; Thanks A slice is just a _view_ on your memory, the easiest w

Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 02:50:30 UTC, Seb wrote: On Wednesday, 15 June 2016 at 02:43:37 UTC, data pulverizer wrote: How do I unravel a sliced item T[].sliced(...) to an array T[]? For instance: import std.experimental.ndslice; auto slice = new int[12].sliced(3, 4); int[] x = ??; Thanks

Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) thanks, now I can go to bed! You are welcome. Sleep tig

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) t

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to creat

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 07:45:12 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missin

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling eleme

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:56:15 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement)

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R and D's cblas adaptor and ndslice. n = 4000 Matrices: A, B Sizes: b

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 11:19:20 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R a

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my machine now both scripts take 1.5s when compiled with I didn't ben

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
Oh, I didn't see that runif now returns a tuple.

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my m

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer And where can I find more cool tricks like that? Browse the source code and the unittests. Phobos is an amazing resource :) Very true! That's great many thanks!

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: ``` T[] a = slice.ptr[0.. slice.elementsCount]; ``` This would work only for slices with continuous memory representation and positive strides. -- Ilya