Class Vector
- All Implemented Interfaces:
Serializable
,DenseMixin<Double>
,DenseVectorMixin
,RealTensorMixin<Vector,
,CVector> TensorComparisonsMixin
,TensorManipulationsMixin<Vector>
,TensorOperationsMixin<Vector,
,Vector, CVector, CVector, Vector, Double> TensorPropertiesMixin
,VectorComparisonsMixin
,VectorManipulationsMixin<Matrix>
,VectorMixin<Vector,
,Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> VectorOperationsMixin<Vector,
,Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> VectorPropertiesMixin
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ConstructorDescriptionVector
(double... entries) Creates a vector with specified entries.Vector
(int size) Creates a vector of specified size filled with zeros.Vector
(int... entries) Creates a vector with specified entries.Vector
(int size, double fillValue) Creates a vector of specified size filled with a specified value.Creates a vector from another vector.Creates a vector of the specified shape filled with zeros.Creates a vector of specified size filled with a specified value. -
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise addition between this vector and the specified vector.add
(CooCVector B) Computes the element-wise addition between this vector and the specified vector.Computes the element-wise addition between this vector and the specified vector.void
Computes the element-wise addition between this vector and the specified vector.Computes the vector cross product between two vectors.Computes the vector cross product between two vectors.Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.boolean
Checks if an object is equal to this vector object.extend
(int n, int axis) Extends a vector a specified number of times to a matrix.flatten()
Since vectors are rank 1 tensors, this method simply copies the vector.flatten
(int axis) Flattens a tensor along the specified axis.protected Vector
getSelf()
Simply returns this tensor.Computes the inner product between two vectors.Computes the inner product between two vectors.inner
(CooCVector b) Computes the inner product between two vectors.Computes the inner product between two vectors.boolean
isParallel
(Vector b) Checks if a vector is parallel to this vector.boolean
Checks if a vector is perpendicular to this vector.Joints specified vector with this vector.Joints specified vector with this vector.join
(CooCVector b) Joints specified vector with this vector.Joints specified vector with this vector.int
length()
Gets the length of a vector.protected CVector
makeComplexTensor
(Shape shape, double[] entries) Factory to create a complex tensor with the specified shape and size.protected CVector
makeComplexTensor
(Shape shape, CNumber[] entries) Factory to create a complex tensor with the specified shape and size.protected Vector
makeTensor
(Shape shape, double[] entries) Factory to create a tensor with the specified shape and size.Computes a unit vector in the same direction as this vector.Computes the outer product of two vectors.Computes the outer product of two vectors.outer
(CooCVector b) Computes the outer product of two vectors.Computes the outer product of two vectors.repeat
(int n, int axis) Repeats a vectorn
times along a certain axis to create a matrix.int
size()
gets the size of this vector.Stacks two vectors along columns.Stacks two vectors along specified axis.Stacks two vectors along columns as if they were row vectors.Stacks two vectors along specified axis.stack
(CooCVector b) Stacks two vectors along columns.stack
(CooCVector b, int axis) Stacks two vectors along specified axis.Stacks two vectors along columns.Stacks two vectors along specified axis.Computes the element-wise addition between this vector and the specified vector.sub
(CooCVector B) Computes the element-wise addition between this vector and the specified vector.Computes the element-wise addition between this vector and the specified vector.void
Computes the element-wise addition between this vector and the specified vector.T()
Computes the transpose of a tensor.toCoo()
Converts this dense vector to an equivalentCooVector
.toMatrix()
Converts a vector to an equivalent matrix representing the vector as a column.toMatrix
(boolean columVector) Converts a vector to an equivalent matrix representing either a row or column vector.toString()
Converts this vector to a human-readable string format.toTensor()
Converts this vector to an equivalent tensor.Computes the transpose of a tensor.Methods inherited from class org.flag4j.core.dense_base.RealDenseTensorBase
abs, add, add, add, addEq, addEq, allClose, argMax, argMin, copy, div, div, elemDiv, elemMult, get, hashCode, isNeg, isOnes, isPos, isZeros, max, maxAbs, min, minAbs, mult, mult, recip, reshape, reshape, round, round, roundToZero, roundToZero, set, sqrt, sub, sub, sub, subEq, subEq, sum, toComplex
Methods inherited from class org.flag4j.core.TensorBase
allClose, getEntries, getRank, getShape, sameLength, sameShape, tensorEquals, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.flag4j.core.dense_base.DenseVectorMixin
addEq, subEq
Methods inherited from interface org.flag4j.core.VectorOperationsMixin
add, elemDiv, elemMult, sub
Methods inherited from interface org.flag4j.core.VectorPropertiesMixin
maxAbs
-
Field Details
-
size
public final int sizeThe size of this vector. That is, the number of entries in this vector.
-
-
Constructor Details
-
Vector
public Vector(int size) Creates a vector of specified size filled with zeros.- Parameters:
size
- Size of the vector.
-
Vector
public Vector(int size, double fillValue) Creates a vector of specified size filled with a specified value.- Parameters:
size
- Size of the vector.fillValue
- Value to fill vector with.
-
Vector
Creates a vector of the specified shape filled with zeros.- Parameters:
shape
- Shape of this vector.- Throws:
IllegalArgumentException
- If the shapes is not rank 1.
-
Vector
Creates a vector of specified size filled with a specified value.- Parameters:
shape
- Shape of the vector.fillValue
- Value to fill vector with.- Throws:
IllegalArgumentException
- If the shapes is not rank 1.
-
Vector
public Vector(double... entries) Creates a vector with specified entries.- Parameters:
entries
- Entries for this column vector.
-
Vector
public Vector(int... entries) Creates a vector with specified entries.- Parameters:
entries
- Entries for this column vector.
-
Vector
Creates a vector from another vector. This essentially copies the vector.- Parameters:
a
- Vector to make copy of.
-
-
Method Details
-
equals
Checks if an object is equal to this vector object.- Specified by:
equals
in interfaceTensorComparisonsMixin
- Overrides:
equals
in classObject
- Parameters:
object
- Object to check equality with this vector.- Returns:
- True if the two vectors have the same shape, are numerically equivalent, and are of type
Vector
. False otherwise.
-
flatten
Since vectors are rank 1 tensors, this method simply copies the vector.- Specified by:
flatten
in interfaceTensorManipulationsMixin<Vector>
- Returns:
- The flattened tensor.
-
extend
Extends a vector a specified number of times to a matrix.- Specified by:
extend
in interfaceVectorManipulationsMixin<Matrix>
- Parameters:
n
- The number of times to extend this vector.axis
- Axis along which to extend. Ifaxis=0
, then the vector will be treated as a row vector. Ifaxis=1
then the vector will be treated as a column vector.- Returns:
- A matrix which is the result of extending a vector
n
times. - Throws:
IllegalArgumentException
- If axis is not 0 or 1.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
add
Computes the element-wise addition between this vector and the specified vector.- Specified by:
add
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Computes the element-wise addition between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Computes the element-wise addition between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
sub
Computes the element-wise addition between this vector and the specified vector.- Specified by:
sub
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to add to this vector.- Returns:
- The result of the element-wise vector addition.
- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
addEq
Computes the element-wise addition between this vector and the specified vector. The result is stored in this vector.- Specified by:
addEq
in interfaceDenseVectorMixin
- Parameters:
B
- Vector to add to this vector.- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
subEq
Computes the element-wise addition between this vector and the specified vector. The result is stored in this vector.- Specified by:
subEq
in interfaceDenseVectorMixin
- Parameters:
B
- Vector to add to this vector.- Throws:
IllegalArgumentException
- If this vector and the specified vector have different lengths.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
elemMult
Computes the element-wise multiplication (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemMult
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to element-wise multiply to this vector.- Returns:
- The vector resulting from the element-wise multiplication.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
elemDiv
Computes the element-wise division (Hadamard multiplication) between this vector and a specified vector.- Specified by:
elemDiv
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
B
- Vector to element-wise divide this vector by.- Returns:
- The vector resulting from the element-wise division.
- Throws:
IllegalArgumentException
- If this vector andB
do not have the same size.
-
transpose
-
T
Computes the transpose of a tensor. For a vector, this just copies the vector.
Same astranspose()
. -
join
Joints specified vector with this vector. -
join
Joints specified vector with this vector. -
join
Joints specified vector with this vector. -
join
Joints specified vector with this vector. -
stack
Stacks two vectors along columns as if they were row vectors.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector b.
- Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vector b.
-
stack
Stacks two vectors along columns.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector b.
- Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vector b.
-
stack
Stacks two vectors along columns.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector b.
- Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vector b.
-
stack
Stacks two vectors along columns.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack to the bottom of this vector.- Returns:
- The result of stacking this vector and vector b.
- Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vector b.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
stack
Stacks two vectors along specified axis.
Stacking two vectors of length
n
along axis 0 stacks the vectors as if they were row vectors resulting in a2-by-n
matrix.Stacking two vectors of length
n
along axis 1 stacks the vectors as if they were column vectors resulting in an-by-2
matrix.- Specified by:
stack
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to stack with this vector.axis
- Axis along which to stack vectors. Ifaxis=0
, then vectors are stacked as if they are row vectors. Ifaxis=1
, then vectors are stacked as if they are column vectors.- Returns:
- The result of stacking this vector and the vector
b
. - Throws:
IllegalArgumentException
- If the number of entries in this vector is different from the number of entries in the vectorb
.IllegalArgumentException
- If axis is not either 0 or 1.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
normalize
Computes a unit vector in the same direction as this vector. -
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
inner
Computes the inner product between two vectors.- Specified by:
inner
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the inner product.- Returns:
- The inner product between this vector and the vector b.
- Throws:
IllegalArgumentException
- If this vector and vector b do not have the same number of entries.
-
cross
Computes the vector cross product between two vectors.- Parameters:
b
- Second vector in the cross product.- Returns:
- The result of the vector cross product between this vector and b.
- Throws:
IllegalArgumentException
- If either this vector or b do not have exactly 3 entries.
-
cross
Computes the vector cross product between two vectors.- Parameters:
b
- Second vector in the cross product.- Returns:
- The result of the vector cross product between this vector and b.
- Throws:
IllegalArgumentException
- If either this vector or b do not have 3 entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
outer
Computes the outer product of two vectors.- Specified by:
outer
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Second vector in the outer product.- Returns:
- The result of the vector outer product between this vector and b.
- Throws:
IllegalArgumentException
- If the two vectors do not have the same number of entries.
-
isParallel
Checks if a vector is parallel to this vector.- Specified by:
isParallel
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
b
- Vector to compare to this vector.- Returns:
- True if the vector
b
is parallel to this vector and the same size. Otherwise, returns false.
-
isPerp
Checks if a vector is perpendicular to this vector. -
toMatrix
-
toMatrix
Converts a vector to an equivalent matrix representing either a row or column vector.- Specified by:
toMatrix
in interfaceVectorOperationsMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
columVector
- Flag for choosing whether to convert this vector to a matrix representing a row or column vector.If true, the vector will be converted to a matrix representing a column vector.
If false, The vector will be converted to a matrix representing a row vector.
- Returns:
- A matrix equivalent to this vector.
-
toTensor
Converts this vector to an equivalent tensor.- Returns:
- A tensor which is equivalent to this vector.
-
makeTensor
Factory to create a tensor with the specified shape and size.- Specified by:
makeTensor
in classDenseTensorBase<Vector,
CVector, Vector, double[], Double> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
makeComplexTensor
Factory to create a complex tensor with the specified shape and size.- Specified by:
makeComplexTensor
in classRealDenseTensorBase<Vector,
CVector> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
makeComplexTensor
Factory to create a complex tensor with the specified shape and size.- Specified by:
makeComplexTensor
in classRealDenseTensorBase<Vector,
CVector> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
toCoo
-
getSelf
-
length
public int length()Gets the length of a vector. Same assize()
- Specified by:
length
in interfaceVectorPropertiesMixin
- Returns:
- The length, i.e. the number of entries, in this vector.
-
size
-
repeat
Repeats a vectorn
times along a certain axis to create a matrix.- Specified by:
repeat
in interfaceVectorMixin<Vector,
Vector, CooVector, CVector, Double, Matrix, Matrix, CMatrix> - Parameters:
n
- Number of times to repeat vector.axis
- Axis along which to repeat vector. Ifaxis=0
then each row of the resulting matrix will be equivalent to this vector. Ifaxis=1
then each column of the resulting matrix will be equivalent to this vector.- Returns:
- A matrix whose rows/columns are this vector repeated.
-
flatten
Flattens a tensor along the specified axis. For a vector, this simply copies the vector.- Specified by:
flatten
in interfaceTensorManipulationsMixin<Vector>
- Parameters:
axis
- Axis along which to flatten tensor.- Throws:
IllegalArgumentException
- If the axis is not positive or larger thanthis.
.TensorBase.getRank()
-1
-
toString
Converts this vector to a human-readable string format. To specify the maximum number of entries to print, usePrintOptions.setMaxColumns(int)
.
-