public byte [ ] asByteArray ( NumberVector vector ) { final long [ ] longValueList = new long [ dimensionality ] ; for ( int dim = 0 ; dim < dimensionality ; ++ dim ) { final double minValue = minValues [ dim ] ; final double maxValue = maxValues [ dim ] ; double dimValue = vector . doubleValue ( dim ) ; dimValue = ( dimValue - minValue ) / ( maxValue - minValue ) ; longValueList [ dim ] = ( long ) ( dimValue * ( Long . MAX_VALUE ) ) ; } final byte [ ] bytes = new byte [ Long . SIZE * dimensionality * ( Long . SIZE / Byte . SIZE ) ] ; int shiftCounter = 0 ; for ( int i = 0 ; i < Long . SIZE ; ++ i ) { for ( int dim = 0 ; dim < dimensionality ; ++ dim ) { long byteValue = longValueList [ dim ] ; int localShift = shiftCounter % Byte . SIZE ; bytes [ ( bytes . length - 1 ) - ( shiftCounter / Byte . SIZE ) ] |= ( ( byteValue >> i ) & 0x01 ) << localShift ; shiftCounter ++ ; } } return bytes ; }
Transform a single vector .