@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) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); 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 < other.indices.length; ++j) { row.elements.put(other.indices[j], new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); 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 < other.indices.length; ++j) { row.elements.put(other.indices[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) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); 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 < other.indices.length; ++j) { row.elements.put(other.indices[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; }