mikera.vectorz
Class Vectorz
- java.lang.Object
-
- mikera.vectorz.Vectorz
-
public class Vectorz extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field and Description static intMIN_SPARSE_LENGTHSpecified the minimum length at which it is worthwhile creating sparse vectors rather than dense vectors.static doubleTEST_EPSILONConstant tolerance used for testing double values
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description static doubleaverageSquaredDifference(AVector a, AVector b)Deprecated.static doubleaverageValue(AVector v)Deprecated.static AVectoraxisVector(int axisIndex, int dimensions)static AVectorcreate(AIndex index)Creates a new vector containing the values in the specified indexstatic AVectorcreate(AVector vector)Creates a mutable clone of a given vectorstatic AVectorcreate(double... data)Creates a vector using the given double data, using the most efficient dense representation.static AVectorcreate(java.nio.DoubleBuffer d)Create a vector from a DoubleBuffer Note: consumes all doubles from the bufferstatic AVectorcreate(java.lang.Iterable<java.lang.Object> d)Create a vector from an arbitrary iterable objectstatic AVectorcreate(IVector vector)Creates a mutable clone of a given vectorstatic AVectorcreate(java.util.List<java.lang.Object> d)Create a vector from a list of numerical values (objects should be java.lang.Number instances)static AVectorcreate(java.lang.Object o)Creates a vector from the given source data.static AVectorcreateMutableRange(int length)Create a mutable vector contain the sequence of integers from 0 to length-1static AVectorcreateMutableVector(AVector v)Deprecated.static AVectorcreateRange(int length)Create an immutable vector contain the sequence of integers from 0 to length-1static AVectorcreateRepeatedElement(int length, double value)Create an immutable vector containing a single repeated value.static AVectorcreateSameSize(AVector v)Creates a new zero-filled vector of the same size as the given Vector.static ScalarcreateScalar(double value)static AVectorcreateSparse(AVector v)Creates a sparse vector from the data in the given vector.static AVectorcreateSparse(java.lang.Object... values)Creates a sparse vector from an array of Object valuesstatic AVectorcreateSparse(java.lang.Object data)Creates a sparse vector from an array of Object valuesstatic AVectorcreateSparseMutable(AVector v)static AVectorcreateSparseMutable(int length)Creates a mutable sparse vector from the data in the given vector.static AVectorcreateUniformRandomVector(int dimensions)Creates a random vector containing the specified number of elements.static AVectorcreateZeroVector(long l)Creates an immutable zero vector of the specified length.static voidfillBinaryRandom(AVector v)static voidfillBinaryRandom(AVector v, double prob)static voidfillGaussian(AVector v)static voidfillGaussian(AVector v, double mean, double sd)static voidfillGaussian(AVector v, double mean, double sd, java.util.Random r)static voidfillGaussian(AVector v, java.util.Random r)static voidfillIndexes(AVector v)Fills a vector with index valuesstatic voidfillNormal(AVector v, long seed)Fills a mutable vector with random normally distributed valuesstatic voidfillNormal(AVector v, java.util.Random random)Fills a mutable vector with random normally distributed valuesstatic voidfillRandom(AVector v)Fills a vector with uniform random numbers in the range [0..1)static voidfillRandom(AVector v, long seed)Fills a mutable vector with random double values in the range [0..1)static voidfillRandom(AVector v, java.util.Random random)Fills a mutable vector with random double values in the range [0..1)static AVectorimmutableZeroVector(int dimensions)Returns an immutable vector of zerosstatic intindexOfMaxValue(AVector v)Deprecated.static intindexOfMinValue(AVector v)Deprecated.static voidinvSqrt(AVector v)static voidinvSqrt(Vector v)static booleanisUncountable(double value)Utility function to test whether a double value is uncountable Uncountable values are NaN and infinitystatic AVectorjoin(AVector... vectors)Join one or more vectors into a single concatenated vectorstatic AVectorjoin(AVector first, AVector second)Creates a joined vector that refers to the two underlying vectorsstatic AVectorjoin(java.util.List<AVector> vectors)Join a list of vectors into a single concatenated vectorstatic doublemaxValue(AVector v)Deprecated.static doubleminValue(AVector v)Deprecated.static AVectornewVector(int length)Returns a new mutable vector filled with zeros of the specified length.static AVectorparse(java.lang.String ednString)Parse a vector in edn formatstatic doublermsDifference(AVector a, AVector b)static intsafeLongToInt(long value)Cast a long to an int value, and throws an exception if the result does not fit in an intstatic voidswap(AVector a, AVector b)Swaps two vectors, mutating both.static doubletotalValue(AVector v)Deprecated.static AVectortoVector(java.lang.Object o)Coerce to AVector.static Vectorwrap(double... data)Wraps a double array as a Vector instance.static AVectorwrap(double[][] data)static ADenseArrayVectorwrap(double[] data, int offset, int length)static AStridedVectorwrapStrided(double[] data, int offset, int length, int stride)
-
-
-
Field Detail
-
TEST_EPSILON
public static final double TEST_EPSILON
Constant tolerance used for testing double values- See Also:
- Constant Field Values
-
MIN_SPARSE_LENGTH
public static final int MIN_SPARSE_LENGTH
Specified the minimum length at which it is worthwhile creating sparse vectors rather than dense vectors. This acts as a hint to modify the behaviour of sparse vector construction functions.- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static AVector create(double... data)
Creates a vector using the given double data, using the most efficient dense representation.- Parameters:
data-- Returns:
-
join
public static AVector join(AVector first, AVector second)
Creates a joined vector that refers to the two underlying vectors- Parameters:
first-second-- Returns:
-
join
public static AVector join(AVector... vectors)
Join one or more vectors into a single concatenated vector- Parameters:
vectors-- Returns:
-
join
public static AVector join(java.util.List<AVector> vectors)
Join a list of vectors into a single concatenated vector- Parameters:
vectors-- Returns:
-
createZeroVector
public static AVector createZeroVector(long l)
Creates an immutable zero vector of the specified length.- Parameters:
l-- Returns:
-
wrap
public static Vector wrap(double... data)
Wraps a double array as a Vector instance. Changes to the double array will be reflected in the Vector- Parameters:
data-- Returns:
-
wrap
public static AVector wrap(double[][] data)
-
wrap
public static ADenseArrayVector wrap(double[] data, int offset, int length)
-
wrapStrided
public static AStridedVector wrapStrided(double[] data, int offset, int length, int stride)
-
newVector
public static AVector newVector(int length)
Returns a new mutable vector filled with zeros of the specified length. Attempts to select the most efficient dense mutable concrete Vector type for any given length.- Parameters:
length-- Returns:
-
createSparse
public static AVector createSparse(AVector v)
Creates a sparse vector from the data in the given vector. Selects the appropriate sparse vector type based on analysis of the element values. The sparse vector may or may not be mutable.- Parameters:
v- Vector containing sparse element data- Returns:
-
createSparse
public static AVector createSparse(java.lang.Object... values)
Creates a sparse vector from an array of Object values- Parameters:
values-- Returns:
-
createSparse
public static AVector createSparse(java.lang.Object data)
Creates a sparse vector from an array of Object values- Parameters:
values-- Returns:
-
createSparseMutable
public static AVector createSparseMutable(int length)
Creates a mutable sparse vector from the data in the given vector. Selects the appropriate sparse vector type based on analysis of the element values.- Parameters:
v- Vector containing sparse element data- Returns:
-
createSameSize
public static AVector createSameSize(AVector v)
Creates a new zero-filled vector of the same size as the given Vector.- Parameters:
v-- Returns:
-
create
public static AVector create(AVector vector)
Creates a mutable clone of a given vector- Parameters:
vector-- Returns:
-
create
public static AVector create(IVector vector)
Creates a mutable clone of a given vector- Parameters:
vector-- Returns:
-
create
public static AVector create(AIndex index)
Creates a new vector containing the values in the specified index- Parameters:
index-- Returns:
-
createScalar
public static Scalar createScalar(double value)
-
createUniformRandomVector
public static AVector createUniformRandomVector(int dimensions)
Creates a random vector containing the specified number of elements. Each element will be randomly distributed in the range [0,1)- Parameters:
dimensions-- Returns:
-
immutableZeroVector
public static AVector immutableZeroVector(int dimensions)
Returns an immutable vector of zeros- Parameters:
dimensions-- Returns:
-
parse
public static AVector parse(java.lang.String ednString)
Parse a vector in edn format- Parameters:
ednString-- Returns:
-
create
public static AVector create(java.util.List<java.lang.Object> d)
Create a vector from a list of numerical values (objects should be java.lang.Number instances)
-
create
public static AVector create(java.nio.DoubleBuffer d)
Create a vector from a DoubleBuffer Note: consumes all doubles from the buffer
-
create
public static AVector create(java.lang.Iterable<java.lang.Object> d)
Create a vector from an arbitrary iterable object- Parameters:
d-- Returns:
-
minValue
@Deprecated public static double minValue(AVector v)
Deprecated.Returns the minimum-valued component in a vector- Parameters:
v-- Returns:
-
indexOfMinValue
@Deprecated public static int indexOfMinValue(AVector v)
Deprecated.Returns the index of the minimum-valued component in a vector- Parameters:
v-- Returns:
-
maxValue
@Deprecated public static double maxValue(AVector v)
Deprecated.
-
indexOfMaxValue
@Deprecated public static int indexOfMaxValue(AVector v)
Deprecated.
-
invSqrt
public static void invSqrt(AVector v)
-
swap
public static void swap(AVector a, AVector b)
Swaps two vectors, mutating both.- Parameters:
a-b-
-
invSqrt
public static void invSqrt(Vector v)
-
totalValue
@Deprecated public static double totalValue(AVector v)
Deprecated.
-
averageValue
@Deprecated public static double averageValue(AVector v)
Deprecated.
-
averageSquaredDifference
@Deprecated public static double averageSquaredDifference(AVector a, AVector b)
Deprecated.
-
fillRandom
public static void fillRandom(AVector v)
Fills a vector with uniform random numbers in the range [0..1)- Parameters:
v-
-
fillIndexes
public static void fillIndexes(AVector v)
Fills a vector with index values- Parameters:
v-
-
fillGaussian
public static void fillGaussian(AVector v)
-
fillGaussian
public static void fillGaussian(AVector v, java.util.Random r)
-
fillGaussian
public static void fillGaussian(AVector v, double mean, double sd)
-
fillGaussian
public static void fillGaussian(AVector v, double mean, double sd, java.util.Random r)
-
fillBinaryRandom
public static void fillBinaryRandom(AVector v)
-
axisVector
public static AVector axisVector(int axisIndex, int dimensions)
-
fillBinaryRandom
public static void fillBinaryRandom(AVector v, double prob)
-
toVector
public static AVector toVector(java.lang.Object o)
Coerce to AVector. Avoids copying if possible.- Parameters:
o-- Returns:
-
create
public static AVector create(java.lang.Object o)
Creates a vector from the given source data. Copies undelying data as needed.- Parameters:
o-- Returns:
-
createMutableRange
public static AVector createMutableRange(int length)
Create a mutable vector contain the sequence of integers from 0 to length-1- Parameters:
length- The length of vector to create- Returns:
-
createRange
public static AVector createRange(int length)
Create an immutable vector contain the sequence of integers from 0 to length-1- Parameters:
length- The length of vector to create- Returns:
-
createRepeatedElement
public static AVector createRepeatedElement(int length, double value)
Create an immutable vector containing a single repeated value. Guaranteed to be O(1).- Parameters:
length-value-- Returns:
-
safeLongToInt
public static int safeLongToInt(long value)
Cast a long to an int value, and throws an exception if the result does not fit in an int- Parameters:
value- A long value- Returns:
- An int equal to the long value argument
- Throws:
java.lang.IllegalArgumentException- if the long value is out of range for an int
-
fillRandom
public static void fillRandom(AVector v, long seed)
Fills a mutable vector with random double values in the range [0..1)
-
fillRandom
public static void fillRandom(AVector v, java.util.Random random)
Fills a mutable vector with random double values in the range [0..1)
-
fillNormal
public static void fillNormal(AVector v, long seed)
Fills a mutable vector with random normally distributed values
-
fillNormal
public static void fillNormal(AVector v, java.util.Random random)
Fills a mutable vector with random normally distributed values
-
isUncountable
public static boolean isUncountable(double value)
Utility function to test whether a double value is uncountable Uncountable values are NaN and infinity- Parameters:
value-- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG