@Override public void assertSameDimensionality( final Vector other) { assertEqualDimensionality(this, other); }
@Override public void dotDivideEquals( final Vector other) { this.assertSameDimensionality(other); // This is a dense loop since there is no sparsity in division. final int dimensionality = this.getDimensionality(); for (int i = 0; i < dimensionality; i++) { this.setElement(i, this.getElement(i) / other.getElement(i)); } }
@Override public Vector transform( final IndexValueTransform function) { final Vector result = this.clone(); result.transformEquals(function); return result; }
/** * Assigns the values in the provided vector into this. * * @param parameters The vector to convert. */ @Override public void convertFromVector( final Vector parameters ) { this.assertSameDimensionality( parameters ); final int dimensionality = this.getDimensionality(); for (int i = 0; i < dimensionality; i++) { this.setElement( i, parameters.getElement( i ) ); } }
@Override public void minusEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : other) { this.decrement(entry.getIndex(), entry.getValue()); } }
@Override public Vector times( final Matrix matrix) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertDimensionalityEquals(matrix.getNumRows()); final int n = matrix.getNumColumns(); final Vector result = this.getVectorFactory().createVector(n); for (final MatrixEntry entry : matrix) { result.increment(entry.getColumnIndex(), this.get(entry.getRowIndex()) * entry.getValue()); } return result; }
@Override public void plusEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : other) { this.increment(entry.getIndex(), entry.getValue()); } }
@Override public double dotProduct( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); double result = 0.0; for (final VectorEntry entry : this) { result += entry.getValue() * other.get(entry.getIndex()); } return result; }
@Override public double dotProduct( final Vector other) { if (other instanceof AbstractMTJVector) { return this.dotProduct((AbstractMTJVector) other); } else { return super.dotProduct(other); } }
@Override public void decrement( final int index) { this.decrement(index, 1.0); }
@Override public boolean equals( final Vector other, final double effectiveZero) { if( !this.checkSameDimensionality(other) ) { return false; } else { return super.equals( other, effectiveZero ); } }
@Override final public void dotTimesEquals( final Vector other) { this.assertSameDimensionality(other); if (other instanceof SparseVector) { dotTimesEquals((SparseVector) other); } else if (other instanceof DenseVector) { this.dotTimesEquals((DenseVector) other); } else { super.dotTimesEquals(other); } }
@Override final public double euclideanDistanceSquared( final Vector other) { this.assertSameDimensionality(other); if (other instanceof SparseVector) { return euclideanDistanceSquared((SparseVector) other); } else if (other instanceof DenseVector) { return this.euclideanDistanceSquared((DenseVector) other); } else { return super.euclideanDistanceSquared(other); } }
@Override public boolean equals( final Object other ) { if (other == null) { return false; } else if (this == other) { return true; } else if (other instanceof Vector) { return this.equals( (Vector) other, 0.0 ); } else { return false; } }
/** * Assigns the values in the provided vector into this. * * @param parameters The vector to convert. */ @Override public void convertFromVector( final Vector parameters ) { this.assertSameDimensionality( parameters ); final int dimensionality = this.getDimensionality(); for (int i = 0; i < dimensionality; i++) { this.setElement( i, parameters.getElement( i ) ); } }
@Override public Vector times( final Matrix matrix) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertDimensionalityEquals(matrix.getNumRows()); final int n = matrix.getNumColumns(); final Vector result = this.getVectorFactory().createVector(n); for (final MatrixEntry entry : matrix) { result.increment(entry.getColumnIndex(), this.get(entry.getRowIndex()) * entry.getValue()); } return result; }
@Override public void plusEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : other) { this.increment(entry.getIndex(), entry.getValue()); } }
@Override public void minusEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : other) { this.decrement(entry.getIndex(), entry.getValue()); } }
@Override public double dotProduct( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); double result = 0.0; for (final VectorEntry entry : this) { result += entry.getValue() * other.get(entry.getIndex()); } return result; }
@Override public double dotProduct( final Vector other) { if (other instanceof AbstractMTJVector) { return this.dotProduct((AbstractMTJVector) other); } else { return super.dotProduct(other); } }