/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a 2D real matrix from <code>byte[][]</code> * * Note: array is converted to Byte[] * * @param name - array name * @param vals - two-dimensional array of values */ public MLUInt8(String name, byte[][] vals) { this(name, byte2DToByte(vals), vals.length); }
/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a matrix from a one-dimensional packed array * * @param name - array name * @param vals - One-dimensional array of doubles, packed by columns (ala Fortran). * @param m - Number of rows */ public MLUInt8(String name, byte[] vals, int m) { this(name, castToByte(vals), m); }
public Byte buldFromBytes(byte[] bytes) { if (bytes.length != getBytesAllocated()) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated()); } return bytes[0]; }
/** * Gets two-dimensional real array. * * @return - 2D real array */ public byte[][] getArray() { final int M = getM(); final int N = getN(); byte[][] result = new byte[M][]; for ( int m = 0; m < M; m++ ) { result[m] = new byte[N]; for ( int n = 0; n < N; n++ ) { result[m][n] = getReal(m,n); } } return result; } /**
mlArray = new MLUInt8(name, dims, type, attributes); if (content.getRealByteBuffer() != null) { new ByteBufferInputStream(content.getRealByteBuffer(), content.getRealByteBuffer().limit()))) { Object o = ois.readObject(); mlArray = new MLJavaObject(arrName, className, o);
@Test public void testBenchmarkUInt8() throws Exception { final String fileName = "bigbyte.mat"; final String name = "bigbyte"; final int SIZE = 1024; MLUInt8 mluint8 = new MLUInt8(name, new int[]{SIZE, SIZE}); // write array to file ArrayList<MLArray> list = new ArrayList<MLArray>(); list.add(mluint8); // write arrays to file new MatFileWriter(getTempFile(fileName), list); // read array form file MatFileReader mfr = new MatFileReader(getTempFile(fileName)); MLArray mlArrayRetrived = mfr.getMLArray(name); for (int i = 0; i < mlArrayRetrived.getSize(); i++) { ((MLNumericArray<?>) mlArrayRetrived).get(i); } // test if MLArray objects are equal assertEquals("Test if value red from file equals value stored", mluint8, mlArrayRetrived); }
private static void parseMCOS(MLUInt8 mcosData, Set<MLObjectPlaceholder> mcosPlaceholders) throws IOException { ByteBuffer buffer = mcosData.getRealByteBuffer(); ByteBufferInputStream dataStream = new ByteBufferInputStream(buffer, buffer.limit()); Map<String, MLArray> mcosContent = matFile.getContent(); MLCell mcosInfo = (MLCell) ((MLStructure) mcosContent.get("@0")).getField("MCOS"); ByteBuffer mcosDataBuf = ((MLUInt8) mcosInfo.get(0)).getRealByteBuffer();
@Test public void testUInt8() throws Exception { String fileName = "uint8.mat"; String arrName = "arr"; MatFileReader mfr; MLArray src; // read array form file mfr = new MatFileReader(getTestFile(fileName)); assertEquals("Test min. value from file:" + fileName + " array: " + arrName, (byte) 0, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 0), 0.001); assertEquals("Test max. value from file:" + fileName + " array: " + arrName, (byte) 255, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 1), 0.001); src = mfr.getMLArray(arrName); // write fileName = "uint8out.mat"; ArrayList<MLArray> towrite = new ArrayList<MLArray>(); towrite.add(mfr.getMLArray(arrName)); new MatFileWriter(getTempFile(fileName), towrite); // read again mfr = new MatFileReader(getTempFile(fileName)); assertEquals("Test min. value from file:" + fileName + " array: " + arrName, (byte) 0, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 0), 0.001); assertEquals("Test max. value from file:" + fileName + " array: " + arrName, (byte) 255, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 1), 0.001); assertEquals("Test if array retrieved from " + fileName + " equals source array", src, mfr.getMLArray(arrName)); }
mlArray = new MLUInt8(name, dims, type, attributes); new ByteBufferInputStream( content.getRealByteBuffer(), content.getRealByteBuffer().limit() ) ); try
mlArray = new MLUInt8(name, dims, type, attributes);
private static void parseMCOS(MLUInt8 mcosData, Set<MLObjectPlaceholder> mcosPlaceholders) throws IOException { ByteBuffer buffer = mcosData.getRealByteBuffer(); ByteBufferInputStream dataStream = new ByteBufferInputStream(buffer, buffer.limit()); Map<String, MLArray> mcosContent = matFile.getContent(); MLCell mcosInfo = (MLCell) ((MLStructure) mcosContent.get("@0")).getField("MCOS"); ByteBuffer mcosDataBuf = ((MLUInt8) mcosInfo.get(0)).getRealByteBuffer();
mlArray = new MLUInt8(name, dims, type, attributes);
/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a 2D real matrix from <code>byte[][]</code> * * Note: array is converted to Byte[] * * @param name - array name * @param vals - two-dimensional array of values */ public MLUInt8(String name, byte[][] vals) { this(name, byte2DToByte(vals), vals.length); }
/** * <a href="http://math.nist.gov/javanumerics/jama/">Jama</a> [math.nist.gov] style: * construct a matrix from a one-dimensional packed array * * @param name - array name * @param vals - One-dimensional array of doubles, packed by columns (ala Fortran). * @param m - Number of rows */ public MLUInt8(String name, byte[] vals, int m) { this(name, castToByte( vals ), m ); } /* (non-Javadoc)
public Byte buldFromBytes(byte[] bytes) { if ( bytes.length != getBytesAllocated() ) { throw new IllegalArgumentException( "To build from byte array I need array of size: " + getBytesAllocated() ); } return bytes[0]; } public byte[] getByteArray(Byte value)