| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void multiply(Vec b, double z, Vec c) |
| 103 | { |
| 104 | if(this.cols() != b.length()) |
| 105 | throw new ArithmeticException("Matrix dimensions do not agree, [" + rows() +"," + cols() + "] x [" + b.length() + ",1]" ); |
| 106 | if(this.rows() != c.length()) |
| 107 | throw new ArithmeticException("Target vector dimension does not agree with matrix dimensions. Matrix has " + rows() + " rows but tagert has " + c.length()); |
| 108 | |
| 109 | for(int i = 0; i < rows(); i++) |
| 110 | { |
| 111 | //The Dense construcure does not clone the matrix, it just takes the refernce -making it fast |
| 112 | DenseVector row = new DenseVector(matrix[i]); |
| 113 | c.increment(i, row.dot(b)*z);//We use the dot product in this way so that if the incoming matrix is sparce, we can take advantage of save computaitons |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void transposeMultiply(double c, Vec b, Vec x) |