/* SCCS @(#)NslFloat2.java 1.14 -- 09/20/99 -- 19:19:49 */ // Copyright: Copyright (c) 1997 University of Southern California Brain Project. // Copyright: This software may be freely copied provided the toplevel // Copyright: COPYRIGHT file is included with each such copy. // Copyright: Email nsl@java.usc.edu. //////////////////////////////////////////////////////////////////////////////// // NslFloat2.java package nslj.src.lang; public class NslFloat2 extends NslNumeric2 { // public float[][] _data; //public String _name; //boolean visibility = true; //NslHierarchy module; public NslFloat2(float[][] d) { super(); _data = new float[d.length][d[0].length]; set(d); //_name = null; } public NslFloat2(NslNumeric2 n) { super(); _data = new float[n.getSize1()][n.getSize2()]; set(n.getfloat2()); //_name = null; } public NslFloat2(int size1, int size2) { super(); _data = new float[size1][size2]; //_name = null; } public NslFloat2() { super(); _data=null; //_name = null; } /** * This constructs a number with specified name * @param name - name of the variable */ public NslFloat2(String name, NslHierarchy curParent) { super(name,curParent,curParent.nslGetAccess()); _data = null; //_name = name; //module = curParent; //visibility = module.getVisibility(); //module.enableAccess(this); } public NslFloat2(String name) { super(name); _data = null; //_name = name; } /** * This constructs a number with specified name * @param name - name of the variable * @param size1 - size of the array 1st-Dimension * @param size2 - size of the array 2nd-Dimension */ public NslFloat2(String name, int size1, int size2) { super(name); _data = new float[size1][size2]; //_name = name; } public NslFloat2(String name, NslHierarchy curParent, int size1, int size2) { super(name,curParent,curParent.nslGetAccess()); _data = new float[size1][size2]; //_name = name; //module = curParent; //visibility = module.getVisibility(); //module.enableAccess(this); } /** * This constructs a number with specified name * @param name - name of the variable * @param n - initialized values */ public NslFloat2(String name, NslHierarchy curParent,NslNumeric2 n) { super(name,curParent,curParent.nslGetAccess()); _data = new float[n.getSize1()][n.getSize2()]; set(n.getfloat2()); //_name = name; //module = curParent; //visibility = module.getVisibility(); //module.enableAccess(this); } public NslFloat2(String name, NslNumeric2 n) { super(name); _data = new float[n.getSize1()][n.getSize2()]; set(n.getfloat2()); //_name = name; } // aa public NslFloat2(String name, float[][] d) { super(name); _data = new float[d.length][d[0].length]; set(d); //_name = name; } // public void nslMemAlloc(int size1, int size2) { _data = new float[size1][size2]; } // ------------gets--------------------------------------- public float[][] get() { return _data; } public float[] get(int pos1) { return _data[pos1]; } public float get(int pos1, int pos2) { return _data[pos1][pos2]; } /** * @return - the value of this object in java numerical array type double[][]. Override this method in NslDouble2 with more efficient one. */ public double[][] getdouble2() { double[][] doubledata; int i; int j; int size1 = _data.length; int size2 = _data[0].length; doubledata = new double[size1][size2]; for (i=0; ifloat[][]. Override this method in NslFloat2 with more efficient one. */ public float[][] getfloat2(){ return _data; } /** * @return - the value of this object in java numerical array type int[][]. Override this method in NslInt2 with more efficient one. */ public int[][] getint2() { int[][] intdata; int i; int j; int size1 = _data.length; int size2 = _data[0].length; intdata = new int[size1][size2]; for (i=0; iposth row of this object in java numerical array type double[]. */ public double[] getdouble1(int pos) { int i; int size2 = _data[0].length; double[] tmp = new double[size2]; for (i=0; iposth row of this object in java numerical array type int[]. */ public int[] getint1(int pos) { int i; int size2 = _data[0].length; int tmp[] = new int[size2]; for (i=0; ipos1th row and pos2th column in java numerical type double. */ public double getdouble(int pos1, int pos2) { return (double)_data[pos1][pos2]; } /** * @param pos1 - row number * @param pos2 - column number * @return the value of the element in pos1th row and pos2th column in java numerical type float. */ public float getfloat(int pos1, int pos2) { return _data[pos1][pos2]; } /** * @param pos1 - row number * @param pos2 - column number * @return the value of the element in pos1th row and pos2th column in java numerical type int. */ public int getint(int pos1, int pos2) { return (int)_data[pos1][pos2]; } // Interface with NslNumeric type /** * get the value of this object in NslDouble2 form. */ // Override this method in NslDouble2 with more efficient one. public NslDouble2 getNslDouble2() { return (new NslDouble2(getdouble2())); } // Override this method in NslFloat2 with more efficient one. public NslFloat2 getNslFloat2() { return this; } // Override this method in NslFloat2 with more efficient one. public NslInt2 getNslInt2() { return (new NslInt2(getint2())); } public float[][] getSector(int start1, int start2, int end1, int end2) { int i1; int i2; int j1; int j2; int length1; int length2; float[][] floatdata; if (start1 < 0) start1 = 0; if (start2 < 0) start2 = 0; if (end1 > _data.length) end1 = _data.length; if (end2 > _data[0].length) end2 = _data[0].length; length1 = end1-start1+1; length2 = end2-start2+1; floatdata = new float[length1][length2]; i1 = start1; i2 = start2; for (j1=0; j1 _data.length) return; if (startpos2 > _data[0].length) return; if (endpos1 > _data.length) endpos1 = _data.length; if (endpos2 > _data[0].length) endpos2 = _data[0].length; for (i1=startpos1, j1=0; i1value) { pos1 = i; pos2 = j; value = _data[i][j]; } } } max_elem_pos1.set(pos1); max_elem_pos2.set(pos2); return value; } public float maxValue() { return maxElem(new NslInt0(0), new NslInt0(0)); } public float minElem(NslInt0 max_elem_pos1, NslInt0 max_elem_pos2) { float value = java.lang.Float.POSITIVE_INFINITY; int i, j; int size1 = _data.length; int size2 = _data[0].length; int pos1 = -1; int pos2 = -1; for (i=0; i