Class pmr.euclid.RealArray
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class pmr.euclid.RealArray

java.lang.Object
   |
   +----pmr.euclid.Status
           |
           +----pmr.euclid.RealArray

public class RealArray
extends Status

RealArray - array of doubles

RealArray represents a 1-dimensional vector/array of doubles and is basically a wrapper for double[] in Java There are a lot of useful member functions (sorting, ranges, parallel operations, etc. - have a look)

The default is an array with zero points. All arrays are valid objects.

Attempting to create an array with < 0 points creates a default array (zero points).

Since double[] knows its length (unlike C), there are many cases where double[] can be safely used. However it is not a first-class object and RealArray supplies this feature. double[] is referenceable through getArray().

Author:
(C) P. Murray-Rust, 1996

Constructor Index

 o RealArray()
default is an array of zero points
 o RealArray(double[])
from an existing double[] (which knows its length)
 o RealArray(int)
creates n-element array initialised to 0.0
 o RealArray(int, double)
set all elements of the array to a given value
 o RealArray(int, double, double)
This gives a nelem-element array initialised to elem1+(i-1)*delta
 o RealArray(int, double[])
Formed by feeding in an existing array; requires the size.
 o RealArray(int, String, double)
Create a given 'shape' of array for data filtering.
 o RealArray(IntArray)
convert an IntArray to a RealArray
 o RealArray(RealArray)
copy constructor
 o RealArray(RealArray, int, int)
subarray of another array - inclusive; if low > high or other silly indices, creates default array
 o RealArray(String)
from a String with space-separated strings representing Reals
 o RealArray(String[])
from an array of Strings (which must represent Reals)

Method Index

 o absSumAllElements()
absolute sum of all elements
 o addArray(RealArray)
append elements
 o addElement(double)
append element
 o applyFilter(RealArray)
apply filter (i.e.
 o clearArray()
clear all elements of array
 o clone()
clones another RealArray
 o copy(double[])
copy a double[] into a new one
 o cumulativeSum()
cumulative sum of array (new RA contains
elem[i] = sum(k = 0 to i) f[k]

does not modify 'this'

 o deleteElement(int)
delete element and close up; if outside range, take no action
 o deleteElements(double[], int, int)
delete elements (lo - > hi inclusive) in a float[] and close up; if hi >= float.length hi is reset to float.length-1.
 o deleteElements(int, int)
delete elements and close up; if outside range take no action
 o dotProduct(RealArray)
dot product of two RealArrays - if of same length - else zero
 o elementAt(int)
extracts a given element from the array
 o equals(RealArray)
are two arrays equal in all elements?
 o equals(RealArray, double)
are two arrays equal in all elements? (use epsilon as tolerance)
 o euclideanLength()
Euclidean length of vector
 o getArray()
return the array as a double[]; this has to resize the array to the precise length used , or confusion will result! Note that this gives the user access to the actual array, so that they can alter its contents.
 o getReorderedArray(IntSet)
reorder by index in IntSet; does NOT modify array
 o getReverseArray()
return the elements in reverse order as double[]
 o getStringValues()
returns values as strings
 o getSubArray(int, int)
RHS: get a subRealArray from element start to end
 o indexOfLargestElement()
index of largest element; returns -1 if zero element array
 o indexOfSmallestElement()
index of smallest element
 o indexSortAscending()
 o indexSortDescending()
sort array into descending order via indexes; array NOT MODIFIED
 o innerProduct()
inner product - same as dotProduct
 o inRange(RealRange)
return index of elements within a given range
 o insertArray(int, RealArray)
insert a RealArray at position elem and expand
 o insertElementAt(int, double)
insert element and expand; if outside range, take no action
 o isClear()
is the array filled with zeros?
 o largestElement()
value of largest element
 o main(String[])
 o multiplyBy(double)
array multiplication by a scalar; does NOT modify 'this'
 o negative()
change the sign of all elements; MODIFIES this
 o outOfRange(RealRange)
return index of elements outside a given range
 o plus(RealArray)
array addition - adds conformable arrays
 o range()
range of array (default RealRange for zero array)
 o reverse()
MODIFIES array to be in reverse order
 o rms()
root mean square sqrt(sigma(x(i)**2)/n)
 o setAllElements(double)
initialise array to given double[]
 o setElementAt(int, double)
set a given element into the array; must be less than current max index
 o setElements(int, double[])
copy a smaller array into the array statrting at start
 o setMaxIndex(int)
reset the maximum index (for when poking elements) (no other effect)
 o shallowCopy(RealArray)
shallowCopy
 o size()
get actual number of elements
 o smallestElement()
value of smallest element
 o sortAscending()
MODIFIES array to be in ascending order
 o sortDescending()
MODIFIES array to be in ascending order
 o subtract(RealArray)
array subtraction - subtracts conformable arrays
 o sumAllElements()
sum all elements
 o test()
 o toString()
concatenates values with spaces
 o unitVector()
get unit vector

Constructors

 o RealArray
  public RealArray()
default is an array of zero points
 o RealArray
  public RealArray(int n)
creates n-element array initialised to 0.0
 o RealArray
  public RealArray(int n,
                   double elem1,
                   double delta)
This gives a nelem-element array initialised to elem1+(i-1)*delta
 o RealArray
  public RealArray(int n,
                   double elem1)
set all elements of the array to a given value
 o RealArray
  public RealArray(int n,
                   double arr[])
Formed by feeding in an existing array; requires the size. (You can use the *.length of the array if necessary)
 o RealArray
  public RealArray(double arr[])
from an existing double[] (which knows its length)
 o RealArray
  public RealArray(IntArray ia)
convert an IntArray to a RealArray
 o RealArray
  public RealArray(RealArray m,
                   int low,
                   int high)
subarray of another array - inclusive; if low > high or other silly indices, creates default array
 o RealArray
  public RealArray(RealArray m)
copy constructor
 o RealArray
  public RealArray(int nn,
                   String shape,
                   double maxval)
Create a given 'shape' of array for data filtering. An intended use is with RealArray.arrayFilter(). The shapes (before scaling by maxval) are:
 o RealArray
  public RealArray(String strings[]) throws NumberFormatException
from an array of Strings (which must represent Reals)
Throws: NumberFormatException
a string could not be interpreted as Real
 o RealArray
  public RealArray(String string) throws NumberFormatException
from a String with space-separated strings representing Reals
Throws: NumberFormatException
a string could not be interpreted as Real

Methods

 o clone
  public Object clone()
clones another RealArray
Overrides:
clone in class Object
 o shallowCopy
  public void shallowCopy(RealArray m)
shallowCopy
 o elementAt
  public double elementAt(int elem) throws ArrayIndexOutOfBoundsException
extracts a given element from the array
Throws: ArrayIndexOutOfBoundsException
elem >= size of this
 o size
  public int size()
get actual number of elements
 o getArray
  public double[] getArray()
return the array as a double[]; this has to resize the array to the precise length used , or confusion will result! Note that this gives the user access to the actual array, so that they can alter its contents. This should be used with care, but Java should stop any access outside the buffer limits.
 o clearArray
  public void clearArray()
clear all elements of array
 o getReverseArray
  public double[] getReverseArray()
return the elements in reverse order as double[]
 o setMaxIndex
  public void setMaxIndex(int max)
reset the maximum index (for when poking elements) (no other effect)
 o equals
  public boolean equals(RealArray f) throws UnequalLengthArraysException
are two arrays equal in all elements?
Throws: UnequalLengthArraysException
f is different size from this
 o equals
  public boolean equals(RealArray f,
                        double epsilon) throws UnequalLengthArraysException
are two arrays equal in all elements? (use epsilon as tolerance)
Throws: UnequalLengthArraysException
f is different size from this
 o plus
  public RealArray plus(RealArray f) throws UnequalLengthArraysException
array addition - adds conformable arrays
Throws: UnequalLengthArraysException
f is different size from this
 o subtract
  public RealArray subtract(RealArray f) throws UnequalLengthArraysException
array subtraction - subtracts conformable arrays
Throws: UnequalLengthArraysException
f is different size from this
 o negative
  public void negative()
change the sign of all elements; MODIFIES this
 o multiplyBy
  public RealArray multiplyBy(double f)
array multiplication by a scalar; does NOT modify 'this'
 o setElementAt
  public void setElementAt(int elem,
                           double f) throws ArrayIndexOutOfBoundsException
set a given element into the array; must be less than current max index
Throws: ArrayIndexOutOfBoundsException
elem >= size of this
 o getSubArray
  public RealArray getSubArray(int start,
                               int end)
RHS: get a subRealArray from element start to end
 o setElements
  public void setElements(int start,
                          double a[])
copy a smaller array into the array statrting at start
 o isClear
  public boolean isClear()
is the array filled with zeros?
 o setAllElements
  public void setAllElements(double f)
initialise array to given double[]
 o sumAllElements
  public double sumAllElements()
sum all elements
 o absSumAllElements
  public double absSumAllElements()
absolute sum of all elements
 o innerProduct
  public double innerProduct()
inner product - same as dotProduct
 o dotProduct
  public double dotProduct(RealArray f) throws UnequalLengthArraysException
dot product of two RealArrays - if of same length - else zero
Throws: UnequalLengthArraysException
f is different size from this
 o euclideanLength
  public double euclideanLength()
Euclidean length of vector
 o rms
  public double rms() throws ArrayTooSmallException
root mean square sqrt(sigma(x(i)**2)/n)
Throws: ArrayTooSmallException
must have at least 1 point
 o unitVector
  public RealArray unitVector() throws ZeroLengthVectorException
get unit vector
Throws: ZeroLengthVectorException
elements of this are all zero
 o cumulativeSum
  public RealArray cumulativeSum()
cumulative sum of array (new RA contains
elem[i] = sum(k = 0 to i) f[k]

does not modify 'this'

 o applyFilter
  public RealArray applyFilter(RealArray filter)
apply filter (i.e. convolute RA with another RA). This is 1-D image processing. If filter has <= 1 element, return this unchanged. filter should have an odd number of elements.

The filter can be created with a RealArray constructor

 o indexOfLargestElement
  public int indexOfLargestElement()
index of largest element; returns -1 if zero element array
 o indexOfSmallestElement
  public int indexOfSmallestElement()
index of smallest element
 o largestElement
  public double largestElement()
value of largest element
 o smallestElement
  public double smallestElement()
value of smallest element
 o range
  public RealRange range()
range of array (default RealRange for zero array)
 o deleteElement
  public void deleteElement(int elem)
delete element and close up; if outside range, take no action
 o deleteElements
  public void deleteElements(int low,
                             int high)
delete elements and close up; if outside range take no action
 o insertElementAt
  public void insertElementAt(int elem,
                              double f)
insert element and expand; if outside range, take no action
 o insertArray
  public void insertArray(int elem,
                          RealArray f)
insert a RealArray at position elem and expand
 o addElement
  public void addElement(double f)
append element
 o addArray
  public void addArray(RealArray f)
append elements
 o getReorderedArray
  public RealArray getReorderedArray(IntSet idx) throws BadSubscriptException
reorder by index in IntSet; does NOT modify array
Throws: BadSubscriptException
an element of idx is outside range of this
 o inRange
  public IntSet inRange(RealRange r)
return index of elements within a given range
 o outOfRange
  public IntSet outOfRange(RealRange r)
return index of elements outside a given range
 o getStringValues
  public String[] getStringValues()
returns values as strings
 o toString
  public String toString()
concatenates values with spaces
Overrides:
toString in class Object
 o deleteElements
  public static double[] deleteElements(double f[],
                                        int low,
                                        int hi)
delete elements (lo - > hi inclusive) in a float[] and close up; if hi >= float.length hi is reset to float.length-1.
 o copy
  public static double[] copy(double f[])
copy a double[] into a new one
 o sortAscending
  public void sortAscending()
MODIFIES array to be in ascending order
 o sortDescending
  public void sortDescending()
MODIFIES array to be in ascending order
 o reverse
  public void reverse()
MODIFIES array to be in reverse order
 o indexSortAscending
  public IntSet indexSortAscending()
 o indexSortDescending
  public IntSet indexSortDescending()
sort array into descending order via indexes; array NOT MODIFIED
 o test
  public static void test()
 o main
  public static void main(String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index