package jsci.maths.vectors;
import jsci.GlobalSettings;
import jsci.maths.Mapping;
import jsci.maths.MathDouble;
import jsci.maths.MathInteger;
import jsci.maths.algebras.Module;
import jsci.maths.algebras.VectorSpace;
import jsci.maths.fields.Field;
import jsci.maths.fields.Ring;
import jsci.maths.groups.AbelianGroup;
import jsci.maths.matrices.DoubleSparseMatrix;
/**
* The DoubleSparseVector class encapsulates sparse vectors.
* Uses Morse-coding.
* @author Daniel Lemire
* @author Alain Beliveau
*/
public final class DoubleSparseVector extends AbstractDoubleVector {
private double vector[];
/**
* Sparse indexing data.
* Contains the component positions of each element,
* e.g. pos[n] is the component position
* of the nth element
* (the pos[n]th component is stored at index n).
*/
private int pos[];
/**
* Constructs an empty vector.
* @param dim the dimension of the vector.
*/
public DoubleSparseVector(final int dim) {
super(dim);
vector=new double[0];
pos=new int[0];
}
/**
* Constructs a vector from an array.
*/
public DoubleSparseVector(double array[]) {
super(array.length);
int n=0;
for(int i=0;i=N)
throw new VectorDimensionException(getInvalidComponentMsg(n));
for(int k=0;k=N)
throw new VectorDimensionException(getInvalidComponentMsg(n));
if(Math.abs(x)<=GlobalSettings.ZERO_TOL)
return;
for(int k=0;k2-norm (magnitude).
*/
public double norm() {
return Math.sqrt(sumSquares());
}
/**
* Returns the sum of the squares of the components.
*/
public double sumSquares() {
double norm=0.0;
for(int k=0;k
Ads help maintain this website.