The Matrix to end all Matrix classes (Let's dream!)

Dan murpsoft at hotmail.com
Tue Nov 20 21:01:51 PST 2007


Bill Baxter Wrote:
> 
> :-) What about the other end?  How do you define the opSlice that gets 
> called by every possible combination of N-dimensional slices and indices 
> like
>     [1..2, N, 4..7]
> One way to extend the current syntax would be if there's any .., in an 
> argument then all arguments are treated as slices, and a single number 
> argument would be treated as N..N+1.  So the above would call 
> opSlice(1,2, N,N+1, 4,7)
> 
> Another more general solution would be to have 1..2 result in a slice 
> object.  So the above would be like calling 
> opSlice(slice(1,2),slice(N,N+1),slice(4,7))

I would certainly agree that the [n,n] notation seems to have some major limitations with regards to the other features of D.  If they're fixing them, awesome.

The way I had thought to achieve this is to use [1..2][0..$][4..7].  This is arrays of arrays, which I suppose isn't quite as efficient but would allow slicing multiple ways and you could accomplish alot of cool stuff with that.

Heck, if you use [0..i][($-i)..($-i+1)][3] you can even get diagonal profiles on a matrix any way you wanna cut it.

You don't have to worry about opSlice weirdness or much else.  You also don't need templates or classes or any wizardry to get 90% of the stuff you want out of it.

Instead of boxes or templates to handle the type nastiness, I recommend using some parts of my Value struct from Walnut - it's BSD licensed and will let you do different stuff to different types at runtime.  That will matter because values in a matrix can be non-numerical.



More information about the Digitalmars-d mailing list