@Override final public int getNumColumns() { return (rows == null) ? 0 : (rows.length == 0) ? 0 : rows[0].getDimensionality(); }
@Override final public int getNumColumns() { return (rows == null) ? 0 : (rows.length == 0) ? 0 : rows[0].getDimensionality(); }
@Override final public int getNumColumns() { return (rows == null) ? 0 : (rows.length == 0) ? 0 : rows[0].getDimensionality(); }
@Override public final Matrix outerProduct( final DenseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); final DenseVector[] rows = new DenseVector[numRows]; for (int i = 0; i < numRows; ++i) { DenseVector row = new DenseVector(numCols); for (int j = 0; j < numCols; ++j) { row.values[j] = values[i] * other.values[j]; } rows[i] = row; } return new DenseMatrix(rows); }
@Override public final Matrix outerProduct( final DenseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); final DenseVector[] rows = new DenseVector[numRows]; for (int i = 0; i < numRows; ++i) { DenseVector row = new DenseVector(numCols); for (int j = 0; j < numCols; ++j) { row.values[j] = values[i] * other.values[j]; } rows[i] = row; } return new DenseMatrix(rows); }
@Override public final Matrix outerProduct( final DenseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); final DenseVector[] rows = new DenseVector[numRows]; for (int i = 0; i < numRows; ++i) { DenseVector row = new DenseVector(numCols); for (int j = 0; j < numCols; ++j) { row.values[j] = values[i] * other.values[j]; } rows[i] = row; } return new DenseMatrix(rows); }
/** * Package private optimized constructor that allows creation of a matrix * from the given rows. * * This is an optimized constructor for within package only. Don't call this * unless you are -super- careful. * * @param rows The array of rows for the matrix. Each row must be the same * length. */ DenseMatrix( final DenseVector[] rows) { super(); final int numRows = rows.length; if (numRows > 0) { final int numColumns = rows[0].getDimensionality(); for (int i = 1; i < numRows; i++) { rows[i].assertDimensionalityEquals(numColumns); } } this.rows = rows; initBlas(); }
/** * Package private optimized constructor that allows creation of a matrix * from the given rows. * * This is an optimized constructor for within package only. Don't call this * unless you are -super- careful. * * @param rows The array of rows for the matrix. Each row must be the same * length. */ DenseMatrix( final DenseVector[] rows) { super(); final int numRows = rows.length; if (numRows > 0) { final int numColumns = rows[0].getDimensionality(); for (int i = 1; i < numRows; i++) { rows[i].assertDimensionalityEquals(numColumns); } } this.rows = rows; initBlas(); }
/** * Package private optimized constructor that allows creation of a matrix * from the given rows. * * This is an optimized constructor for within package only. Don't call this * unless you are -super- careful. * * @param rows The array of rows for the matrix. Each row must be the same * length. */ DenseMatrix( final DenseVector[] rows) { super(); final int numRows = rows.length; if (numRows > 0) { final int numColumns = rows[0].getDimensionality(); for (int i = 1; i < numRows; i++) { rows[i].assertDimensionalityEquals(numColumns); } } this.rows = rows; initBlas(); }
@Override public final Matrix outerProduct( final DenseVector other) { compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); // This is debatable. The issue is that each row is likely to be dense, // but many rows are likely to be completely empty. My current thinking // is that storing the empty rows as dense vectors is a complete waste, // and the additional overehead of storing the dense rows as sparse // vectors is decreased when the sparse matrix is optimized. SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < numCols; ++j) { row.elements.put(j, new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final DenseVector other) { compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); // This is debatable. The issue is that each row is likely to be dense, // but many rows are likely to be completely empty. My current thinking // is that storing the empty rows as dense vectors is a complete waste, // and the additional overehead of storing the dense rows as sparse // vectors is decreased when the sparse matrix is optimized. SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < numCols; ++j) { row.elements.put(j, new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final DenseVector other) { compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); // This is debatable. The issue is that each row is likely to be dense, // but many rows are likely to be completely empty. My current thinking // is that storing the empty rows as dense vectors is a complete waste, // and the additional overehead of storing the dense rows as sparse // vectors is decreased when the sparse matrix is optimized. SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < numCols; ++j) { row.elements.put(j, new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }