Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::CompressedVMatrix Class Reference

#include <CompressedVMatrix.h>

Inheritance diagram for PLearn::CompressedVMatrix:

Inheritance graph
[legend]
Collaboration diagram for PLearn::CompressedVMatrix:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CompressedVMatrix ()
 default constructor (for automatic deserialization)

 CompressedVMatrix (int the_max_length, int the_width, size_t memory_alloc=0)
 CompressedVMatrix (VMat v, size_t memory_alloc=0)
 PLEARN_DECLARE_OBJECT (CompressedVMatrix)
virtual ~CompressedVMatrix ()
virtual void appendRow (Vec v)
 This method must be implemented for matrices that are allowed to grow.

size_t memoryAllocated ()
 returns the number of bytes allocated for the data

size_t memoryUsed ()
 returns the memory actually used for the data

virtual void compacify ()
 This will reallocate the data chunk to be exactly of the needed size, so that no memory will be wasted.


Protected Member Functions

void init (int the_max_length, int the_width, size_t memory_alloc)
virtual void getNewRow (int i, const Vec &v) const
 This is the only method requiring implementation in subclasses.


Protected Attributes

int max_length
 maximum number of rows that can be appended to the initially empty matrix

signed char * data
signed char ** rowstarts
signed char * dataend
 data+memory_alloc

signed char * curpos
 next writing position in data chunk


Private Types

typedef RowBufferedVMatrix inherited

Detailed Description

Like MemoryVMatrix this class holds the data in memory. But it is designed to keep a compact representation. Each row is compressed/decompressed through the methods of VecCompressor (it's the same encoding of row vectors that is used in the DiskVMatrix) This encodes only non zero values, using one byte for small integers, and 4-byte floating points for all other values. This representation should be reasonably good for both sparse matrices, and matrices containing categorical data (represented by small integers) possibly with one hot representations.

Definition at line 63 of file CompressedVMatrix.h.


Member Typedef Documentation

typedef RowBufferedVMatrix PLearn::CompressedVMatrix::inherited [private]
 

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 65 of file CompressedVMatrix.h.


Constructor & Destructor Documentation

PLearn::CompressedVMatrix::CompressedVMatrix  ) 
 

default constructor (for automatic deserialization)

Definition at line 53 of file CompressedVMatrix.cc.

PLearn::CompressedVMatrix::CompressedVMatrix int  the_max_length,
int  the_width,
size_t  memory_alloc = 0
 

This initializes the matrix with a length of 0 (but up to the_max_length rows can be appended) If no memory_alloc value is given, a sufficient default value will be used initially. You can always call reallocateCompactMemory() later to use the minimum memory

Definition at line 58 of file CompressedVMatrix.cc.

References init().

PLearn::CompressedVMatrix::CompressedVMatrix VMat  v,
size_t  memory_alloc = 0
 

This initializes a matrix from the data of another. If no memory_alloc value is given, a sufficient default value will be used initially. You can always call reallocateCompactMemory() later to use the minimum memory

Definition at line 73 of file CompressedVMatrix.cc.

References appendRow(), init(), PLearn::VMat::length(), PLearn::Vec, and PLearn::VMat::width().

PLearn::CompressedVMatrix::~CompressedVMatrix  )  [virtual]
 

Definition at line 125 of file CompressedVMatrix.cc.

References data, and rowstarts.


Member Function Documentation

void PLearn::CompressedVMatrix::appendRow Vec  v  )  [virtual]
 

This method must be implemented for matrices that are allowed to grow.

Reimplemented from PLearn::VMatrix.

Definition at line 96 of file CompressedVMatrix.cc.

References curpos, dataend, max_length, PLERROR, and rowstarts.

Referenced by CompressedVMatrix().

void PLearn::CompressedVMatrix::compacify  )  [virtual]
 

This will reallocate the data chunk to be exactly of the needed size, so that no memory will be wasted.

Reimplemented from PLearn::VMatrix.

Definition at line 107 of file CompressedVMatrix.cc.

References curpos, data, dataend, max_length, and rowstarts.

void PLearn::CompressedVMatrix::getNewRow int  i,
const Vec v
const [protected, virtual]
 

This is the only method requiring implementation in subclasses.

Implements PLearn::RowBufferedVMatrix.

Definition at line 85 of file CompressedVMatrix.cc.

References PLearn::TVec< T >::length(), PLERROR, and rowstarts.

void PLearn::CompressedVMatrix::init int  the_max_length,
int  the_width,
size_t  memory_alloc
[protected]
 

This initializes the matrix with a length of 0 (but up to the_max_length rows can be appended) A memory_alloc of length*(2 + 4*width + width/128) should be enough in every case (and much less is needed for matrices containing a lot of 0 or small integers)

Definition at line 62 of file CompressedVMatrix.cc.

References curpos, data, dataend, max_length, and rowstarts.

Referenced by CompressedVMatrix().

size_t PLearn::CompressedVMatrix::memoryAllocated  )  [inline]
 

returns the number of bytes allocated for the data

Definition at line 113 of file CompressedVMatrix.h.

References data, and dataend.

size_t PLearn::CompressedVMatrix::memoryUsed  )  [inline]
 

returns the memory actually used for the data

Definition at line 116 of file CompressedVMatrix.h.

References curpos, and data.

PLearn::CompressedVMatrix::PLEARN_DECLARE_OBJECT CompressedVMatrix   ) 
 


Member Data Documentation

signed char* PLearn::CompressedVMatrix::curpos [protected]
 

next writing position in data chunk

Definition at line 75 of file CompressedVMatrix.h.

Referenced by appendRow(), compacify(), init(), and memoryUsed().

signed char* PLearn::CompressedVMatrix::data [protected]
 

Definition at line 70 of file CompressedVMatrix.h.

Referenced by compacify(), init(), memoryAllocated(), memoryUsed(), and ~CompressedVMatrix().

signed char* PLearn::CompressedVMatrix::dataend [protected]
 

data+memory_alloc

Definition at line 72 of file CompressedVMatrix.h.

Referenced by appendRow(), compacify(), init(), and memoryAllocated().

int PLearn::CompressedVMatrix::max_length [protected]
 

maximum number of rows that can be appended to the initially empty matrix

Definition at line 68 of file CompressedVMatrix.h.

Referenced by appendRow(), compacify(), and init().

signed char** PLearn::CompressedVMatrix::rowstarts [protected]
 

Definition at line 71 of file CompressedVMatrix.h.

Referenced by appendRow(), compacify(), getNewRow(), init(), and ~CompressedVMatrix().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:26:05 2004 for PLearn by doxygen 1.3.7