jml.operation
Class ArrayOperation

java.lang.Object
  extended by jml.operation.ArrayOperation

public class ArrayOperation
extends java.lang.Object

The ArrayOperation includes frequently used operation functions on double arrays. The argument vector is required to have been allocated memory before being used in the array operations.

Version:
1.0, Feb. 21st, 2013
Author:
Mingjie Qian

Constructor Summary
ArrayOperation()
           
 
Method Summary
static int[] allocateIntegerVector(int n)
          Allocate continuous memory block for a 1D int array.
static double[][] allocateMatrix(int nRows, int nCols)
          Allocate memory for a 2D double array.
static double[] allocateVector(int n)
          Allocate continuous memory block for a 1D double array.
static double[] allocateVector(int n, double v)
          Allocate continuous memory block for a 1D double array and assign all elements with a given value.
static int argmax(double[] V)
          Compute the maximum argument.
static void assignIntegerVector(int[] V, int v)
          Assign a 1D int array by a real scalar.
static void assignVector(double[] V, double v)
          Assign a 1D double array by a real scalar.
static void assignVector(double[] V1, double[] V2)
          Element-wise assignment operation.
static void clearMatrix(double[][] M)
          Clear all elements of a 2D double array to zero.
static void clearVector(double[] V)
          Clear all elements of a 1D double array to zero.
static void divideAssign(double[] V, double v)
          Element-wise division and assignment operation.
static void divideAssign(double[] V1, double[] V2)
          Element-wise division and assignment operation.
static void minusAssign(double[] V, double v)
          Element-wise subtraction and assignment operation.
static void minusAssign(double[] V1, double[] V2)
          Element-wise subtraction and assignment operation.
static void minusAssign(int[] V, int v)
          Element-wise subtraction and assignment operation.
static void operate(double[] V1, double[][] A, double[] V2)
          V1 = A * V2.
static void operate(double[] V1, double[] V2, double[][] A)
          V1' = V2' * A.
static void operate(double[] V1, double[] V2, org.apache.commons.math.linear.RealMatrix A)
          V1' = V2' * A.
static void operate(double[] V1, org.apache.commons.math.linear.RealMatrix A, double[] V2)
          V1 = A * V2.
static void plusAssign(double[] V, double v)
          Element-wise addition and assignment operation.
static void plusAssign(double[] V1, double[] V2)
          Element-wise addition and assignment operation.
static double sum(double[] V)
          Compute the sum of a 1D double array.
static void sum2one(double[] V)
          Sum a 1D double array to one, i.e., V[i] = V[i] / sum(V).
static void timesAssign(double[] V, double v)
          Element-wise multiplication and assignment operation.
static void timesAssign(double[] V1, double[] V2)
          Element-wise multiplication and assignment operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayOperation

public ArrayOperation()
Method Detail

argmax

public static int argmax(double[] V)
Compute the maximum argument.

Parameters:
V - a double array
Returns:
maximum argument

assignVector

public static void assignVector(double[] V,
                                double v)
Assign a 1D double array by a real scalar.

Parameters:
V - a 1D double array
v - a real scalar

assignIntegerVector

public static void assignIntegerVector(int[] V,
                                       int v)
Assign a 1D int array by a real scalar.

Parameters:
V - a 1D int array
v - a real scalar

clearVector

public static void clearVector(double[] V)
Clear all elements of a 1D double array to zero.

Parameters:
V - a double array

clearMatrix

public static void clearMatrix(double[][] M)
Clear all elements of a 2D double array to zero.

Parameters:
M - a 2D double array

allocateVector

public static double[] allocateVector(int n)
Allocate continuous memory block for a 1D double array.

Parameters:
n - number of elements to be allocated
Returns:
a 1D double array of length n

allocateVector

public static double[] allocateVector(int n,
                                      double v)
Allocate continuous memory block for a 1D double array and assign all elements with a given value.

Parameters:
n - number of elements to be allocated
v - a real scalar to assign the 1D double array
Returns:
a 1D double array of length n

allocateIntegerVector

public static int[] allocateIntegerVector(int n)
Allocate continuous memory block for a 1D int array.

