/** * Copy constructor -- creates a deep copy of the input sparse vector. * * @param v The sparse vector to copy */ public SparseVector( final DenseVector v) { this.dimensionality = v.values.length; int nnz = v.countNonZeros(); values = new double[nnz]; indices = new int[nnz]; elements = new TreeMap<>(); int idx = 0; for (int i = 0; i < dimensionality; ++i) { double val = v.values[i]; if (val != 0) { values[idx] = val; indices[idx] = i; ++idx; } } }
/** * Copy constructor -- creates a deep copy of the input sparse vector. * * @param v The sparse vector to copy */ public SparseVector( final DenseVector v) { this.dimensionality = v.values.length; int nnz = v.countNonZeros(); values = new double[nnz]; indices = new int[nnz]; elements = new TreeMap<>(); int idx = 0; for (int i = 0; i < dimensionality; ++i) { double val = v.values[i]; if (val != 0) { values[idx] = val; indices[idx] = i; ++idx; } } }
/** * Copy constructor -- creates a deep copy of the input sparse vector. * * @param v The sparse vector to copy */ public SparseVector( final DenseVector v) { this.dimensionality = v.values.length; int nnz = v.countNonZeros(); values = new double[nnz]; indices = new int[nnz]; elements = new TreeMap<>(); int idx = 0; for (int i = 0; i < dimensionality; ++i) { double val = v.values[i]; if (val != 0) { values[idx] = val; indices[idx] = i; ++idx; } } }
Vector result; int len = dimensionality + other.values.length; int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SPARSE_TO_DENSE_THRESHOLD * len)
Vector result; int len = dimensionality + other.values.length; int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SPARSE_TO_DENSE_THRESHOLD * len)
Vector result; int len = dimensionality + other.values.length; int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SPARSE_TO_DENSE_THRESHOLD * len)
int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SparseVector.SPARSE_TO_DENSE_THRESHOLD * len)
int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SparseVector.SPARSE_TO_DENSE_THRESHOLD * len)
int nnz = countNonZeros() + other.countNonZeros(); if (nnz > SparseVector.SPARSE_TO_DENSE_THRESHOLD * len)