Formal Review of std.range.ndslice

Ilya Yaroshenko via Digitalmars-d digitalmars-d at puremagic.com
Sun Dec 13 07:59:19 PST 2015


On Sunday, 13 December 2015 at 15:25:11 UTC, Stefan Frijters 
wrote:
> On Friday, 11 December 2015 at 22:56:15 UTC, Ilya wrote:
>> On Friday, 11 December 2015 at 19:31:14 UTC, Stefan Frijters 
>> wrote:
>>> [...]
>>
>>     Slice!(N, T*) arr;
>>
>>>     [...]
>>
>>       // compute length
>>       // more flexible construtors would be added after
>>       // allocatrs support for ndslice
>>       size_t len = 1;
>>       foreach(l; lengths)
>>          len *= l;
>>
>>       arr = new T[len].sliced(lengths);
>>
>>> [...]
>>
>>    std.experimental.ndslice.selection: indexSlice, byElement;
>>
>>    foreach(p; someField.shape.indexSlice.byElement) {
>>    	  someField[p] = foo(someOtherField[bar(p)]);
>>           ...
>>    }
>>
>>> [...]
>>
>> See also updated docs: 
>> http://dtest.thecybershadow.net/artifact/website-13cbdcf17d84fc31328c3f517a56bea783c418d6-d9c63e815273f0906309088334e7dfb1/web/phobos-prerelease/std_experimental_ndslice.html
>>
>> Ilya
>
> Thank you for your help. I'm trying to convert my code again at 
> the moment, but ran into a new problem: I need to pass a 
> pointer to the data into a C function. It seems that the .ptr 
> property is not available, and using & caused dmd to segfault 
> (currently running a Dustmite reduction for that). Is there any 
> clean way to get a pointer to the underlying data?

Could you please post reduced code example that caused dmd to 
segfault?

2D way: &slice[0, 0]   or   &(slice.front.front());

ND way: &(slice.byElement.front())

Note: Comparing with unstandard  there is no guarantee that the 
first element in a ndarray is the first element in memory. 
`reversed` and `allReversed` should not be used to preserve 
strides positive.

The latests docs (with fixed English): 
http://dtest.thecybershadow.net/artifact/website-13cbdcf17d84fc31328c3f517a56bea783c418d6-dd2292a424959b594956eeeba64d391f/web/phobos-prerelease/std_experimental_ndslice.html

Voting For std.experimental.ndslice 
http://forum.dlang.org/post/ztaudqxmjrgnilsioyqs@forum.dlang.org
Please Vote!

Ilya


More information about the Digitalmars-d mailing list