# Difference between revisions of "Binary vectors"

Jump to navigation
Jump to search

Line 15: | Line 15: | ||

== File Format == | == File Format == | ||

In Diagham, binary matrix file format is fully supported by any class deriving from Matrix. But the format itself is simple enough to be used by any other code. All data is recorded accroding to the little endian ordering for bytes (the default ordering if you use a x86 or related cpu architecture). Using the C/C++ types, the format depends on the type of data. For real vectors with less than 2^31 components, the binary vectors are stored as | |||

* int (4-bytes) : vector dimension | |||

* double (8-bytes) * dim : as many double as we have vector component | |||

Below we give a simple example of a python code reading a real binary vector test.vec and computing its square norm | |||

## Latest revision as of 13:07, 6 June 2018

DiagHam stores vectors in binary mode. A full set of tools is provided in to manipulate them.

## Tools

- GenericOverlap
- compute overlaps between binary vectors
- NormalizeVector
- normalize a binary vector
- VectorBinary2Ascii
- convert from a binary vector to a text file
- VectorAscii2Binary
- convert from a column formated text file to a binary file
- CountingZero
- count the number of zero components in a binary vector
- BuildSuperPosition
- create a linear superposition of binary vectors
- ExtractLinearlyIndependentVectors
- extract a set of linearly independent vectors from a given set of vectors
- VectorPhaseMultiply
- multiply a binary vector with a complex phase factor
- DiffBinaryVectors
- compares two binary vectors

## File Format

In Diagham, binary matrix file format is fully supported by any class deriving from Matrix. But the format itself is simple enough to be used by any other code. All data is recorded accroding to the little endian ordering for bytes (the default ordering if you use a x86 or related cpu architecture). Using the C/C++ types, the format depends on the type of data. For real vectors with less than 2^31 components, the binary vectors are stored as

- int (4-bytes) : vector dimension
- double (8-bytes) * dim : as many double as we have vector component

Below we give a simple example of a python code reading a real binary vector test.vec and computing its square norm

import numpy as np import os InputFile = open('test.vec','rb') Dimension = np.fromfile(InputFile, '<i4', count=1)[0] print ('Vector Dimension = '+str(Dimension)) Vector = np.fromfile(InputFile, '<d', count=Dimension) Norm = 0.0 for Component in Vector: Norm += Component * Component print ('Sqr Norm = '+str(Norm)) InputFile.close()