mikera.vectorz.impl
Class SparseImmutableVector
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.impl.ASizedVector
-
- mikera.vectorz.impl.ASparseVector
-
- mikera.vectorz.impl.ASparseIndexedVector
-
- mikera.vectorz.impl.SparseImmutableVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, ISparse, ISparseVector, IVector
public class SparseImmutableVector extends ASparseIndexedVector
Indexed sparse immutable vector Efficient for sparse vectors. Maintains a indexed array of strictly non-zero elements. Guaranteed to contain at least one non-sparse index value- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidabs()Replaces all elements of this array with their absolute values, according to Math.abs(double)voidadd(ASparseVector v)voidaddAt(int i, double value)Adds a value to a specific element of the vector This function does not perform bounds checking, i.e.voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)SparseIndexedVectorclone()Clones the vector, creating a new mutable copy of all data.static AVectorcreate(ASparseVector source)static AVectorcreate(AVector source)Creates a sparse immutable vector from the given vector, ignoring the zeros in the source.static AVectorcreate(int length, Index sparseIndex, AVector sparseValues)Creates a SparseImmutableVector using the given sorted Index to identify the indexes of non-zero values, and a dense vector to specify all the non-zero element valuesstatic AVectorcreate(int length, Index sparseIndex, double[] sparseValues)Creates a SparseImmutableVector using the given sorted Index to identify the indexes of non-zero values, and a double[] array to specify all the non-zero element valuesstatic AVectorcreateFromRow(AMatrix m, int row)Creates a SparseIndexedVector from a row of an existing matrixVectordense()Coerces this INDArray to a dense format, without changing its element values.SparseImmutableVectorexactClone()Returns an exact clone of this vector, i.e.doubleget(int i)Returns the double value at the specified position in a 1D vectorbooleanincludesIndex(int i)Returns true iff the sparse vector contains the index ibooleanisFullyMutable()Returns true if this vector is fully mutable, i.e.booleanisMutable()Returns true if this vector is mutable.booleanisZero()Returns true if this vector is a zero vector (all components zero)doublemaxAbsElement()Returns the maximum absolute element value of a vectorintmaxAbsElementIndex()Returns the index of the maximum absolute element of a vectorintmaxElementIndex()Returns the index of the maximum element of a vectorintminElementIndex()Returns the index of the minimum element of a vectorSparseIndexedVectormutable()Coerces to a mutable version of a vector.voidnegate()Negates all emlements of this vector in place.intnonSparseElementCount()Returns the number of non-sparse elements in the sparse vector.IndexnonSparseIndex()Returns an Index indicating which elements of this vector are defined as non-sparse.VectornonSparseValues()Returns the non-sparse elements as a compacted vector.longnonZeroCount()Returns the number of non-zero elements in the array.int[]nonZeroIndices()Return an int array specifying the positions in this vector which are non-zerodouble[]nonZeroValues()Return an double array specifying the values in this vector which are non-zerovoidset(AVector v)Sets the vector to equal the value of another vectorvoidset(int i, double value)Sets a value at a given position in a mutable 1D arraySparseIndexedVectorsparseClone()Clones the vector into a sparse mutable formatdoubleunsafeGet(int i)Like get, but performs no bounds checking.voidvalidate()Validates the internal data structure of the INDArray.static SparseImmutableVectorwrap(int length, Index index, double[] nonSparseValues)Creates a SparseImmutableVector with the specified index and data values.-
Methods inherited from class mikera.vectorz.impl.ASparseIndexedVector
addMultipleToArray, addProductToArray, addProductToArray, addToArray, addToArray, addToArray, cloneIncludingIndices, copyTo, dotProduct, dotProduct, dotProduct, dotProduct, elementSquaredSum, elementSum, equals, equalsArray, getElements, innerProduct, isRangeZero, multiply
-
Methods inherited from class mikera.vectorz.impl.ASparseVector
add, addMultiple, copyTo, copyTo, density, distanceL1, distanceLinf, distanceSquared, dotProduct, elementAbsPowSum, elementPowSum, elementProduct, equals, getSlices, hasUncountable, isSparse, isView, reduce, reduce, reduceSlices, roundToZero, sparse, toDoubleArray, toSparseIndexedVector, visitNonZero
-
Methods inherited from class mikera.vectorz.impl.ASizedVector
checkIndex, checkLength, checkRange, elementCount, equalsArray, get, getShape, getShapeClone, isSameShape, length, sliceCount
-
Methods inherited from class mikera.vectorz.AVector
absCopy, absDiff, absDiff, absDiff, absDiffCopy, add, add, add, add, add, add, add, add, addAt, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addSparse, addSparse, addWeighted, angle, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastLike, broadcastLike, broadcastLike, clamp, clampMax, clampMin, compareTo, compareTo, copy, copyTo, copyTo, crossProduct, crossProduct, denseClone, dimensionality, distance, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, elementIterator, elementMax, elementMaxAbs, elementMin, elementsEqual, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, fill, fillRange, get, get, get, get, get, getElement, getElements, getElements, getLongShape, getShape, getTranspose, getTransposeCopy, getTransposeView, hashCode, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isElementConstrained, isSameShape, isUnitLengthVector, isUnitLengthVector, iterator, join, join, join, log, logistic, magnitude, magnitudeSquared, maxElement, minElement, multiply, multiply, multiply, multiply, multiplyCopy, multiplyCopy, multiplyCopy, multiplyTo, negateCopy, normalise, normaliseCopy, normaliseMaxAbsElement, outerProduct, outerProduct, pow, projectToPlane, reciprocal, reciprocalCopy, reduceSlices, reorder, reorder, reshape, rotateCopy, rotateView, rotateView, scale, scaleAdd, scaleAdd, scaleAdd, scaleAdd, scaleCopy, scaleToMagnitude, select, selectClone, selectView, set, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setApplyOp, setElements, setElements, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, slice, sliceValue, softmax, softmaxCopy, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toDoubleBuffer, toList, toNormal, toSliceArray, toString, toStringFull, toVector, tryEfficientJoin, unsafeSet
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
add, addApplyOp, addCopy, addInnerProduct, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, scale, set, set, signumCopy, sqrt, sub, sub, withComponents
-
Methods inherited from interface mikera.vectorz.IVector
addCopy, divideCopy, epsilonEquals, isSameShape, length, multiplyCopy, normalise, normaliseCopy, rotateCopy, rotateView, shiftCopy, sqrtCopy, subCopy
-
Methods inherited from interface mikera.arrayz.INDArray
absCopy, absDiff, absDiffCopy, add, add, addApplyOp, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, broadcastLike, clamp, componentCount, copy, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementsEqual, ensureMutable, epsilonEquals, epsilonEquals, equals, equalsArray, exp, fill, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSliceViews, getTranspose, getTransposeCopy, getTransposeView, immutable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isElementConstrained, isSameShape, join, join, log, multiply, multiplyCopy, multiplyCopy, negateCopy, outerProduct, pow, reciprocal, reciprocalCopy, reduceSlices, reorder, reorder, reshape, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, set, set, set, setApplyOp, setElements, setElements, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, slice, slice, sliceCount, sliceValue, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleBuffer, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
wrap
public static SparseImmutableVector wrap(int length, Index index, double[] nonSparseValues)
Creates a SparseImmutableVector with the specified index and data values. WARNING: Performs no checking - Index must be distinct and sorted, and data must be non-zero.
-
create
public static AVector create(int length, Index sparseIndex, double[] sparseValues)
Creates a SparseImmutableVector using the given sorted Index to identify the indexes of non-zero values, and a double[] array to specify all the non-zero element values
-
create
public static AVector create(int length, Index sparseIndex, AVector sparseValues)
Creates a SparseImmutableVector using the given sorted Index to identify the indexes of non-zero values, and a dense vector to specify all the non-zero element values
-
create
public static AVector create(AVector source)
Creates a sparse immutable vector from the given vector, ignoring the zeros in the source.
-
create
public static AVector create(ASparseVector source)
-
createFromRow
public static AVector createFromRow(AMatrix m, int row)
Creates a SparseIndexedVector from a row of an existing matrix
-
nonSparseElementCount
public int nonSparseElementCount()
Description copied from class:ASparseVectorReturns the number of non-sparse elements in the sparse vector. This will be greater or equal to the number of non-zero elements- Specified by:
nonSparseElementCountin classASparseVector- Returns:
-
isZero
public boolean isZero()
Description copied from class:AVectorReturns true if this vector is a zero vector (all components zero)- Specified by:
isZeroin interfaceINDArray- Overrides:
isZeroin classASparseIndexedVector
-
maxAbsElement
public double maxAbsElement()
Description copied from class:AVectorReturns the maximum absolute element value of a vector- Overrides:
maxAbsElementin classAVector- Returns:
-
maxElementIndex
public int maxElementIndex()
Description copied from class:AVectorReturns the index of the maximum element of a vector- Overrides:
maxElementIndexin classAVector- Returns:
-
maxAbsElementIndex
public int maxAbsElementIndex()
Description copied from class:AVectorReturns the index of the maximum absolute element of a vector- Overrides:
maxAbsElementIndexin classAVector- Returns:
-
minElementIndex
public int minElementIndex()
Description copied from class:AVectorReturns the index of the minimum element of a vector- Overrides:
minElementIndexin classAVector
-
negate
public void negate()
Description copied from class:AVectorNegates all emlements of this vector in place.
-
applyOp
public void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)
-
abs
public void abs()
Description copied from interface:INDArrayReplaces all elements of this array with their absolute values, according to Math.abs(double)
-
get
public double get(int i)
Description copied from interface:INDArrayReturns the double value at the specified position in a 1D vector
-
unsafeGet
public double unsafeGet(int i)
Description copied from class:AVectorLike get, but performs no bounds checking. Results are undefined if the index is out of range
-
isFullyMutable
public boolean isFullyMutable()
Description copied from class:AVectorReturns true if this vector is fully mutable, i.e. can contain any unconstrained double values- Specified by:
isFullyMutablein interfaceINDArray- Overrides:
isFullyMutablein classAVector
-
isMutable
public boolean isMutable()
Description copied from class:AVectorReturns true if this vector is mutable.
-
nonZeroCount
public long nonZeroCount()
Description copied from interface:INDArrayReturns the number of non-zero elements in the array.- Specified by:
nonZeroCountin interfaceINDArray- Overrides:
nonZeroCountin classASparseIndexedVector
-
nonZeroIndices
public int[] nonZeroIndices()
Description copied from class:AVectorReturn an int array specifying the positions in this vector which are non-zero- Overrides:
nonZeroIndicesin classASparseIndexedVector- Returns:
-
add
public void add(ASparseVector v)
- Specified by:
addin classASparseVector
-
set
public void set(AVector v)
Description copied from class:AVectorSets the vector to equal the value of another vector
-
set
public void set(int i, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 1D array
-
addAt
public void addAt(int i, double value)Description copied from class:AVectorAdds a value to a specific element of the vector This function does not perform bounds checking, i.e. is an unsafe operation
-
nonSparseValues
public Vector nonSparseValues()
Description copied from interface:ISparseVectorReturns the non-sparse elements as a compacted vector. May or may not be a view.- Specified by:
nonSparseValuesin interfaceISparseVector- Specified by:
nonSparseValuesin classASparseVector- Returns:
-
nonZeroValues
public double[] nonZeroValues()
Description copied from class:AVectorReturn an double array specifying the values in this vector which are non-zero- Overrides:
nonZeroValuesin classAVector- Returns:
-
nonSparseIndex
public Index nonSparseIndex()
Description copied from class:AVectorReturns an Index indicating which elements of this vector are defined as non-sparse. A sparse index must be zero. A non-sparse element may be zero, but is typically expected be non-zero.- Specified by:
nonSparseIndexin interfaceISparseVector- Specified by:
nonSparseIndexin classASparseVector- Returns:
-
includesIndex
public boolean includesIndex(int i)
Description copied from class:ASparseVectorReturns true iff the sparse vector contains the index i- Overrides:
includesIndexin classASparseIndexedVector- Returns:
-
dense
public Vector dense()
Description copied from interface:INDArrayCoerces this INDArray to a dense format, without changing its element values. May return the same INDArray if already dense. May also mutate the internal structure of the original NDArray, or create a view over parts of the original INDArray. You should take a defensive copy of the original NDArray if any of this concerns you. The returned dense array may not be fully mutable in all elements.
-
mutable
public SparseIndexedVector mutable()
Description copied from class:AVectorCoerces to a mutable version of a vector. May or may not be a copy, but guaranteed to be fully mutable
-
clone
public SparseIndexedVector clone()
Description copied from class:AVectorClones the vector, creating a new mutable copy of all data. The clone is: - not guaranteed to be of the same type. - guaranteed to be fully mutable - guaranteed not to contain a reference (i.e. is a full deep copy)
-
sparseClone
public SparseIndexedVector sparseClone()
Description copied from class:AVectorClones the vector into a sparse mutable format- Specified by:
sparseClonein interfaceINDArray- Overrides:
sparseClonein classAVector
-
exactClone
public SparseImmutableVector exactClone()
Description copied from class:AVectorReturns an exact clone of this vector, i.e. of the same type- Specified by:
exactClonein interfaceINDArray- Specified by:
exactClonein classAVector- Returns:
- A clone of the original array
-
validate
public void validate()
Description copied from interface:INDArrayValidates the internal data structure of the INDArray. Throws an exception on failure. Failure indicates a serious bug and/or data corruption.
-
-
DMelt 3.0 © DataMelt by jWork.ORG