Parameters:
n - number of elements to be allocated
Returns:
a 1D int array of length n

allocateMatrix

public static double[][] allocateMatrix(int nRows,
                                        int nCols)
Allocate memory for a 2D double array.

Parameters:
nRows - number of rows
nCols - number of columns
Returns:
a nRows by nCols 2D double array

divideAssign

public static void divideAssign(double[] V,
                                double v)
Element-wise division and assignment operation. It divides the first argument with the second argument and assign the result to the first argument, i.e., V = V / v.

Parameters:
V - a 1D double array
v - a real scalar

divideAssign

public static void divideAssign(double[] V1,
                                double[] V2)
Element-wise division and assignment operation. It divides the first argument with the second argument and assign the result to the first argument, i.e., V1 = V1 ./ V2.

Parameters:
V1 - a 1D double array
V2 - a 1D double array

timesAssign

public static void timesAssign(double[] V,
                               double v)
Element-wise multiplication and assignment operation. It multiplies the first argument with the second argument and assign the result to the first argument, i.e., V = V * v.

Parameters:
V - a 1D double array
v - a real scalar

timesAssign

public static void timesAssign(double[] V1,
                               double[] V2)
Element-wise multiplication and assignment operation. It multiplies the first argument with the second argument and assign the result to the first argument, i.e., V1 = V1 .* V2.

Parameters:
V1 - a 1D double array
V2 - a 1D double array

sum

public static double sum(double[] V)
Compute the sum of a 1D double array.

Parameters:
V - a 1D double array
Returns:
sum(V)

sum2one

public static void sum2one(double[] V)
Sum a 1D double array to one, i.e., V[i] = V[i] / sum(V).

Parameters:
V - a 1D double array

plusAssign

public static void plusAssign(double[] V,
                              double v)
Element-wise addition and assignment operation. It adds the first argument by the second argument and assign the result to the first argument, i.e., V = V + v.

Parameters:
V - a 1D double array
v - a real scalar

plusAssign

public static void plusAssign(double[] V1,
                              double[] V2)
Element-wise addition and assignment operation. It adds the first argument by the second argument and assign the result to the first argument, i.e., V1 = V1 + V2.

Parameters:
V1 - a 1D double array
V2 - a 1D double array

minusAssign

public static void minusAssign(int[] V,
                               int v)
Element-wise subtraction and assignment operation. It subtracts the first argument by the second argument and assign the result to the first argument, i.e., V = V - v.

Parameters:
V - a 1D int array
v - an integer

minusAssign

public static void minusAssign(double[] V,
                               double v)
Element-wise subtraction and assignment operation. It subtracts the first argument by the second argument and assign the result to the first argument, i.e., V = V - v.

Parameters:
V - a 1D double array
v - a real scalar

minusAssign

public static void minusAssign(double[] V1,
                               double[] V2)
Element-wise subtraction and assignment operation. It subtracts the first argument by the second argument and assign the result to the first argument, i.e., V1 = V1 - V2.

Parameters:
V1 - a 1D double array
V2 - a 1D double array

assignVector

public static void assignVector(double[] V1,
                                double[] V2)
Element-wise assignment operation. It assigns the first argument with the second argument, i.e., V1 = V2.

Parameters:
V1 - a 1D double array
V2 - a 1D double array

operate

public static void operate(double[] V1,
                           double[][] A,
                           double[] V2)
V1 = A * V2.

Parameters:
V1 - a 1D double array
A - a 2D double array
V2 - a 1D double array

operate

public static void operate(double[] V1,
                           org.apache.commons.math.linear.RealMatrix A,
                           double[] V2)
V1 = A * V2.

Parameters:
V1 - a 1D double array
A - a real matrix
V2 - a 1D double array

operate

public static void operate(double[] V1,
                           double[] V2,
                           double[][] A)
V1' = V2' * A.

Parameters:
V1 - a 1D double array
V2 - a 1D double array
A - a 2D double array

operate

public static void operate(double[] V1,
                           double[] V2,
                           org.apache.commons.math.linear.RealMatrix A)
V1' = V2' * A.

Parameters:
V1 - a 1D double array
V2 - a 1D double array
A - a 2D double array