Binary vectors

From diagham
Jump to navigation Jump to search

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


compute overlaps between binary vectors
normalize a binary vector
convert from a binary vector to a text file
convert from a column formated text file to a binary file
count the number of zero components in a binary vector
create a linear superposition of binary vectors
extract a set of linearly independent vectors from a given set of vectors
multiply a binary vector with a complex phase factor
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))