Upsurge icon indicating copy to clipboard operation
Upsurge copied to clipboard

How can I compute sum of a slice of matrix?

Open keunwoochoi opened this issue 7 years ago • 2 comments

// S is a Matrix
sum(S[0..<1, 5..<10])? // doesn't work because MatrixSlice is not LinearType

Is there a workaround for it?

Ultimately, it would be easier to maintain I guess if there are less number of data types, e.g., everything is ndarray in numpy.. until then, hopefully more documents to come! ReadTheDocs would be perfect, but simple readme.mds would do the work pretty well, too, for APIs/inheritance/etc. I'm up for contributing to it if there's anything I can.

keunwoochoi avatar Feb 19 '18 23:02 keunwoochoi

It doesn't work because it is a 2D data structure (QuadraticType) but sum expects a 1D data structure (LinearType). You would need to flatten it first. I think it would be good to have a flatten method on TensorTypes to convert to an array.

I'll look into ReadTheDocs, it already has some docs in the code it's just a matter of running Jazzy on it. I do think it could use some simplification, but it's always a compromise between performance and convenience.

alejandro-isaza avatar Feb 20 '18 05:02 alejandro-isaza

think it would be good to have a flatten method

Agreed!

ReadTheDocs

I think so, at the moment RTD could be a burden. I'll keep the hackmd document updated, could be useful later :)

keunwoochoi avatar Feb 20 '18 10:02 keunwoochoi