@Override public double dot(Vector x) { if (size != x.size()) { throw new CardinalityException(size, x.size()); } if (this == x) { return getLengthSquared(); } return aggregate(x, Functions.PLUS, Functions.MULT); }
@Override public Vector plus(Vector that) { if (size != that.size()) { throw new CardinalityException(size, that.size()); } return createOptimizedCopy().assign(that, Functions.PLUS); }
@Override public Vector minus(Vector that) { if (size != that.size()) { throw new CardinalityException(size, that.size()); } return createOptimizedCopy().assign(that, Functions.MINUS); }
@Override public Vector assign(Vector other, DoubleDoubleFunction function) { if (size != other.size()) { throw new CardinalityException(size, other.size()); } VectorBinaryAssign.assignBest(this, other, function); invalidateCachedLength(); return this; }
@Override public Matrix assign(Matrix other) { int rows = rowSize(); if (rows != other.rowSize()) { throw new CardinalityException(rows, other.rowSize()); } int columns = columnSize(); if (columns != other.columnSize()) { throw new CardinalityException(columns, other.columnSize()); } for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { setQuick(row, col, other.getQuick(row, col)); } } return this; }
@Override public void set(int row, double[] data) { int columns = columnSize(); if (columns < data.length) { throw new CardinalityException(columns, data.length); } int rows = rowSize(); if (row < 0 || row >= rows) { throw new IndexException(row, rowSize()); } for (int i = 0; i < columns; i++) { setQuick(row, i, data[i]); } }
@Override public Matrix assignColumn(int column, Vector other) { if (rowSize() != other.size()) { throw new CardinalityException(rowSize(), other.size()); } for (int row = 0; row < rowSize(); row++) { matrix.setQuick(row + offset[ROW], column + offset[COL], other .getQuick(row)); } return this; }
public void addAll(Vector v) { if (size() != v.size()) { throw new CardinalityException(size(), v.size()); } for (Element element : v.nonZeroes()) { values[element.index()] += element.get(); } }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } for (int col = 0; col < columnSize(); col++) { matrix .setQuick(row + offset[ROW], col + offset[COL], other.getQuick(col)); } return this; }
@Override public Vector times(Vector that) { if (size != that.size()) { throw new CardinalityException(size, that.size()); } if (this.getNumNondefaultElements() <= that.getNumNondefaultElements()) { return createOptimizedCopy(this).assign(that, Functions.MULT); } else { return createOptimizedCopy(that).assign(this, Functions.MULT); } }
@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()); } rowVectors.put(row, 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()); } rowVectors[row].assign(other); return this; }
@Override public Vector times(Vector v) { int columns = columnSize(); if (columns != v.size()) { throw new CardinalityException(columns, v.size()); } int rows = rowSize(); Vector w = new DenseVector(rows); for (int row = 0; row < rows; row++) { w.setQuick(row, v.dot(viewRow(row))); } return w; }
@Override public Vector assign(Vector other) { if (size() != other.size()) { throw new CardinalityException(size(), other.size()); } values.clear(); for (Element e : other.nonZeroes()) { setQuick(e.index(), e.get()); } 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++) { values[row][col] = other.getQuick(col); } return this; }
@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()); } for (int row = 0; row < rowSize(); row++) { values[row][column] = other.getQuick(row); } return this; }
public static Vector mult(Matrix m, Vector v) { if (m.numRows() != v.size()) { throw new CardinalityException(m.numRows(), v.size()); } // Use a Dense Vector for the moment, Vector result = new DenseVector(m.numRows()); for (int i = 0; i < m.numRows(); i++) { result.set(i, m.viewRow(i).dot(v)); } return result; }
@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()); } for (int row = 0; row < rowSize(); row++) { rowVectors[row].setQuick(column, other.getQuick(row)); } 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; }