libmir / mir

Mir (backports): Sparse tensors, Hoffman
http://mir.libmir.org
Boost Software License 1.0
210 stars 20 forks source link

Overlapping blocks #369

Closed ljubobratovicrelja closed 7 years ago

ljubobratovicrelja commented 7 years ago

Is it possible to achieve this with current mir.ndslice.selection API? For example, I'd like to divide matrix into m-by-n blocks, but I'd like blocks to overlap by k elements, where k < m && k < n.

Something like this:

Slice!(2, float*) matrix = slice!int(6, 3);
matrix[] = [[1,  2,  3,  4,  5,  6  ],             
            [7,  8,  9,  10, 11, 12 ],
            [13, 14, 15, 16, 17, 18 ]];

assert( 
matrix.ovelappedBlocks([2, 2], 1) ==  /*(blocking shape, and overlapping length)*/
[ [ [[1, 2], [7,   8]], [[2, 3], [8,   9]], ...],
  [ [[7, 8], [13, 14]], [[8, 9], [14, 15]] ....]] ); 

Hope example is understandable. :)

ljubobratovicrelja commented 7 years ago

I've been trying to achieve this for few hours, and just after posting the issue here I got the solution - matrix.windows(m, n).strided!(0, 1)(k, k) seems to be doing the job.

Sorry for spamming.

thewilsonator commented 7 years ago

Maybe put this in the docs somewhere?

ljubobratovicrelja commented 7 years ago

Well, in blocks' documentation it's clearly noted it's non-ovelapping blocking of tensor. My first hint was to look around blocks, and wasn't thinking even remotely windows would solve the problem. And that is most probably the reason for my confusion, and why I was not able to come up with a solution for a period of time.

So, maybe a hint in the blocks description about this would be good. Also an unittest example on this in windows section. @9il @thewilsonator if you both agree, I would like to add this.

9il commented 7 years ago

agree, please open a Phobos PR

ljubobratovicrelja commented 7 years ago

agree, please open a Phobos PR

Will do, tnx.