il2.util
Class ArrayUtils

Object
  extended by ArrayUtils

public class ArrayUtils
extends Object

Static utility methods acting on arrays of primitive types.

Author:
James Park, Mark Chavira, Keith Cascio

Constructor Summary
ArrayUtils()
           
 
Method Summary
static int count(boolean[] vals, boolean val)
          Returns the number of occurrences of the given value in the given array.
static int[] cumProd(int[] vals)
          Returns the cumulative product of the given array.
static long[] cumProd(long[] vals)
           
static long[] cumProdAsLong(int[] vals)
           
static BigInteger cumProdLastBigInteger(int[] vals)
           
static long cumProdLastLong(int[] vals)
           
static double intervalSum(double[] vals, int start, int bound)
          Returns the sum of the given consecutive range of values in the given array.
static double max(double[] vals)
          Returns the maximum of the values in the given array.
static int max(int[] vals)
          Returns the maximum of the values in the given array.
static int maxInd(double[] vals)
          Returns the index of the maximum value in the given array.
static int maxInd(int[] vals)
          Returns the index of the maximum value in the given array.
static double min(double[] vals)
          Returns the minimum of the values in the given array.
static int min(int[] vals)
          Returns the minimum of the values in the given array.
static int minInd(double[] vals)
          Returns the index of the minimum value in the given array.
static int minInd(int[] vals)
          Returns the index of the minimum value in the given array.
static int[] reversed(int[] vals)
          Returns an array that contains the same values as the given array but reversed.
static double[] select(double[] vals, int[] inds)
          Returns an array that contains selected values from the given array.
static int[] select(int[] vals, int[] inds)
          Returns an array that contains selected values from the given array.
static long[] select(long[] vals, int[] inds)
           
static double[] selectWithOffset(double[] vals, int[] inds, int offset)
          Returns an array that contains selected values from the given array.
static void selectWithOffset(double[] vals, int[] inds, int offset, double[] dest)
          Fills an array with selected values from the given array.
static int[] sequence(int len)
          Returns an array of ints [0, 1, 2, ..., L - 1], where L is the given length.
static int[] sortedInds(double[] vals)
          Returns an array of indices of the the values in the given array sorted according to the values they index.
static int[] sortedInds(int[] vals)
          Returns an array of indices of the the values in the given array sorted according to the values they index.
static double sum(double[] vals)
          Returns the sum of the values in the given array.
static double[] toDoubles(int[] vals)
          Returns an array of doubles containing the same values as the given array of ints.
static int[] toInts(double[] vals)
          Returns an array of ints containing the same values as the given array of doubles after the double values are rounded.
static String toString(double[] vals)
          Returns a string representation of the given array.
static String toString(int[] vals)
          Returns a string representation of the given array.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

cumProd

public static int[] cumProd(int[] vals)
Returns the cumulative product of the given array. The cumulative product of array a is an array ans such that:

Parameters:
vals - the given array.
Returns:
the cumulative product.

cumProdAsLong

public static long[] cumProdAsLong(int[] vals)
Since:
020705

cumProd

public static long[] cumProd(long[] vals)
Since:
020305

cumProdLastLong

public static long cumProdLastLong(int[] vals)
Since:
020305

cumProdLastBigInteger

public static BigInteger cumProdLastBigInteger(int[] vals)
Since:
020305

select

public static int[] select(int[] vals,
                           int[] inds)
Returns an array that contains selected values from the given array.

Parameters:
vals - the given array.
inds - the indices of the values to select.
Returns:
an array ans of length inds.length where ans[i] = vals[inds[i]]

select

public static double[] select(double[] vals,
                              int[] inds)
Returns an array that contains selected values from the given array.

Parameters:
vals - the given array.
inds - the indices of the values to select.
Returns:
an array ans of length inds.length where ans[i] = vals[inds[i]]

select

public static long[] select(long[] vals,
                            int[] inds)
Since:
020305

selectWithOffset

public static void selectWithOffset(double[] vals,
                                    int[] inds,
                                    int offset,
                                    double[] dest)
Fills an array with selected values from the given array.

