All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xxdb.data.BasicComplexMatrix Maven / Gradle / Ivy

There is a newer version: 3.00.2.2
Show newest version
package com.xxdb.data;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;

import com.xxdb.io.Double2;
import com.xxdb.io.ExtendedDataInput;
import com.xxdb.io.ExtendedDataOutput;

public class BasicComplexMatrix extends AbstractMatrix{
	private Double2[] values;
	
	public BasicComplexMatrix(int rows, int columns){
		super(rows, columns);
		values = new Double2[rows * columns];
	}
	
	public BasicComplexMatrix(int rows, int columns, List listOfArrays) throws Exception {
		super(rows,columns);
		values = new Double2[rows*columns];
		if (listOfArrays == null || listOfArrays.size() != columns)
			throw new Exception("input list of arrays does not have " + columns + " columns");
		for (int i=0; i getElementClass(){
		return BasicComplex.class;
	}

	@Override
	protected void readMatrixFromInputStream(int rows, int columns,	ExtendedDataInput in)  throws IOException{
		int size = rows * columns;
		values =new Double2[size];
		long totalBytes = (long)size * 16, off = 0;
		ByteOrder bo = in.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
		while (off < totalBytes) {
			int len = (int)Math.min(BUF_SIZE, totalBytes - off);
			in.readFully(buf, 0, len);
			int start = (int)(off / 16), end = len / 16;
			ByteBuffer byteBuffer = ByteBuffer.wrap(buf, 0, len).order(bo);
			for (int i = 0; i < end; i++)
				values[i + start] = new Double2(byteBuffer.getDouble(i * 16), byteBuffer.getDouble(i*16 + 8));
			off += len;
		}
	}

	protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException{
		for(Double2 value : values)
			out.writeDouble2(value);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy