array/Array.java 100444 012056 000144 00000007045 06617376747 014457 0 ustar 00moreira usr 000000 000000 /** IBM SOFTWARE DISCLAIMER Java array package (draft 0.2). Copyright (1998), International Business Machines Corporation. Permission to use, copy, modify and distribute this software for any noncommercial purpose and without fee is hereby granted, provided that this copyright and permission notice appear on all copies of the software. The name of the IBM Corporation may not be used in any advertising or publicity pertaining to the use of the software. IBM makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. IBM shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software. */ package array; /** array = Java array package
The Java array package provides the basic functionality of Fortran 90 arrays in Java. Arrays are multidimensional, rectangular grids of elements. The array class hierarchy is as follows:
Array ----> <type>Array ----> <type>Array<rank>
where Array is an interface, <type>Array is an abstract class and <type>Array<rank> is a (concrete) class. Only objects of class <type>Array<rank> can be instantiated. The following <type>s are valid:
boolean, byte, short, int, long, char, float, double, FloatComplex, DoubleComplex, and Object.
The following <rank>s are valid:
0D (for 0-dimensional arrays), 1D (for 1-dimensional arrays), 2D, 3D, 4D, 5D, 6D, 7D.
Note: This distribution only contains the classes for <type>=double and <rank>=0D,1D,2D,3D.
The Array interface is implemented by all abstract array classes of the form <type>Array. It declares the basic methods that are common to all arrays, independent of <type> and <rank> */ public interface Array { /** Return the rank of the array. */ public int rank(); /** Return the number of elements in the array. */ public int size(); /** Return the extent of the array along its i-th axis. @param i array axis (0 <= i < rank()) @exception InvalidArrayAxisException i must be between 0 and rank-1 */ public int size(int i) throws InvalidArrayAxisException; /** Return the shape of the array as an int[] I of length rank(). I(i) = size(i) */ public int[] shape(); /** Return an Object which has the same value as the specified element of the array. @param index index[i] = index along i-th axis, 0 <= index[i] < size(i) @exception InvalidArrayIndexException index[] must be of length equal to rank */ public Object getAsObject(int[] index) throws InvalidArrayIndexException, ArrayIndexOutOfBoundsException; /** Sets the specified element of the array to a particular value. @param index index[i] = index along i-th axis, 0 <= index[i] < size(i) @param obj the array element is set to the value of this Object @exception InvalidArrayIndexException index[] must be of length equal to rank */ public void setToObject(int[] index, Object obj) throws InvalidArrayIndexException, ArrayIndexOutOfBoundsException, NullPointerException; } array/Blas.java 100644 012056 000144 00000012237 06617645745 014260 0 ustar 00moreira usr 000000 000000 /** IBM SOFTWARE DISCLAIMER Java array package (draft 0.2). Copyright (1998), International Business Machines Corporation. Permission to use, copy, modify and distribute this software for any noncommercial purpose and without fee is hereby granted, provided that this copyright and permission notice appear on all copies of the software. The name of the IBM Corporation may not be used in any advertising or publicity pertaining to the use of the software. IBM makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. IBM shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software. */ package array; /** Blas = Basic Linear Algebra Subprograms for the array package.
This class implements the BLAS functions for operations on arrays from the array package. It follows the spirit of the "Draft Proposal for Java BLAS Interface", by Roldan Pozo of the National Institute of Standards and Technology. Because the array package supports sections, the interface is actually simpler.
The purpose of this current implementation is to serve as an example
of interfaces. Therefore, only three operations are coded:
dgemm, dgemv, and ddot.
Please note that the operations are coded for clarity, not performance.
*/
public class Blas {
public static final boolean NoTranspose = false;
public static final boolean Transpose = true;
private static int min(int a, int b) {
return (a < b) ? a : b;
}
/**
BLAS dgemm routine: C = alpha*A*B + beta*C.
@param transa indicates if A is to be transposed
@param transb indicates if B is to be transposed
@param alpha multiplier for A*B
@param a matrix A
@param b matrix B
@param beta multiplier for C
@param c matrix C
@exception NonconformingArrayException shapes do not match
*/
public static void dgemm(boolean transa,
boolean transb,
double alpha,
doubleArray2D a,
doubleArray2D b,
double beta,
doubleArray2D c)
throws NonconformingArrayException {
try {
if (transa) a = a.permuteAxes(1,0);
if (transb) b = b.permuteAxes(1,0);
int m = a.size(0);
int n = a.size(1);
int p = b.size(1);
if (n != b.size(0)) throw new NonconformingArrayException();
if (p != c.size(1)) throw new NonconformingArrayException();
if (m != c.size(0)) throw new NonconformingArrayException();
doubleArray2D d = new doubleArray2D(m,p);
for (int i=0; i