@Override public void setQuick(int row, int column, double value) { if (columnVectors[column] == null) { columnVectors[column] = new RandomAccessSparseVector(rowSize()); } columnVectors[column].setQuick(row, value); }
@Override public Matrix like() { return new SparseColumnMatrix(rowSize(), columnSize()); }
/** * Construct a matrix of the given cardinality * * @param rows # of rows * @param columns # of columns */ public SparseColumnMatrix(int rows, int columns) { super(rows, columns); this.columnVectors = new RandomAccessSparseVector[columnSize()]; for (int col = 0; col < columnSize(); col++) { this.columnVectors[col] = new RandomAccessSparseVector(rowSize()); } }
@Override public Matrix assignColumn(int column, Vector other) { if (rowSize() != other.size()) { throw new CardinalityException(rowSize(), other.size()); } if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } columnVectors[column].assign(other); return this; }
@Override public String toString() { int row = 0; int maxRowsToDisplay = 10; int maxColsToDisplay = 20; int colsToDisplay = maxColsToDisplay; if(maxColsToDisplay > columnSize()){ colsToDisplay = columnSize(); } StringBuilder s = new StringBuilder("{\n"); for (MatrixSlice next : this.transpose()) { if (row < maxRowsToDisplay) { s.append(" ") .append(next.index()) .append(" =>\t") .append(new VectorView(next.vector(), 0, colsToDisplay)) .append('\n'); row++; } } String returnString = s.toString(); if (maxColsToDisplay <= columnSize()) { returnString = returnString.replace("}", " ... }"); } if (maxRowsToDisplay <= rowSize()) { return returnString + "... }"; } else { return returnString + "}"; } }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } for (int col = 0; col < columnSize(); col++) { columnVectors[col].setQuick(row, other.getQuick(col)); } return this; }
@Override public void setQuick(int row, int column, double value) { if (columnVectors[column] == null) { columnVectors[column] = new RandomAccessSparseVector(rowSize()); } columnVectors[column].setQuick(row, value); }
@Override public void setQuick(int row, int column, double value) { if (columnVectors[column] == null) { columnVectors[column] = new RandomAccessSparseVector(rowSize()); } columnVectors[column].setQuick(row, value); }
@Override public Matrix like() { return new SparseColumnMatrix(rowSize(), columnSize()); }
@Override public Matrix like() { return new SparseColumnMatrix(rowSize(), columnSize()); }
/** * Construct a matrix of the given cardinality * * @param rows * @param columns */ public SparseColumnMatrix(int rows, int columns) { super(rows, columns); this.columnVectors = new RandomAccessSparseVector[columnSize()]; for (int col = 0; col < columnSize(); col++) { this.columnVectors[col] = new RandomAccessSparseVector(rowSize()); } }
/** * Construct a matrix of the given cardinality * * @param rows # of rows * @param columns # of columns */ public SparseColumnMatrix(int rows, int columns) { super(rows, columns); this.columnVectors = new RandomAccessSparseVector[columnSize()]; for (int col = 0; col < columnSize(); col++) { this.columnVectors[col] = new RandomAccessSparseVector(rowSize()); } }
@Override public Matrix assignColumn(int column, Vector other) { if (rowSize() != other.size()) { throw new CardinalityException(rowSize(), other.size()); } if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } columnVectors[column].assign(other); return this; }
@Override public String toString() { int row = 0; int maxRowsToDisplay = 10; int maxColsToDisplay = 20; int colsToDisplay = maxColsToDisplay; if(maxColsToDisplay > columnSize()){ colsToDisplay = columnSize(); } StringBuilder s = new StringBuilder("{\n"); for (MatrixSlice next : this.transpose()) { if (row < maxRowsToDisplay) { s.append(" ") .append(next.index()) .append(" =>\t") .append(new VectorView(next.vector(), 0, colsToDisplay)) .append('\n'); row++; } } String returnString = s.toString(); if (maxColsToDisplay <= columnSize()) { returnString = returnString.replace("}", " ... }"); } if (maxRowsToDisplay <= rowSize()) { return returnString + "... }"; } else { return returnString + "}"; } }
@Override public Matrix assignColumn(int column, Vector other) { if (rowSize() != other.size()) { throw new CardinalityException(rowSize(), other.size()); } if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } columnVectors[column].assign(other); return this; }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } for (int col = 0; col < columnSize(); col++) { columnVectors[col].setQuick(row, other.getQuick(col)); } return this; }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } for (int col = 0; col < columnSize(); col++) { columnVectors[col].setQuick(row, other.getQuick(col)); } return this; }