adamaulia / efficient-java-matrix-library

Automatically exported from code.google.com/p/efficient-java-matrix-library
0 stars 0 forks source link

Add row and column methods to CommonOps #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Although easy to implement, it would be of convenience to have methods in 
CommonOps that return a vector with either the row totals or the column totals 
of a Matrix.

Original issue reported on code.google.com by b.broeks...@gmail.com on 30 May 2011 at 12:14

GoogleCodeExporter commented 9 years ago
An easy way (but perhaps naive, performance wise) is:

public static SimpleMatrix rowTotals(SimpleMatrix A) { 
        SimpleMatrix l = new SimpleMatrix(1, A.numCols()); 
        l.set(1.0); 
        return l.mult(A.transpose()).transpose(); 
} 

public static SimpleMatrix columnTotals(SimpleMatrix A) { 
        SimpleMatrix l = new SimpleMatrix(1, A.numRows()); 
        l.set(1.0); 
        return l.mult(A).transpose(); 
} 

Which is a simple trick to get the totals. The final transpose is 
there just to get vertical vectors in stead of horizontal ones. I'm 
not sure if this is the most efficient way in ejml or if iteration is 
faster. Feel free to reuse. 

Original comment by b.broeks...@gmail.com on 30 May 2011 at 12:15

GoogleCodeExporter commented 9 years ago
I remember you mentioned this before.  I'll add something similar to CommonOps.

Original comment by peter.ab...@gmail.com on 1 Jun 2011 at 11:23

GoogleCodeExporter commented 9 years ago
Similar functions have been added to CommonOps.  Take a look at sumRows() and 
sumCols() in common ops.  A more direct method was used to compute the output 
which should be faster.

Original comment by peter.ab...@gmail.com on 11 Jun 2011 at 5:52

GoogleCodeExporter commented 9 years ago
Assuming that the functions added are sufficient.  Will reopen if this is not 
the case.

Original comment by peter.ab...@gmail.com on 22 Jun 2011 at 6:50