Parameters:
vals - the given array.
inds - the indices, which together with offset, define the values to select.
offset - the value, which together with indices, defines the values to select.

selectWithOffset

public static double[] selectWithOffset(double[] vals,
                                        int[] inds,
                                        int offset)
Returns an array that contains selected values from the given array.

Parameters:
vals - the given array.
inds - the indices, which together with offset, define the values to select.
offset - the value, which together with indices, defines the values to select.
Returns:
an array ans of length inds.length where ans[i] = vals[offset + inds[i]]

toString

public static String toString(int[] vals)
Returns a string representation of the given array.

Parameters:
vals - the given array.
Returns:
the string representation.

toString

public static String toString(double[] vals)
Returns a string representation of the given array.

Parameters:
vals - the given array.
Returns:
the string representation.

count

public static int count(boolean[] vals,
                        boolean val)
Returns the number of occurrences of the given value in the given array.

Parameters:
vals - the given array.
val - the given value.
Returns:
the number of occurrences.

sum

public static double sum(double[] vals)
Returns the sum of the values in the given array.

Parameters:
vals - the given array.
Returns:
the sum.

intervalSum

public static double intervalSum(double[] vals,
                                 int start,
                                 int bound)
Returns the sum of the given consecutive range of values in the given array. The range is [start, bound).

Parameters:
vals - the given array.
start - the first element to sum (inclusive).
bound - the last element to sum (exclusive).
Returns:
the sum.

min

public static int min(int[] vals)
Returns the minimum of the values in the given array. If the array is empty, returns Integer.MAX_VALUE.

Parameters:
vals - the given array.
Returns:
the minimum.

max

public static int max(int[] vals)
Returns the maximum of the values in the given array. If the array is empty, returns Integer.MIN_VALUE.

Parameters:
vals - the given array.
Returns:
the maximum.

minInd

public static int minInd(int[] vals)
Returns the index of the minimum value in the given array. If the array is empty, returns -1.

Parameters:
vals - the given array.
Returns:
the index or -1.

maxInd

public static int maxInd(int[] vals)
Returns the index of the maximum value in the given array. If the array is empty, returns -1.

Parameters:
vals - the given array.
Returns:
the index or -1.

min

public static double min(double[] vals)
Returns the minimum of the values in the given array. If the array is empty, returns Double.POSITIVE_INFINITY.

Parameters:
vals - the given array.
Returns:
the maximum.

max

public static double max(double[] vals)
Returns the maximum of the values in the given array. If the array is empty, returns Double.NEGATIVE_INFINITY.

Parameters:
vals - the given array.
Returns:
the maximum.

minInd

public static int minInd(double[] vals)
Returns the index of the minimum value in the given array. If the array is empty, returns -1.

Parameters:
vals - the given array.
Returns:
the index or -1.

maxInd

public static int maxInd(double[] vals)
Returns the index of the maximum value in the given array. If the array is empty, returns -1.

Parameters:
vals - the given array.
Returns:
the index or -1.

toDoubles

public static double[] toDoubles(int[] vals)
Returns an array of doubles containing the same values as the given array of ints.

Parameters:
vals - the given array of ints.
Returns:
the array of doubles.

toInts

public static int[] toInts(double[] vals)
Returns an array of ints containing the same values as the given array of doubles after the double values are rounded.

Parameters:
vals - the given array of doubles.
Returns:
the array of ints.

sortedInds

public static int[] sortedInds(double[] vals)
Returns an array of indices of the the values in the given array sorted according to the values they index.

Parameters:
vals - the given array.
Returns:
the indices.

sortedInds

public static int[] sortedInds(int[] vals)
Returns an array of indices of the the values in the given array sorted according to the values they index.

Parameters:
vals - the given array.
Returns:
the indices.

reversed

public static int[] reversed(int[] vals)
Returns an array that contains the same values as the given array but reversed.

Parameters:
vals - the given array.
Returns:
the reversed array.

sequence

public static int[] sequence(int len)
Returns an array of ints [0, 1, 2, ..., L - 1], where L is the given length.

Parameters:
len - the given length.
Returns:
the array.


Copyright 2010 UCLA Automated Reasoning Group