Skip to main content

REXS V1.6

Javascript examples

Decoding of binary arrays

function decodeIntegerArray(b64){
	var blob = atob( b64 );
	var ary_buf = new ArrayBuffer( blob.length );
	var dv = new DataView( ary_buf );
	for( var i=0; i < blob.length; i++ ) dv.setUint8( i, blob.charCodeAt(i) );
		return Array.from(new Int32Array( ary_buf ));
}
function decodeRealArrayFloat32(b64){
	var blob = atob( b64 );
	var ary_buf = new ArrayBuffer( blob.length );
	var dv = new DataView( ary_buf );
	for( var i=0; i < blob.length; i++ ) dv.setUint8( i, blob.charCodeAt(i) );
		return Array.from(new Float32Array( ary_buf ));
};
function decodeRealArrayFloat64(b64){
	var blob = atob( b64 );
	var ary_buf = new ArrayBuffer( blob.length );
	var dv = new DataView( ary_buf );
	for( var i=0; i < blob.length; i++ ) dv.setUint8( i, blob.charCodeAt(i) );
		return Array.from(new Float64Array( ary_buf ));
};

Decoding of binary matrices

function decodeRealMatrixFloat32(b64, sizeX, sizeY){
	var blob = atob( b64 );
	var ary_buf = new ArrayBuffer( blob.length );
	var dv = new DataView( ary_buf );
	for( var i=0; i < blob.length; i++ ) dv.setUint8( i, blob.charCodeAt(i) );
		var oneDimArray = Array.from(new Float32Array( ary_buf ));
		var twoDimArray = new Array(sizeY);
		for (var i = 0; i < twoDimArray.length; i++) {
			twoDimArray[i] = oneDimArray.slice(i*sizeX, (i+1)*sizeX-1);
		}
		return twoDimArray;
	}
};