lessthanoptimal / ejml

A fast and easy to use linear algebra library written in Java for dense, sparse, real, and complex matrices.
https://ejml.org
551 stars 117 forks source link

Support for matrix projections #61

Open kboom opened 4 years ago

kboom commented 4 years ago

Assume we have a 2D matrix A with A1xA2 dimensions. Assume we have a 2D matrix B with B1xB2 dimensions where B1<A1 and B2<A2. Basically B "fits in" A.

Then I don't think there is a way to add B to a sub matrix (same size) of A efficiently. This rather popular operation in certain types of algorithms (which use merging and elimination of matrices). Note that this has been implemented in other libraries by using "projections" or "views". You just select a sub matrix of A without making any copies and then use it to do normal additions. You then can just dispose of the view because the data gets updated properly - and you can use all the normal operators you'd use (although only some of them probably make sense).

Please see Breeze.

lessthanoptimal commented 4 years ago

Do you just need to be able to basic operations, like addition, subtraction, and other element-wise ops?

To keep things simple sub-matrices were not included in EJML by design. I could create a wrapper class, but that would have a noticeable speed hit. Having the implementation create a local copy of the inner matrix might be faster and would have full access to all operations.

lessthanoptimal commented 4 years ago

Would having a function call that lets you do element-wise operations in inner matrices do what you need? @kboom