jfig.utils
Class Array

java.lang.Object
  extended byjfig.utils.Array

public class Array
extends java.lang.Object

utility functions for double[] arrays, Matlab-style:


Constructor Summary
Array()
          dummy constructor; you can use this to create an Array instance that allows you to access the static methods of this class from Matlab 5.3 (which requires a very ugly syntax to use static methods).
 
Method Summary
static double[] abs(double[] arg)
           
static double[] add(double[] arg, double value)
           
static double[] add(double[] arg, double[] arg2)
           
static double[] add(double[] x1, double[] x2, double[] x3)
           
static double[] add(double[] x1, double[] x2, double[] x3, double[] x4)
           
static int any(double[] x)
          return 0 if all elements of x[] are zero, otherwise return 1
static double[] array(double x0)
          create an array [x0]
static double[] array(double x0, double x1)
          create an array [x0,x1]
static double[] array(double x0, double x1, double x2)
           
static double[] array(double x0, double x1, double x2, double x3)
           
static double[] array(double x0, double x1, double x2, double x3, double x4)
           
static double[] array(java.lang.String s)
          read a whitespace, comma, semicolon separated string and create a double array with values corresponding to the tokens in that string.
static double[] autoRangeClipped(double[] arg)
          return a range of 'clipped'/'rounded' values suitable that bound the minimum and maximum values of the input array.
static double[] ceil(double[] x)
           
static double[] clone(double[] arg)
           
static double[] concat(double[] u, double[] v)
           
static double[] concat(double[] u, double[] v, double[] w)
           
static double[] concat(double[] u, double[] v, double[] w, double[] x)
           
static double[] constant(double value, int N)
           
static double[] constant(int N, double value)
           
static double[] convolve(double[] target, double[] kernel)
           
static double[] cos(double[] arg)
           
static double[] div(double[] arg, double value)
           
static double[] div(double[] arg, double[] arg2)
           
static double[] equals(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] == y[i], but result[i] = 0.0 otherwise.
static double[] exp(double[] arg)
           
static double[][] eye(int M, int N)
          create an identity matrix (M rows, N columns), i.e.
static void fft_core(int sign, int n, double[] ar, double[] ai, double scale)
          calculate in-place FFT for input arrays ar and ai of length 2**n.
static double[][] fft(double[] ar, double[] ai)
          calculate the FFT of arrays ar and ai (real and imaginary parts of the input values).
static double[] filter(double[] B, double[] A, double[] X)
          one-dimensional digital filter.
static double[] floor(double[] x)
           
static int getIndexOfMaxValue(double[] arg)
           
static int getIndexOfMinValue(double[] arg)
           
static double getMax(double[] arg)
           
static double getMin(double[] arg)
           
static double[] getMinMax(double[] arg)
           
static double[] greaterEquals(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] >= y[i], but result[i] = 0.0 otherwise.
static double[] greaterThan(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] > y[i], but result[i] = 0.0 otherwise.
static double[] hamming(int N)
           
static double[] hanning(int N)
           
static boolean hasNaN(double[] x)
           
static void help()
           
static double[][] ifft(double[] ar, double[] ai)
           
static int[] indexArray(double[] x)
          create a new array containing the indices of all non-zero elements of x[].
static double[] insert(double[] x, double[] y, int start)
          insert the elements of y into x, starting at index 'start' For example, for x=[0 1 2 3 4 5 6 7 8 9] and y=[4 3 2], the call insert( x, y, 2 ) yields x = [ 0 1 4 3 2 5 6 7 8 9 ]
static double[] lessEquals(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] <= y[i], but result[i] = 0.0 otherwise.
static double[] lessThan(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] < y[i], but result[i] = 0.0 otherwise.
static double[] linspace(double min, double max, int N)
           
static double[] log(double[] arg)
           
static double log10(double arg)
           
static double[] log10(double[] arg)
           
static double log2(double arg)
           
static double[] log2(double[] arg)
           
static double[] logspace(double exp1, double exp2, int N)
           
static void main(java.lang.String[] argv)
           
static double[] max(double[] arg, double[] arg2)
           
static double[] min(double[] arg, double[] arg2)
           
static double[] mult(double[] arg, double value)
           
static double[] mult(double[] arg, double[] arg2)
           
static double[] neq(double[] x, double[] y)
          create a new array where result[i] = 1.0 if x[i] != y[i], but result[i] = 0.0 if x[i] == y[i]
static double[] normalize(double[] s)
           
static double[] ones(int N)
          create an array of N ones
static double[][] ones(int M, int N)
          create a matrix (M rows, N columns) initialized with all ones
static double[] parse(java.lang.String s)
          parse the given string and construct an array from it.
static java.lang.String print(double[] arg)
           
static double[] random(int N)
          generate an array of N random values, each in the range [0.0 ..
static double[][] random(int M, int N)
          create a matrix (M rows, N columns) initialized with uniformly distributed random values in the range [0..1)
static double[] range(int start, int end)
          create a double array with all integers in the given range, using Matlab conventions: both start and end values are included.
static double[] reciprocal(double[] arg)
           
static double[] resample(double[] arg, int new_length)
          resample (i.e.
static double[] reverse(double[] arg)
           
static double[] round(double[] x)
           
static double scalarproduct(double[] arg1, double[] arg2)
           
static double[] sin(double[] arg)
           
static double[] sqrt(double[] arg)
           
static double[] sub(double[] arg, double value)
           
static double[] sub(double[] arg, double[] arg2)
           
static double[] subset(double[] arg, int start)
           
static double[] subset(double[] arg, int start, int end)
          return the specified subset of the argument array.
static double[] subset(double[] arg, int start, int end, int step)
          return the specified subset of the argument array, starting at the given 'start' index and stepping by 'step' to 'end'.
static double sum(double[] x)
           
static double[] tan(double[] arg)
           
static double[] toDouble(float[] x)
           
static double[] toDouble(int[] x)
           
static double[][] toDouble(int[][] x)
           
static float[] toFloat(double[] x)
           
static int[] toInteger(double[] x)
          round the values in array x to the nearest integer; too-large values are clipped to Integer.MAX_VALUE and MIN_VALUE respectively.
static int[][] toInteger(double[][] x)
           
static double[] toMask(double[] x)
          create a new array where each non-zero value in x is replaced by a value of 1.0, while zeroes are kept.
static java.lang.String toString(double[] arg)
           
static java.lang.String toString(double[] arg, Format format)
           
static double[] zeros(int N)
          create an array of N zeroes
static double[][] zeros(int M, int N)
          create a matrix (M rows, N columns) initialized with all zeros
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Array

public Array()
dummy constructor; you can use this to create an Array instance that allows you to access the static methods of this class from Matlab 5.3 (which requires a very ugly syntax to use static methods).

Method Detail

help

public static void help()

constant

public static double[] constant(int N,
                                double value)

constant

public static double[] constant(double value,
                                int N)

zeros

public static double[] zeros(int N)
create an array of N zeroes


zeros

public static double[][] zeros(int M,
                               int N)
create a matrix (M rows, N columns) initialized with all zeros


ones

public static double[] ones(int N)
create an array of N ones


ones

public static double[][] ones(int M,
                              int N)
create a matrix (M rows, N columns) initialized with all ones


eye

public static double[][] eye(int M,
                             int N)
create an identity matrix (M rows, N columns), i.e. zero values everywhere except for 1's on the main diagonal.


array

public static double[] array(double x0)
create an array [x0]


array

public static double[] array(double x0,
                             double x1)
create an array [x0,x1]


array

public static double[] array(double x0,
                             double x1,
                             double x2)

array

public static double[] array(double x0,
                             double x1,
                             double x2,
                             double x3)

array

public static double[] array(double x0,
                             double x1,
                             double x2,
                             double x3,
                             double x4)

array

public static double[] array(java.lang.String s)
read a whitespace, comma, semicolon separated string and create a double array with values corresponding to the tokens in that string.


parse

public static double[] parse(java.lang.String s)
parse the given string and construct an array from it. See array(String).


reverse

public static double[] reverse(double[] arg)

random

public static double[] random(int N)
generate an array of N random values, each in the range [0.0 .. 1.0]


random

public static double[][] random(int M,
                                int N)
create a matrix (M rows, N columns) initialized with uniformly distributed random values in the range [0..1)


toDouble

public static double[] toDouble(int[] x)

toDouble

public static double[][] toDouble(int[][] x)

toDouble

public static double[] toDouble(float[] x)

toFloat

public static float[] toFloat(double[] x)

toInteger

public static int[] toInteger(double[] x)
round the values in array x to the nearest integer; too-large values are clipped to Integer.MAX_VALUE and MIN_VALUE respectively.


toInteger

public static int[][] toInteger(double[][] x)

ceil

public static double[] ceil(double[] x)

floor

public static double[] floor(double[] x)

round

public static double[] round(double[] x)

linspace

public static double[] linspace(double min,
                                double max,
                                int N)

logspace

public static double[] logspace(double exp1,
                                double exp2,
                                int N)

range

public static double[] range(int start,
                             int end)
create a double array with all integers in the given range, using Matlab conventions: both start and end values are included. This differs from Python/Jython, where the end value is excluded.


resample

public static double[] resample(double[] arg,
                                int new_length)
resample (i.e. stretch) the given input vector to the new length. This currently uses simple nearest-neighbor sampling and should rather use better techniques (e.g. bilinear or fft-based).


clone

public static double[] clone(double[] arg)

getMin

public static double getMin(double[] arg)

getMax

public static double getMax(double[] arg)

getMinMax

public static double[] getMinMax(double[] arg)

getIndexOfMinValue

public static int getIndexOfMinValue(double[] arg)

getIndexOfMaxValue

public static int getIndexOfMaxValue(double[] arg)

autoRangeClipped

public static double[] autoRangeClipped(double[] arg)
return a range of 'clipped'/'rounded' values suitable that bound the minimum and maximum values of the input array. The typical use is to calculate pleasing bounds when plotting the values; Examples: input bounds: output array: [-1.3, 72.5] [-20, 0, 20, 40, 60, 80] [ 0.0, 3.14] [0.0, 1.0, 2.0, 3.0, 4.0] [-15001, -11001] [-16000, -14000, -12000, -10000]


add

public static double[] add(double[] arg,
                           double[] arg2)

add

public static double[] add(double[] arg,
                           double value)

add

public static double[] add(double[] x1,
                           double[] x2,
                           double[] x3)

add

public static double[] add(double[] x1,
                           double[] x2,
                           double[] x3,
                           double[] x4)

mult

public static double[] mult(double[] arg,
                            double[] arg2)

mult

public static double[] mult(double[] arg,
                            double value)

div

public static double[] div(double[] arg,
                           double[] arg2)

div

public static double[] div(double[] arg,
                           double value)

reciprocal

public static double[] reciprocal(double[] arg)

sub

public static double[] sub(double[] arg,
                           double[] arg2)

sub

public static double[] sub(double[] arg,
                           double value)

min

public static double[] min(double[] arg,
                           double[] arg2)

max

public static double[] max(double[] arg,
                           double[] arg2)

sin

public static double[] sin(double[] arg)

cos

public static double[] cos(double[] arg)

exp

public static double[] exp(double[] arg)

log

public static double[] log(double[] arg)

log2

public static double log2(double arg)

log2

public static double[] log2(double[] arg)

log10

public static double log10(double arg)

log10

public static double[] log10(double[] arg)

abs

public static double[] abs(double[] arg)

sqrt

public static double[] sqrt(double[] arg)

tan

public static double[] tan(double[] arg)

concat

public static double[] concat(double[] u,
                              double[] v)

concat

public static double[] concat(double[] u,
                              double[] v,
                              double[] w)

concat

public static double[] concat(double[] u,
                              double[] v,
                              double[] w,
                              double[] x)

insert

public static double[] insert(double[] x,
                              double[] y,
                              int start)
insert the elements of y into x, starting at index 'start' For example, for x=[0 1 2 3 4 5 6 7 8 9] and y=[4 3 2], the call insert( x, y, 2 ) yields x = [ 0 1 4 3 2 5 6 7 8 9 ]


subset

public static double[] subset(double[] arg,
                              int start,
                              int end)
return the specified subset of the argument array. Note that the 'end' element is included the result array. Therefore, the indexing of the result array runs from 0 to (end-start).


subset

public static double[] subset(double[] arg,
                              int start)

subset

public static double[] subset(double[] arg,
                              int start,
                              int end,
                              int step)
return the specified subset of the argument array, starting at the given 'start' index and stepping by 'step' to 'end'. Note that the 'end' element is included the result array. For example, subset( x, x.length-1, 0, -1 ) reverses the array.


indexArray

public static int[] indexArray(double[] x)
create a new array containing the indices of all non-zero elements of x[]. For example, for x=[ 0 1 0 0 -3 -5 0 0 7 ], this function returns result = [ 1 4 5 8 ]


scalarproduct

public static double scalarproduct(double[] arg1,
                                   double[] arg2)

toString

public static java.lang.String toString(double[] arg)

toString

public static java.lang.String toString(double[] arg,
                                        Format format)

print

public static java.lang.String print(double[] arg)

normalize

public static double[] normalize(double[] s)

hamming

public static double[] hamming(int N)

hanning

public static double[] hanning(int N)

sum

public static double sum(double[] x)

toMask

public static double[] toMask(double[] x)
create a new array where each non-zero value in x is replaced by a value of 1.0, while zeroes are kept.


equals

public static double[] equals(double[] x,
                              double[] y)
create a new array where result[i] = 1.0 if x[i] == y[i], but result[i] = 0.0 otherwise.


neq

public static double[] neq(double[] x,
                           double[] y)
create a new array where result[i] = 1.0 if x[i] != y[i], but result[i] = 0.0 if x[i] == y[i]


greaterThan

public static double[] greaterThan(double[] x,
                                   double[] y)
create a new array where result[i] = 1.0 if x[i] > y[i], but result[i] = 0.0 otherwise.


greaterEquals

public static double[] greaterEquals(double[] x,
                                     double[] y)
create a new array where result[i] = 1.0 if x[i] >= y[i], but result[i] = 0.0 otherwise.


lessThan

public static double[] lessThan(double[] x,
                                double[] y)
create a new array where result[i] = 1.0 if x[i] < y[i], but result[i] = 0.0 otherwise.


lessEquals

public static double[] lessEquals(double[] x,
                                  double[] y)
create a new array where result[i] = 1.0 if x[i] <= y[i], but result[i] = 0.0 otherwise.


any

public static int any(double[] x)
return 0 if all elements of x[] are zero, otherwise return 1


hasNaN

public static boolean hasNaN(double[] x)

convolve

public static double[] convolve(double[] target,
                                double[] kernel)

filter

public static double[] filter(double[] B,
                              double[] A,
                              double[] X)
one-dimensional digital filter. Y = filter( B, A, X ) filters the data in vector X with the filter described by vectors A and B to create the filtered data Y. The filter is the "Direct From II Transposed" implementation of the standard difference equation: a(0)*y(n-1) = b(0)*x(n-1) + b(1)*x(n-2) + ... + b(nb)*x(n-nb-1) - a(1)*y(n-1) - ... - a(na)*y(n-na-1) If a(0) is not equal to 1, filter normalizes the filter coefficients by a(0).


fft

public static double[][] fft(double[] ar,
                             double[] ai)
calculate the FFT of arrays ar and ai (real and imaginary parts of the input values). Returns two vectors; the real and imaginary parts of the transform. Matlab-compatible scaling (1.0 for FFT, 1/N for IFFT), i.e. Matlab: four = fft( real(data), imag(data)) Java: fft[0] = real(fft(data)) fft[1] = imag(fft(data))


ifft

public static double[][] ifft(double[] ar,
                              double[] ai)

fft_core

public static void fft_core(int sign,
                            int n,
                            double[] ar,
                            double[] ai,
                            double scale)
calculate in-place FFT for input arrays ar and ai of length 2**n. sign=-1: FFT sign=+1: iFFT


main

public static void main(java.lang.String[] argv)