## gov.sandia.cognition.math.matrix Class VectorUtil

```java.lang.Object gov.sandia.cognition.math.matrix.VectorUtil
```

`public class VectorUtilextends Object`

Utility methods for dealing with vectors.

Since:
3.0
Author:
Justin Basilico

Constructor Summary
`VectorUtil()`

Method Summary
`static void` ```assertDimensionalitiesAllEqual(Iterable<? extends Vectorizable> data, int dimensionality)```
Asserts that all of the dimensionalities of the vectors in the given set of data equal the given dimensionality.
`static Vector` `divideByNorm1(Vector input)`
Returns a new vector whose elements are the elements of the original vector, divided by the 1-norm of the vector (the sum of the absolute values of the elements).
`static void` `divideByNorm1Equals(Vector vector)`
Divides all of the given elements of the vector by the 1-norm (the sum of the absolute values of the elements.
`static Vector` ```interpolateLinear(Vectorizable first, Vectorizable second, double percent)```
Performs linear interpolation between two vectors.
`static Vector` ```interpolateLinear(Vector first, Vector second, double percent)```
Performs linear interpolation between two vectors.
`static int` `safeGetDimensionality(Vector vector)`
Gets the dimensionality of the given vector, if it is not null.
`static int` `safeGetDimensionality(Vectorizable vector)`
Gets the dimensionality of the given vector, if it is not null.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### VectorUtil

`public VectorUtil()`
Method Detail

### safeGetDimensionality

`public static int safeGetDimensionality(Vectorizable vector)`
Gets the dimensionality of the given vector, if it is not null. Otherwise, -1 is returned.

Parameters:
`vector` - The vector to get the dimensionality of.
Returns:
The dimensionality of the given vector, if it is not null. Otherwise, -1 is returned.

### safeGetDimensionality

`public static int safeGetDimensionality(Vector vector)`
Gets the dimensionality of the given vector, if it is not null. Otherwise, -1 is returned.

Parameters:
`vector` - The vector to get the dimensionality of.
Returns:
The dimensionality of the given vector, if it is not null. Otherwise, -1 is returned.

### divideByNorm1

`public static Vector divideByNorm1(Vector input)`
Returns a new vector whose elements are the elements of the original vector, divided by the 1-norm of the vector (the sum of the absolute values of the elements). If the 1-norm is zero (which means all the elements are zero), then the result is just a duplicate of the input (zero) vector.

Parameters:
`input` - The vector to divide by its 1-norm.
Returns:
A new vector whose elements are the elements from the given vector, divided by its 1-norm.

### divideByNorm1Equals

`public static void divideByNorm1Equals(Vector vector)`
Divides all of the given elements of the vector by the 1-norm (the sum of the absolute values of the elements. If the 1-norm is zero (which means all the elements are zero), then the vector is not modified.

Parameters:
`vector` - The vector to divide the elements by the 1-norm. It is modified by this method.

### interpolateLinear

```public static Vector interpolateLinear(Vectorizable first,
Vectorizable second,
double percent)```
Performs linear interpolation between two vectors. If percent is between 0.0 and 1.0, the result is: percent (y - x) + x. If percent is less than 0.0, the result is x. If percent is greater than 1.0, the result is y.

Parameters:
`first` - The first vector. Sometimes this is referred to as x.
`second` - The second vector. Sometimes this is referred to as y.
`percent` - A value between 0.0 and 1.0 to interpolate between the two vectors. Sometimes this is also referred to as alpha.
Returns:
A new vector that is linearly interpolated between the two vectors vectors.

### interpolateLinear

```public static Vector interpolateLinear(Vector first,
Vector second,
double percent)```
Performs linear interpolation between two vectors. If percent is between 0.0 and 1.0, the result is: percent * (y - x) + x. If percent is less than 0.0, the result is x. If percent is greater than 1.0, the result is y.

Parameters:
`first` - The first vector. Sometimes this is referred to as x.
`second` - The second vector. Sometimes this is referred to as y.
`percent` - A value between 0.0 and 1.0 to interpolate between the two vectors. Sometimes this is also referred to as alpha.
Returns:
A new vector that is linearly interpolated between the two vectors vectors.

### assertDimensionalitiesAllEqual

```public static void assertDimensionalitiesAllEqual(Iterable<? extends Vectorizable> data,
int dimensionality)```
Asserts that all of the dimensionalities of the vectors in the given set of data equal the given dimensionality.

Parameters:
`data` - A collection of input-output pairs.
`dimensionality` - The dimensionality that all the inputs must have.
Throws:
`DimensionalityMismatchException` - If the dimensionalities are not all equal.