vkostyukov / la4j

Linear Algebra for Java
http://la4j.org
Apache License 2.0
373 stars 107 forks source link

Insert Matrix\Vector into Matrix #193

Open enoonIT opened 10 years ago

enoonIT commented 10 years ago

One extremely useful thing that can be done in Matlab is to insert a matrix inside of another one: A(2:4,1:3) = B;

I've found a way to insert Vectors intro Matrices but I've failed to see a way to insert a Matrix in a Matrix in la4j (other than hand iterating the values) - how should this case be handled?

vkostyukov commented 10 years ago

I've moved this ticket to 0.6.0 release. We should think how to handle this functionality.

sylvia43 commented 9 years ago

So vectors can already be inserted into matrices? I'm just gonna implement adding matricies inside other matricies.

sylvia43 commented 9 years ago

Ok so I'm thinking something like System.arrayCopy() with a bunch of overridable methods.

vkostyukov commented 9 years ago

Wait. You can't insert matrix into vector. We have to provide methods that insert matrix into matrix. Something like this:

interface Matrix {
  Matrix insert(Matrix that, int left, int right);
}
sylvia43 commented 9 years ago

Insert matrix into matrix, that was a typo. Right now I have telescoping methods ending in this (inside the Matrix interface:

Matrix insert(Matrix matrix, int sx, int sy, int dx, int dy, int width, int height);
vkostyukov commented 9 years ago

You can use the naming convention from slice method: https://github.com/vkostyukov/la4j/blob/master/src/main/java/org/la4j/matrix/Matrix.java#L705. AI would suggest having this signature:

Matrix insert(Matrix that, int i, int j) { return insert(that, i, j, that.rows(), that.columns()); }
Matrix insert(Matrix that, int i, int j, int width, int height);

Wait, slice names don't fit well here. Use i, j, width, height.

sylvia43 commented 9 years ago

But there's both source and destination positions. What about sourceX, destX and numRows or something?

vkostyukov commented 9 years ago

Right. How about sourceRow, sourceColumn, destRow, destColumn, width, height?

sylvia43 commented 9 years ago

width/height sorta break row/column don't they? And also (related) why are rows and columns fields in AbstractMatrix? They have methods too...? Can I kill the fields (or move them down to subclasses) and just use the methods?

sylvia43 commented 9 years ago

Let's move the conversation to #222.

sylvia43 commented 9 years ago

Inserting vectors into vectors.