Class Dimensions

java.lang.Object
com.singularsys.extensions.matrix.Dimensions
All Implemented Interfaces:
Serializable

public class Dimensions extends Object implements 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 In Versions 2.2 the constant SCALER has been changed to SCALAR
See Also:
  • Field Details

  • Method Details

    • valueOf

      @Deprecated public static Dimensions valueOf(int d)
      Factory method returns a Dimension for vector of given length. For 0, 1,2,3 returns constants EMPTY_VECTOR, SCALAR, TWO or THREE otherwise create a new object. This method treats an argument of 1 as a Scalar, rather than a vector with one element
    • valueOfVecOrScalar

      public static Dimensions valueOfVecOrScalar(int d)
      Factory method, treating an argument of 1 as a scalar.
      Parameters:
      d - either 1 for a scalar or a positive or zero number for vectors with that many elements
      Returns:
      dimensions type
      Since:
      Extension 2.2
    • 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 scalar, a single element for vector, two elements for matrices 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 String toString()
      A string representation. Either 1,[n],[m, n],[l, m, n] etc.
      Overrides:
      toString in class 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 class Object
    • equals

      public boolean equals(Object arg)
      Overrides:
      equals in class Object