Class Dimensions
- java.lang.Object
-
- com.singularsys.extensions.matrix.Dimensions
-
- All Implemented Interfaces:
java.io.Serializable
public class Dimensions extends java.lang.Object implements java.io.Serializable
A class to represent a set of dimensions giving the size of a vector or matrix. Might be 1 for 0-dimensional numbers. [3] for a 3D vector [3,3] for a matrix- Author:
- rich Created on 25-Oct-2003
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Dimensions
EMPTY_VECTOR
static Dimensions
ONE
Deprecated.static Dimensions
ONE_ELEMENT_VECTOR
static Dimensions
SCALER
static Dimensions
THREE
static Dimensions
TWO
static Dimensions
UNKNOWN
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object arg)
boolean
equalsDim(Dimensions dims2)
Two dimensions are equal if the element of dims are the same.int
getFirstDim()
get the first dimension, 1 for numbers, or the length of a vector.int
getIthDim(int i)
Get the value of the i-th dimension.int
getLastDim()
get the last dimension, 1 for numbers, or the length of a vector.int
hashCode()
boolean
is0D()
Is it 0D, ie a simple number.boolean
is1D()
Is it 1D, ie a vector [1,2,3].boolean
is2D()
Is it 2D, ie a matrix [[1,2,3],[4,5,6]].int
numEles()
The total number of elements.int
order()
Order of dimensions 0 for numbers, 1 for vectors, 2 for matricesjava.lang.String
toString()
A string representation.static Dimensions
valueOf(int d)
Deprecated.static Dimensions
valueOf(int[] dims)
returns a dimensions with given dimensions.static Dimensions
valueOf(int rows, int cols)
returns dimensions for a matrix.static Dimensions
valueOf(int d, Dimensions inDim)
return a dimension [d,inDim[0],...static Dimensions
valueOf(Dimensions inDim, int d)
return a dimension [inDim[0],...static Dimensions
valueOf(MatrixI mat)
static Dimensions
valueOf(VectorI vec)
static Dimensions
valueOfVec(int d)
Factory method, treating an argument of 1 as a vector with a single element.static Dimensions
valueOfVecOrScaler(int d)
Factory method, treating an argument of 1 as a scaler.
-
-
-
Field Detail
-
UNKNOWN
public static final Dimensions UNKNOWN
-
SCALER
public static final Dimensions SCALER
-
EMPTY_VECTOR
public static final Dimensions EMPTY_VECTOR
-
ONE_ELEMENT_VECTOR
public static final Dimensions ONE_ELEMENT_VECTOR
-
TWO
public static final Dimensions TWO
-
THREE
public static final Dimensions THREE
-
ONE
@Deprecated public static final Dimensions ONE
Deprecated.An ambiguous value which could be confused with a vector with a single element.
-
-
Method Detail
-
valueOf
@Deprecated public static Dimensions valueOf(int d)
Deprecated.Factory method returns a Dimension for vector of given length. For 0, 1,2,3 returns constantsEMPTY_VECTOR
,SCALER
,TWO
orTHREE
otherwise create a new object. This method treats an argument of 1 as a Scaler, rather than a vector with one element its preferable to usevalueOfVec(int)
orvalueOfVecOrScaler(int)
to make the interpretation clear.
-
valueOfVecOrScaler
public static Dimensions valueOfVecOrScaler(int d)
Factory method, treating an argument of 1 as a scaler.- Parameters:
d
- either 1 for a scaler or an positive or zero number for vectors with that many elements- Returns:
- dimensions type
-
valueOfVec
public static Dimensions valueOfVec(int d)
Factory method, treating an argument of 1 as a vector with a single element.- Parameters:
d
- dimension of the vector, a positive or zero integer- Returns:
- dimensions type
-
valueOf
public static Dimensions valueOf(int rows, int cols)
returns dimensions for a matrix.
-
valueOf
public static Dimensions valueOf(int d, Dimensions inDim)
return a dimension [d,inDim[0],...,inDim[n]]
-
valueOf
public static Dimensions valueOf(Dimensions inDim, int d)
return a dimension [inDim[0],...,inDim[n],d]
-
valueOf
public static Dimensions valueOf(int[] dims)
returns a dimensions with given dimensions.- Parameters:
dims
- list of dimensions, with no elements for a scaler, a single element for vector, two elements for matricies Logic changed when [1] passed in.
-
valueOf
public static Dimensions valueOf(VectorI vec)
-
valueOf
public static Dimensions valueOf(MatrixI mat)
-
getFirstDim
public int getFirstDim()
get the first dimension, 1 for numbers, or the length of a vector. for a matrix [[1,2,3],[4,5,6]] first dim is number of rows eg 2
-
getLastDim
public int getLastDim()
get the last dimension, 1 for numbers, or the length of a vector. for a matrix [[1,2,3],[4,5,6]] last dim is number of cols eg 3
-
getIthDim
public int getIthDim(int i)
Get the value of the i-th dimension.- Parameters:
i
- index based at zero- Returns:
- value of ith dim or -1 if out of range
-
is0D
public boolean is0D()
Is it 0D, ie a simple number.
-
is1D
public boolean is1D()
Is it 1D, ie a vector [1,2,3].
-
is2D
public boolean is2D()
Is it 2D, ie a matrix [[1,2,3],[4,5,6]].
-
numEles
public int numEles()
The total number of elements. Produce of all the dimensions.
-
order
public int order()
Order of dimensions 0 for numbers, 1 for vectors, 2 for matrices
-
toString
public java.lang.String toString()
A string representation. Either 1,[n],[m, n],[l, m, n] etc.- Overrides:
toString
in classjava.lang.Object
-
equalsDim
public boolean equalsDim(Dimensions dims2)
Two dimensions are equal if the element of dims are the same.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object arg)
- Overrides:
equals
in classjava.lang.Object
-
-