Class 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 Detail

      • EMPTY_VECTOR

        public static final Dimensions EMPTY_VECTOR
      • ONE_ELEMENT_VECTOR

        public static final Dimensions ONE_ELEMENT_VECTOR
      • 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 constants EMPTY_VECTOR, SCALER, TWO or THREE 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 use valueOfVec(int) or valueOfVecOrScaler(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.
      • 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 class java.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 class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object arg)
        Overrides:
        equals in class java.lang.Object