All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lsmp.djep.vectorJep.Dimensions Maven / Gradle / Ivy

Go to download

JEP is a Java library for parsing and evaluating mathematical expressions.

The newest version!
/* @author rich
 * Created on 25-Oct-2003
 */
package org.lsmp.djep.vectorJep;


/**
 * A class to represent a set of dimensions.
 * Might be 1 for 0-dimensional numbers.
 * [3] for a 3D vector
 * [3,3] for a matrix
 * @author rich
 * Created on 25-Oct-2003
 */
public class Dimensions
{
	private int dims[];
	public static final Dimensions UNKNOWN = new Dimensions(-1);
	public static final Dimensions ONE = new Dimensions(1);
	public static final Dimensions TWO = new Dimensions(2);
	public static final Dimensions THREE = new Dimensions(3);
	
	private Dimensions() {}	
	/** Sets the dimension to a single number. Implies its a Scaler or MVector. */
	private Dimensions(int d) {	dims = new int[] {d};	}
	/** Use this method for matrices. */
	private Dimensions(int d1,int d2) {	dims = new int[] {d1,d2}; }
	/** Construct a dimension set from an array. */
	private Dimensions(int d[])	
	{
		dims = new int[d.length];
		System.arraycopy(d,0,dims,0,d.length);
	}
	/**
	 * Factory method returns a Dimension for vector of given length.
	 * For 1,2,3 returns ONE,TWO or THREE otherwise create a new object.
	 */ 
	public static Dimensions valueOf(int d)
	{ 
		switch(d) {
			case 1: return Dimensions.ONE;
			case 2: return Dimensions.TWO;
			case 3: return Dimensions.THREE;
			default:
				return new Dimensions(d);
		}
	}
	/** returns dimensions for a matrix. **/
	public static Dimensions valueOf(int rows,int cols)
	{ 
		return new Dimensions(rows,cols);
	}
	/** return a dimension [d,inDim[0],...,inDim[n]] */
	public static Dimensions valueOf(int d,Dimensions inDim)
	{ 
		Dimensions res = new Dimensions();
		res.dims = new int[inDim.rank()+1];
		res.dims[0]=d;
		for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy