Closed timotheecour closed 7 years ago
auto lazy_slice = indexSlice(3, 4).ndMap!(index => index[0] * index[1]);
http://docs.mir.dlang.io/latest/mir_ndslice_selection.html#indexSlice
http://docs.mir.dlang.io/latest/mir_ndslice_algorithm.html#ndMap
Does it work for you?
auto lazy_slice = indexSlice(3, 4).ndMap!(index => index[0] * index[1]); http://docs.mir.dlang.io/latest/mir_ndslice_selection.html#indexSlice http://docs.mir.dlang.io/latest/mir_ndslice_algorithm.html#ndMap
Does it work for you?
@timotheecour can I close it?
I still think this is a very useful shortcut, especially with the string lambda syntax.
Also, the provided indexSlice only works for fully expanded index, and for eg doesn't allow lambdaSlice!"a"(3,4)
lambdaSlice!"a"(3,4)
indexSlice(3, 4).ndMap!"a[0]"
for me it looks weird to add []
each time
for me it looks weird to add [] each time
ndMap could accept tuples of indexes:
indexSlice(3, 4).ndMap!"a+b"
indexSlice(3, 4).ndMap!((a,b)=>a+b)
but ya, lambdaSlice can probably be implemented based on indexSlice and ndMap (unless it's more efficient to do it directly).
Current syntaxes:
ndiota(3, 4).map!"a[0]+a[1]"
ndiota(3, 4).map!((index)=>index[0] + index[1])
See also new cartesian
and linspace
.
I would really like this feature, seems quite elegant: