bit::FloatArray Class Reference

Array for storing floats in quantized form. More...

#include <FloatArray.hh>

Inheritance diagram for bit::FloatArray:

bit::Array List of all members.

Public Member Functions

 FloatArray ()
 Default constructor.
 FloatArray (u64 num_elems, unsigned int bits_per_elem=0)
 Construct an array with initial number of elements.
void set_mode (const FloatArray &array)
 Copy the mode from another array.
void linear_quantization (double step)
 Set linear quantization mode and quantize possible elements in the array.
void linear_quantization_bits (unsigned int bits)
 Perform linear quantization to given number of bits so that maximum absolute value fits just in.
float get (u64 elem) const
 Return value of an element.
void set (u64 elem, float value)
 Set the value of an element.
void set_grow (u64 elem, float value)
 Set the value of an element growing the array if necessary.
void set_grow_widen (u64 elem, float value)
 Set the value of an element growing the array if necessary and widening bit_width if necessary.
u32 to_uint (float value) const
 Convert float value to bit representation.
float to_float (u32 i) const
 Convert an integer bit representation back to float.
void write (FILE *file) const
 Write the array in file.
void read (FILE *file)
 Read the array from file.

Private Types

enum  Mode { mode_default = 0, mode_linear, mode_kmeans }
 Quantization mode. More...

Private Attributes

enum bit::FloatArray::Mode m_mode
 Quantization mode.
double m_linear_step
 The quantization step for linear quantization (used only in mode_linear).

Detailed Description

Array for storing floats in quantized form.

The floats can be quantized either linearly or with k-means clustering.


Member Enumeration Documentation

enum bit::FloatArray::Mode [private]
 

Quantization mode.

Enumerator:
mode_default 
mode_linear 
mode_kmeans 


Constructor & Destructor Documentation

bit::FloatArray::FloatArray  )  [inline]
 

Default constructor.

bit::FloatArray::FloatArray u64  num_elems,
unsigned int  bits_per_elem = 0
[inline]
 

Construct an array with initial number of elements.

Parameters:
num_elems = number of elements to allocate initially
bits_per_elem = number of bits to allocate per element


Member Function Documentation

float bit::FloatArray::get u64  elem  )  const [inline]
 

Return value of an element.

Parameters:
elem = the position to access
Returns:
the value at the element
Exceptions:
bit::out_of_range accessing outside the array

Reimplemented from bit::Array.

void bit::FloatArray::linear_quantization double  step  )  [inline]
 

Set linear quantization mode and quantize possible elements in the array.

Parameters:
step = quantization step
Exceptions:
bit::invalid_argument if step is negative
bit::invalid_call if the array is already quantized

void bit::FloatArray::linear_quantization_bits unsigned int  bits  )  [inline]
 

Perform linear quantization to given number of bits so that maximum absolute value fits just in.

Does nothing if the array has only zero-elements.

Parameters:
bits = number of bits to use (remember that the sign required one bit)
Exceptions:
bit::invalid_argument if bits < 2 or bits > 31

void bit::FloatArray::read FILE *  file  )  [inline]
 

Read the array from file.

Parameters:
file = file stream to read from
Exceptions:
bit::io_error if read fails

Reimplemented from bit::Array.

void bit::FloatArray::set u64  elem,
float  value
[inline]
 

Set the value of an element.

Note that if the array is already quantized, and the value does not fit well to the existing quantization, the quantization error may be large.

Parameters:
elem = the position to set
value = value to store
Exceptions:
bit::out_of_range accessing outside the array

void bit::FloatArray::set_grow u64  elem,
float  value
[inline]
 

Set the value of an element growing the array if necessary.

Note that if the array is already quantized, and the value does not fit well to the existing quantization, the quantization error may be large.

Parameters:
elem = the position to set
value = value to store

void bit::FloatArray::set_grow_widen u64  elem,
float  value
[inline]
 

Set the value of an element growing the array if necessary and widening bit_width if necessary.

Note that if the array is already quantized, and the value does not fit well to the existing quantization, the quantization error may be large.

Parameters:
elem = the position to set
value = value to store

void bit::FloatArray::set_mode const FloatArray array  )  [inline]
 

Copy the mode from another array.

Exceptions:
bit::invalid_call array was not in default mode before the call

float bit::FloatArray::to_float u32  i  )  const [inline]
 

Convert an integer bit representation back to float.

Parameters:
i = integer to convert
return the converted float

u32 bit::FloatArray::to_uint float  value  )  const [inline]
 

Convert float value to bit representation.

Parameters:
value = float to convert
return the converted bit representation

void bit::FloatArray::write FILE *  file  )  const [inline]
 

Write the array in file.

Parameters:
file = file stream to write to
Exceptions:
bit::io_error if write fails

Reimplemented from bit::Array.


Member Data Documentation

double bit::FloatArray::m_linear_step [private]
 

The quantization step for linear quantization (used only in mode_linear).

enum bit::FloatArray::Mode bit::FloatArray::m_mode [private]
 

Quantization mode.


The documentation for this class was generated from the following file:
Generated on Mon Jan 8 15:51:04 2007 for bit by  doxygen 1.4.6