mikera.vectorz.impl
Class AStridedVector
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.impl.ASizedVector
-
- mikera.vectorz.impl.AArrayVector
-
- mikera.vectorz.impl.AStridedVector
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, IStridedArray, INDArray, IVector
- Direct Known Subclasses:
- ADenseArrayVector, BaseStridedVector, ImmutableVector
public abstract class AStridedVector extends AArrayVector implements IStridedArray
Abstract base class for vectors backed by a double[] array with a constant stride The double array can be directly accessed for performance purposes- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidadd(int offset, AVector a, int aOffset, int length)Adds a segment of another vector into this one, at the specified offsetabstract voidaddAt(int i, double v)Adds a value to a specific element of the vector This function does not perform bounds checking, i.e.voidaddMultipleToArray(double factor, int offset, double[] destData, int destOffset, int length)Adds a multiple of a subvector of this vector into a double array at the specified offsetvoidaddToArray(double[] dest, int destOffset, int destStride)Adds this vector to a double[] array, using the specified offset and stride into the destination arrayvoidaddToArray(int offset, double[] destData, int destOffset, int length)Adds a subvector of this vector into a double array at the specified offsetabstract voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)VectorapplyOpCopy(Op op)Applies a unary operator to all elements of the array (creating a new array)double[]asDoubleArray()Returns the underlying double array representing the densely packed elements of this array.INDArraybroadcast(int... shape)Returns a view of this array broadcasted up to a larger shapeAStridedMatrixbroadcastLike(AMatrix target)Broadcasts an array to match the shape of the target matrixVectorclone()Clones the vector, creating a new mutable copy of all data.voidcopyTo(int offset, double[] dest, int destOffset, int length, int stride)Copies a subset of this vector to a specified destination array offset using the given stride.doubledotProduct(AVector v)Returns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefineddoubledotProduct(double[] data, int offset)Fast dot product with a double[] array.doubleelementMax()Returns the maximum element value in this array.doubleelementMin()Returns the maximum element value in this array.doubleelementProduct()Returns the product of all elements in the array.doubleelementSquaredSum()Returns the sum of squared elements in this array.doubleelementSum()Returns the sum of all elements in a vectorAStridedVectorensureMutable()Ensures the array is a fully mutable representation.booleanequals(AVector v)Returns true if this array is exactly equal to a vector.booleanequalsArray(double[] vs, int offset)Returns true if this vector exactly matches the elements in double[] array, starting from the specified offsetdouble[]getArray()Gets the underlying double[] data array for this vectorabstract intgetArrayOffset()Gets the offset into the underlying double[] data array for the first element of this vectorvoidgetElements(double[] dest, int destOffset)Copies all elements of this array a double array at the specified offsetvoidgetElements(double[] dest, int destOffset, int[] indices)Gets the elements in this vector from the specified indices, storing at the specified offset in the destination arrayabstract intgetStride()Gets the stride of this strided vector.intgetStride(int dimension)Gets the stide for a specific dimension in this strided array.int[]getStrides()Gets the strides for each dimension of this strided array.booleanhasUncountable()Returns true if any element is this array is NaN or infinitebooleanisPackedArray()Checks if this array is fully packed in row major order.booleanisRangeZero(int start, int length)Returns true if a sub-vector range is completely zero.java.util.Iterator<java.lang.Double>iterator()doublereduce(Op2 op)Reduces over all elements of the array in row-major order.doublereduce(Op2 op, double init)Reduces over all elements of the array in row-major order.AVectorselectView(int... inds)Selects a subset of indices from a vector, returning a viewabstract voidset(AVector v)Sets the vector to equal the value of another vectorabstract voidsetElements(double[] values, int offset)Sets all elements in an array using the given double valuesabstract voidsetElements(int pos, double[] values, int offset, int length)Sets elements in an array using the given double values.voidvalidate()Validates the internal data structure of the INDArray.doublevisitNonZero(IndexedElementVisitor elementVisitor)Visits all non-zero elements of this vector.-
Methods inherited from class mikera.vectorz.impl.AArrayVector
maxAbsElement, slice
-
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
abs, 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, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addProductToArray, addProductToArray, addSparse, addSparse, addToArray, addWeighted, angle, applyOp, applyOp, applyOp, applyOp, asElementList, asVector, broadcastLike, broadcastLike, clamp, clampMax, clampMin, compareTo, compareTo, copy, copyTo, copyTo, copyTo, copyTo, crossProduct, crossProduct, dense, denseClone, dimensionality, distance, distanceL1, distanceLinf, distanceSquared, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, dotProduct, dotProduct, elementAbsPowSum, elementIterator, elementMaxAbs, elementPowSum, elementsEqual, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, exactClone, fill, fillRange, get, get, get, get, get, get, getElement, getElements, getLongShape, getShape, getSlices, getTranspose, getTransposeCopy, getTransposeView, hashCode, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isElementConstrained, isFullyMutable, isMutable, isSameShape, isUnitLengthVector, isUnitLengthVector, isView, isZero, join, join, join, log, logistic, magnitude, magnitudeSquared, 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, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateCopy, rotateView, rotateView, scale, scaleAdd, scaleAdd, scaleAdd, scaleAdd, scaleCopy, scaleToMagnitude, select, selectClone, set, set, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setApplyOp, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, sliceValue, softmax, softmaxCopy, sparse, sparseClone, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toDoubleArray, toDoubleBuffer, toList, toNormal, toSliceArray, toString, toStringFull, toVector, tryEfficientJoin, unsafeGet, unsafeSet
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
add, addApplyOp, addCopy, addInnerProduct, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, density, 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
abs, absCopy, absDiff, absDiffCopy, add, add, addApplyOp, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addMultiple, addMultipleSparse, addOuterProduct, addOuterProductSparse, addPower, addPower, addSparse, addSparse, addToArray, applyOp, applyOp, applyOp, asElementList, asVector, broadcastCloneLike, broadcastCopyLike, broadcastLike, broadcastLike, clamp, componentCount, copy, dense, denseClone, dimensionality, divide, divide, divideCopy, divideCopy, elementAbsPowSum, elementCount, elementIterator, elementMaxAbs, elementPowSum, elementsEqual, epsilonEquals, epsilonEquals, equals, equalsArray, exactClone, exp, fill, get, get, get, get, get, get, get, get, get, getComponent, getComponents, getElement, getElements, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getSlices, getSliceViews, getTranspose, getTransposeCopy, getTransposeView, immutable, innerProduct, innerProduct, innerProduct, innerProduct, isBoolean, isDense, isElementConstrained, isFullyMutable, isMutable, isSameShape, isSparse, isView, isZero, join, join, log, multiply, multiply, multiplyCopy, multiplyCopy, mutable, negate, negateCopy, nonZeroCount, outerProduct, pow, reciprocal, reciprocalCopy, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, set, set, set, set, set, set, set, setApplyOp, setElements, setInnerProduct, setMultiple, setMultiple, setSparse, setSparse, signum, signumCopy, slice, slice, sliceCount, sliceValue, sparse, sparseClone, sqrt, square, squareCopy, sub, sub, subArray, subCopy, toDoubleArray, toDoubleBuffer, toSliceArray, toVector, withComponents
-
-
-
-
Method Detail
-
getArray
public final double[] getArray()
Gets the underlying double[] data array for this vector- Specified by:
getArrayin interfaceIStridedArray- Returns:
-
getArrayOffset
public abstract int getArrayOffset()
Gets the offset into the underlying double[] data array for the first element of this vector- Specified by:
getArrayOffsetin interfaceIStridedArray- Returns:
-
getStride
public abstract int getStride()
Gets the stride of this strided vector.- Returns:
-
ensureMutable
public AStridedVector ensureMutable()
Description copied from interface:INDArrayEnsures the array is a fully mutable representation. Returns either the same array or a new clone.- Specified by:
ensureMutablein interfaceINDArray- Overrides:
ensureMutablein classAbstractArray<java.lang.Double>
-
isRangeZero
public boolean isRangeZero(int start, int length)Description copied from class:AVectorReturns true if a sub-vector range is completely zero. Unsafe operation - does not perform bounds checking, results are undefined if sub-vector is out of range- Overrides:
isRangeZeroin classAVector- Returns:
-
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
-
dotProduct
public double dotProduct(AVector v)
Description copied from class:AVectorReturns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefined- Overrides:
dotProductin classAVector- Returns:
-
elementSum
public double elementSum()
Description copied from class:AVectorReturns the sum of all elements in a vector- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAVector
-
elementProduct
public double elementProduct()
Description copied from interface:INDArrayReturns the product of all elements in the array.- Specified by:
elementProductin interfaceINDArray- Overrides:
elementProductin classAVector- Returns:
-
elementMax
public double elementMax()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMaxin interfaceINDArray- Overrides:
elementMaxin classAVector
-
elementMin
public double elementMin()
Description copied from interface:INDArrayReturns the maximum element value in this array. Throws an error if there are no elements.- Specified by:
elementMinin interfaceINDArray- Overrides:
elementMinin classAVector
-
broadcast
public INDArray broadcast(int... shape)
Description copied from interface:INDArrayReturns a view of this array broadcasted up to a larger shape
-
broadcastLike
public AStridedMatrix broadcastLike(AMatrix target)
Description copied from interface:INDArrayBroadcasts an array to match the shape of the target matrix- Specified by:
broadcastLikein interfaceINDArray- Overrides:
broadcastLikein classAVector- Parameters:
target- The target matrix
-
selectView
public AVector selectView(int... inds)
Description copied from class:AVectorSelects a subset of indices from a vector, returning a view- Overrides:
selectViewin classAArrayVector- Returns:
- a view of the selected indices
-
clone
public Vector 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)
-
set
public abstract void set(AVector v)
Description copied from class:AVectorSets the vector to equal the value of another vector
-
setElements
public abstract void setElements(double[] values, int offset)Description copied from interface:INDArraySets all elements in an array using the given double values- Specified by:
setElementsin interfaceINDArray- Overrides:
setElementsin classAVector- Parameters:
values- Element values in a double[] array. There must be at least as many element values as elements in this array.offset- Position in the values array from which to start taking values.
-
setElements
public abstract void setElements(int pos, double[] values, int offset, int length)Description copied from interface:INDArraySets elements in an array using the given double values. The source array must contain at least the specified length in terms of number of elements- Specified by:
setElementsin interfaceINDArray- Overrides:
setElementsin classAVector- Parameters:
pos- Offset into this array, expressed in terms of number of elements in row major ordervalues- Element values in a double[] array. There must be at least as many element values as elements in this array.offset- Position in the values array from which to start taking values.length- Number of elements to set.
-
add
public void add(int offset, AVector a, int aOffset, int length)Description copied from class:AVectorAdds a segment of another vector into this one, at the specified offset
-
addAt
public abstract void addAt(int i, double v)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
-
addToArray
public void addToArray(int offset, double[] destData, int destOffset, int length)Description copied from class:AVectorAdds a subvector of this vector into a double array at the specified offset- Overrides:
addToArrayin classAVector
-
addMultipleToArray
public void addMultipleToArray(double factor, int offset, double[] destData, int destOffset, int length)Description copied from class:AVectorAdds a multiple of a subvector of this vector into a double array at the specified offset- Overrides:
addMultipleToArrayin classAVector
-
addToArray
public void addToArray(double[] dest, int destOffset, int destStride)Description copied from class:AVectorAdds this vector to a double[] array, using the specified offset and stride into the destination array- Overrides:
addToArrayin classAVector
-
applyOp
public abstract void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)
-
applyOpCopy
public final Vector applyOpCopy(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (creating a new array)- Specified by:
applyOpCopyin interfaceINDArray- Overrides:
applyOpCopyin classAVector
-
reduce
public double reduce(Op2 op, double init)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
-
reduce
public double reduce(Op2 op)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.
-
copyTo
public void copyTo(int offset, double[] dest, int destOffset, int length, int stride)Description copied from class:AVectorCopies a subset of this vector to a specified destination array offset using the given stride. Unsafe operation: performs no bounds checking
-
hasUncountable
public boolean hasUncountable()
Description copied from class:AbstractArrayReturns true if any element is this array is NaN or infinite- Specified by:
hasUncountablein interfaceINDArray- Overrides:
hasUncountablein classAVector- Returns:
- True if any element is this array is NaN or infinite, false otherwise
-
asDoubleArray
public double[] asDoubleArray()
Description copied from interface:INDArrayReturns the underlying double array representing the densely packed elements of this array. Modifications to this double array will change the original array. Returns null if there is no such array.- Specified by:
asDoubleArrayin interfaceINDArray- Overrides:
asDoubleArrayin classAVector
-
isPackedArray
public boolean isPackedArray()
Description copied from interface:IStridedArrayChecks if this array is fully packed in row major order.- Specified by:
isPackedArrayin interfaceIStridedArray- Returns:
-
getStrides
public int[] getStrides()
Description copied from interface:IStridedArrayGets the strides for each dimension of this strided array. The returned array should not be modified- Specified by:
getStridesin interfaceIStridedArray- Returns:
-
iterator
public java.util.Iterator<java.lang.Double> iterator()
-
getStride
public int getStride(int dimension)
Description copied from interface:IStridedArrayGets the stide for a specific dimension in this strided array.- Specified by:
getStridein interfaceIStridedArray- Returns:
-
elementSquaredSum
public double elementSquaredSum()
Description copied from interface:INDArrayReturns the sum of squared elements in this array.- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classAVector
-
getElements
public void getElements(double[] dest, int destOffset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAVector
-
getElements
public void getElements(double[] dest, int destOffset, int[] indices)Description copied from class:AVectorGets the elements in this vector from the specified indices, storing at the specified offset in the destination array- Overrides:
getElementsin classAVector
-
equals
public boolean equals(AVector v)
Description copied from class:AbstractArrayReturns true if this array is exactly equal to a vector.
-
equalsArray
public boolean equalsArray(double[] vs, 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 classASizedVector- Parameters:
vs- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
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.- Overrides:
visitNonZeroin classASizedVector
-
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