/** * The O(n^3) multiplication algorithm that is here for if BLAS isn't * available, or if the dimensions wouldn't allow 1-d array indexing. * * @param m The right matrix to multiply by this * @return The result of multiplying this times m */ private Matrix slowMult( final DenseMatrix m) { DenseMatrix result = new DenseMatrix(getNumRows(), m.getNumColumns()); for (int i = 0; i < getNumRows(); i++) { for (int j = 0; j < m.getNumColumns(); j++) { double val = 0; for (int k = 0; k < getNumColumns(); k++) { val += get(i, k) * m.get(k, j); } result.setElement(i, j, val); } } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. */ @Override public final void dotTimesEquals( final DenseMatrix other) { this.assertSameDimensions(other); if (!isCompressed()) { compress(); } // The shortcut I'll take here is that few of the dense matrix's values // are zero where I'm not int rownum = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[rownum + 1]) { ++rownum; } values[i] *= other.get(rownum, columnIndices[i]); } }
/** * The O(n^3) multiplication algorithm that is here for if BLAS isn't * available, or if the dimensions wouldn't allow 1-d array indexing. * * @param m The right matrix to multiply by this * @return The result of multiplying this times m */ private Matrix slowMult( final DenseMatrix m) { DenseMatrix result = new DenseMatrix(getNumRows(), m.getNumColumns()); for (int i = 0; i < getNumRows(); i++) { for (int j = 0; j < m.getNumColumns(); j++) { double val = 0; for (int k = 0; k < getNumColumns(); k++) { val += get(i, k) * m.get(k, j); } result.setElement(i, j, val); } } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. */ @Override public final void dotTimesEquals( final DenseMatrix other) { this.assertSameDimensions(other); if (!isCompressed()) { compress(); } // The shortcut I'll take here is that few of the dense matrix's values // are zero where I'm not int rownum = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[rownum + 1]) { ++rownum; } values[i] *= other.get(rownum, columnIndices[i]); } }
/** * The O(n^3) multiplication algorithm that is here for if BLAS isn't * available, or if the dimensions wouldn't allow 1-d array indexing. * * @param m The right matrix to multiply by this * @return The result of multiplying this times m */ private Matrix slowMult( final DenseMatrix m) { DenseMatrix result = new DenseMatrix(getNumRows(), m.getNumColumns()); for (int i = 0; i < getNumRows(); i++) { for (int j = 0; j < m.getNumColumns(); j++) { double val = 0; for (int k = 0; k < getNumColumns(); k++) { val += get(i, k) * m.get(k, j); } result.setElement(i, j, val); } } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. */ @Override public final void dotTimesEquals( final DenseMatrix other) { this.assertSameDimensions(other); if (!isCompressed()) { compress(); } // The shortcut I'll take here is that few of the dense matrix's values // are zero where I'm not int rownum = 0; for (int i = 0; i < values.length; ++i) { while (i >= firstIndicesForRows[rownum + 1]) { ++rownum; } values[i] *= other.get(rownum, columnIndices[i]); } }
@Override final public Matrix transpose() { // It's the transpose of me int m = getNumColumns(); int n = getNumRows(); final DenseVector[] resultRows = new DenseVector[m]; for (int i = 0; i < m; ++i) { DenseVector row = new DenseVector(n); for (int j = 0; j < n; ++j) { row.setElement(j, get(j, i)); } resultRows[i] = row; } return new DenseMatrix(resultRows); }
@Override final public Matrix transpose() { // It's the transpose of me int m = getNumColumns(); int n = getNumRows(); final DenseVector[] resultRows = new DenseVector[m]; for (int i = 0; i < m; ++i) { DenseVector row = new DenseVector(n); for (int j = 0; j < n; ++j) { row.setElement(j, get(j, i)); } resultRows[i] = row; } return new DenseMatrix(resultRows); }
@Override final public Matrix transpose() { // It's the transpose of me int m = getNumColumns(); int n = getNumRows(); final DenseVector[] resultRows = new DenseVector[m]; for (int i = 0; i < m; ++i) { DenseVector row = new DenseVector(n); for (int j = 0; j < n; ++j) { row.setElement(j, get(j, i)); } resultRows[i] = row; } return new DenseMatrix(resultRows); }