| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void multiply(Vec b, double z, Vec c) |
| 127 | { |
| 128 | if(this.cols() != b.length()) |
| 129 | throw new ArithmeticException("Matrix dimensions do not agree, [" + rows() +"," + cols() + "] x [" + b.length() + ",1]" ); |
| 130 | if(this.rows() != c.length()) |
| 131 | throw new ArithmeticException("Target vector dimension does not agree with matrix dimensions. Matrix has " + rows() + " rows but tagert has " + c.length()); |
| 132 | |
| 133 | if (b.isSparse()) |
| 134 | { |
| 135 | for (int i = 0; i < rows(); i++) |
| 136 | { |
| 137 | double dot = 0; |
| 138 | for(IndexValue iv : b) |
| 139 | dot += this.get(i, iv.getIndex()) * iv.getValue(); |
| 140 | c.increment(i, dot * z); |
| 141 | } |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | for (int i = 0; i < rows(); i++) |
| 146 | { |
| 147 | double dot = 0; |
| 148 | for (int j = 0; j < cols(); j++) |
| 149 | dot += this.get(i, j) * b.get(j); |
| 150 | c.increment(i, dot * z); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public void multiply(Matrix b, Matrix C) |