mikera.vectorz
Class GrowableVector
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.GrowableVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, IVector
public final class GrowableVector extends AVector
Implements a growable vector, intended for incrementally building vectors Supports the following operations which etend the vector's length: - set (when used beyond array length) - append (adds a value to the end of the vector, extending length by one) Note that getting the underlying array or a subVector is unsafe, since the underlying array may be discarded as the vector is grown.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description GrowableVector()GrowableVector(AVector v)GrowableVector(int initialCapacity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidappend(AVector v)voidappend(double... vs)voidappend(double v)AVectorbuild()Function to build a fixed-size vector containing a copy of data once the GrowableVector is constructedvoidclear()GrowableVectorclone()Clones the vector, creating a new mutable copy of all data.static GrowableVectorcreate(AVector values)Creates a GrowableVector containing a copy of the elements of a given vectorstatic java.lang.Objectcreate(double[] nonZeroValues)static GrowableVectorcreate(java.lang.Iterable<java.lang.Number> iterable)Creates a GrowableVector by consuming all numbers in the given iterable objectstatic GrowableVectorcreate(java.util.Iterator<java.lang.Number> iterator)Creates a GrowableVector by consuming all numbers in the given iteratorintcurrentCapacity()doubledotProduct(double[] data, int offset)Fast dot product with a double[] array.voidensureCapacity(int capacity)booleanequalsArray(double[] data, int offset)Returns true if this vector exactly matches the elements in double[] array, starting from the specified offsetGrowableVectorexactClone()Returns an exact clone of this vector, i.e.doubleget(int i)Returns the double value at the specified position in a 1D vectorvoidgetElements(double[] dest, int offset)Copies all elements of this array a double array at the specified offsetvoidinsert(int pos, double value)Inserts a double value at the specified position in this GrowableVector.booleanisView()Returns true if this vector is of a view type that references other vectors / data.intlength()Returns the length of a vector, in terms of the number of elements.static GrowableVectorofInitialCapacity(int capacity)Returns a new, empty GrowableVector with the specified initial capacityvoidset(int i, double value)Sets a value at a given position in a mutable 1D arraydouble[]toDoubleArray()Copies the elements of this array to a new double[] array.VectortoVector()Coerces this vector to the standard dense Vector format.doubleunsafeGet(int i)Like get, but performs no bounds checking.voidunsafeSet(int i, double value)Like set, but performs no bounds checking.voidvalidate()Validates the internal data structure of the INDArray.doublevisitNonZero(IndexedElementVisitor elementVisitor)Visits all non-zero elements of this vector.static GrowableVectorwrap(double[] values)Creates a GrowableVector initialised with the given double[] values-
Methods inherited from class mikera.vectorz.AVector
abs, absCopy, absDiff, absDiff, absDiff, absDiffCopy, add, add, add, add, add, add, add, add, add, addAt, addAt, addCopy, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addProductToArray, addProductToArray, addSparse, addSparse, addToArray, addToArray, addToArray, addWeighted, angle, applyOp, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastLike, broadcastLike, broadcastLike, checkIndex, checkLength, checkRange, clamp, clampMax, clampMin, compareTo, compareTo, copy, copyTo, copyTo, copyTo, copyTo, copyTo, crossProduct, crossProduct, dense, denseClone, dimensionality, distance, distanceL1, distanceLinf, distanceSquared, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, dotProduct, dotProduct, dotProduct, elementAbsPowSum, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementPowSum, elementProduct, elementsEqual, elementSquaredSum, elementSum, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equals, equalsArray, fill, fillRange, get, get, get, get, get, get, getElement, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getTranspose, getTransposeCopy, getTransposeView, hashCode, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isElementConstrained, isFullyMutable, isMutable, isRangeZero, isSameShape, isSameShape, isUnitLengthVector, isUnitLengthVector, isZero, iterator, join, join, join, log, logistic, magnitude, magnitudeSquared, maxAbsElement, maxAbsElementIndex, maxElement, maxElementIndex, minElement, minElementIndex, multiply, multiply, multiply, multiply, multiply, multiplyCopy, multiplyCopy, multiplyCopy, multiplyTo, mutable, negate, negateCopy, nonSparseIndex, nonZeroCount, nonZeroIndices, nonZeroValues, normalise, normaliseCopy, normaliseMaxAbsElement, outerProduct, outerProduct, pow, projectToPlane, reciprocal, reciprocalCopy, reduce, reduce, reduceSlices, 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, set, setApplyOp, setApplyOp, setApplyOp, setElements, setElements, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, slice, sliceCount, sliceValue, softmax, softmaxCopy, sparse, sparseClone, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toDoubleBuffer, toList, toNormal, toSliceArray, toString, toStringFull, tryEfficientJoin
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
add, addApplyOp, addCopy, addInnerProduct, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, density, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, isSparse, scale, set, set, signumCopy, sqrt, sub, sub, withComponents
-
Methods inherited from interface mikera.arrayz.INDArray
addApplyOp, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, isSparse, scale, set, set, signumCopy, sqrt, sub, withComponents
-
-
-
-
Constructor Detail
-
GrowableVector
public GrowableVector(AVector v)
-
GrowableVector
public GrowableVector(int initialCapacity)
-
GrowableVector
public GrowableVector()
-
-
Method Detail
-
ofInitialCapacity
public static GrowableVector ofInitialCapacity(int capacity)
Returns a new, empty GrowableVector with the specified initial capacity
-
create
public static GrowableVector create(java.lang.Iterable<java.lang.Number> iterable)
Creates a GrowableVector by consuming all numbers in the given iterable object- Parameters:
iterable- An Iterable instance over java.lang.Number instances- Returns:
-
create
public static GrowableVector create(AVector values)
Creates a GrowableVector containing a copy of the elements of a given vector- Parameters:
values-- Returns:
-
wrap
public static GrowableVector wrap(double[] values)
Creates a GrowableVector initialised with the given double[] values
-
create
public static GrowableVector create(java.util.Iterator<java.lang.Number> iterator)
Creates a GrowableVector by consuming all numbers in the given iterator- Parameters:
iterable- An Iterable instance over java.lang.Number instances- Returns:
-
length
public int length()
Description copied from interface:IVectorReturns the length of a vector, in terms of the number of elements. For Euclidean length, use magnitude() instead
-
currentCapacity
public int currentCapacity()
-
ensureCapacity
public void ensureCapacity(int capacity)
-
get
public double get(int i)
Description copied from interface:INDArrayReturns the double value at the specified position in a 1D 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
-
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
-
unsafeSet
public void unsafeSet(int i, double value)Description copied from class:AVectorLike set, but performs no bounds checking. Results are undefined if the index is out of range
-
isView
public boolean isView()
Description copied from class:AVectorReturns true if this vector is of a view type that references other vectors / data.
-
append
public void append(double v)
-
append
public void append(double... vs)
-
append
public void append(AVector v)
-
build
public AVector build()
Function to build a fixed-size vector containing a copy of data once the GrowableVector is constructed- Returns:
-
clone
public GrowableVector 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)
-
clear
public void clear()
-
exactClone
public GrowableVector 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.
-
toVector
public Vector toVector()
Description copied from class:AVectorCoerces this vector to the standard dense Vector format. May return the same vector is this is already a dense Vector, otherwise returns a Vector containing a new clone of the vector elements.
-
toDoubleArray
public double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classAVector
-
getElements
public void getElements(double[] dest, int offset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAVector
-
dotProduct
public double dotProduct(double[] data, int offset)Description copied from class:AVectorFast dot product with a double[] array. Performs no bounds checking. Likely to be faster than most other dot product operations- Specified by:
dotProductin classAVector
-
equalsArray
public boolean equalsArray(double[] data, int offset)Description copied from class:AVectorReturns true if this vector exactly matches the elements in double[] array, starting from the specified offset- Specified by:
equalsArrayin interfaceINDArray- Overrides:
equalsArrayin classAVector- Parameters:
data- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
insert
public void insert(int pos, double value)Inserts a double value at the specified position in this GrowableVector. Increases the vector length by 1- Parameters:
pos-value-
-
create
public static java.lang.Object create(double[] nonZeroValues)
-
visitNonZero
public double visitNonZero(IndexedElementVisitor elementVisitor)
Description copied from class:AVectorVisits all non-zero elements of this vector. Visitor may return a non-zero value to terminate early, which will return the given value. Returns 0.0 otherwise.- Specified by:
visitNonZeroin classAVector
-
-
DMelt 3.0 © DataMelt by jWork.ORG