PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Types | Private Member Functions
PLearn::InterleaveVMatrix Class Reference

Interleave several VMats row-wise. More...

#include <InterleaveVMatrix.h>

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

List of all members.

Public Member Functions

 InterleaveVMatrix ()
 default constructor (for automatic deserialization)
 InterleaveVMatrix (TVec< VMat > the_sources)
 The field names are copied from the first VMat in the array.
 InterleaveVMatrix (VMat source1, VMat source2)
 The field names are copied from the first VMat source1.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual InterleaveVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual real get (int i, int j) const
 VMatrix overrides.
virtual void getSubRow (int i, int j, Vec v) const
 It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).
virtual void reset_dimensions ()
 In case the dimensions of an underlying VMat has changed, recompute it.

Static Public Member Functions

static string _classname_ ()
 InterleaveVMatrix.
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()
static void declareOptions (OptionList &ol)
 Declare this class' options.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Attributes

TVec< VMatsources

Private Types

typedef VMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Interleave several VMats row-wise.

This class interleaves several VMats (with consecutive rows always coming from a different source VMat) thus possibly including more than once the rows of the small VMats. For example, if source1.length()==10 and source2.length()==30 then the resulting VM will have 60 rows, and 3 repetitions of each row of source1, with rows taken as follows:

source1.row(0), source2.row(0), source1.row(1), source2.row(1), ..., source1.row(9), source2.row(9), source1.row(0), cource2.row(10), ...

Note that if source2.length() is not a multiple of source1.length() some records from source1 will be repeated once more than others.

Definition at line 68 of file InterleaveVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::VMatrix.

Definition at line 70 of file InterleaveVMatrix.h.


Constructor & Destructor Documentation

PLearn::InterleaveVMatrix::InterleaveVMatrix ( )

default constructor (for automatic deserialization)

Definition at line 65 of file InterleaveVMatrix.cc.

{ }
PLearn::InterleaveVMatrix::InterleaveVMatrix ( TVec< VMat the_sources)

The field names are copied from the first VMat in the array.

Definition at line 68 of file InterleaveVMatrix.cc.

References build(), PLearn::TVec< T >::size(), and sources.

    : sources(the_sources)
{
    if (sources.size() > 0)
        build();
}

Here is the call graph for this function:

PLearn::InterleaveVMatrix::InterleaveVMatrix ( VMat  source1,
VMat  source2 
)

The field names are copied from the first VMat source1.

Definition at line 75 of file InterleaveVMatrix.cc.

References build(), and sources.

    : sources(2)
{
    sources[0] = source1;
    sources[1] = source2;
    build();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::InterleaveVMatrix::_classname_ ( ) [static]

InterleaveVMatrix.

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

OptionList & PLearn::InterleaveVMatrix::_getOptionList_ ( ) [static]

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

RemoteMethodMap & PLearn::InterleaveVMatrix::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

bool PLearn::InterleaveVMatrix::_isa_ ( const Object o) [static]

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

Object * PLearn::InterleaveVMatrix::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 63 of file InterleaveVMatrix.cc.

StaticInitializer InterleaveVMatrix::_static_initializer_ & PLearn::InterleaveVMatrix::_static_initialize_ ( ) [static]

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

void PLearn::InterleaveVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::VMatrix.

Definition at line 83 of file InterleaveVMatrix.cc.

References PLearn::VMatrix::build(), and build_().

Referenced by InterleaveVMatrix().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::InterleaveVMatrix::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 89 of file InterleaveVMatrix.cc.

References i, PLearn::TVec< T >::length(), PLearn::VMatrix::length_, n, PLERROR, PLearn::VMatrix::setMetaInfoFrom(), PLearn::TVec< T >::size(), sources, PLearn::VMatrix::updateMtime(), PLearn::VMatrix::width(), and PLearn::VMatrix::width_.

Referenced by build().

{
    if (sources) {
        int n = sources.size();
        if (n<1)
            PLERROR("InterleaveVMatrix expects >= 1 sources, got %d",n);

        width_ = sources[0]->width();
        int maxl = 0;
        for (int i = 0; i < n; i++) {
            if (sources[i]->width() != width_)
                PLERROR("InterleaveVMatrix: source %d has %d width, while 0-th has %d",
                        i, sources[i]->width(), width_);
            int l = sources[i]->length();
            if (l > maxl)
                maxl=l;
            updateMtime(sources[i]);
        }
        length_ = n * maxl;

        // Finally copy remaining meta information from first VMatrix
        setMetaInfoFrom(sources[0]);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::InterleaveVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file InterleaveVMatrix.cc.

void PLearn::InterleaveVMatrix::declareOptions ( OptionList ol) [static]

Declare this class' options.

Reimplemented from PLearn::VMatrix.

Definition at line 114 of file InterleaveVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), and sources.

{
    declareOption(ol, "sources", &InterleaveVMatrix::sources,
                  OptionBase::buildoption,
                  "Set of VMats to be concatenated");

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::InterleaveVMatrix::declaringFile ( ) [inline, static]

Reimplemented from PLearn::VMatrix.

Definition at line 87 of file InterleaveVMatrix.h.

{
InterleaveVMatrix * PLearn::InterleaveVMatrix::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::VMatrix.

Definition at line 63 of file InterleaveVMatrix.cc.

real PLearn::InterleaveVMatrix::get ( int  i,
int  j 
) const [virtual]

VMatrix overrides.

Implements PLearn::VMatrix.

Definition at line 123 of file InterleaveVMatrix.cc.

References PLearn::TVec< T >::length(), PLearn::VMatrix::length(), m, n, PLERROR, PLearn::TVec< T >::size(), sources, and PLearn::VMatrix::width().

{
#ifdef BOUNDCHECK
    if(i<0 || i>=length() || j<0 || j>=width())
        PLERROR("In InterleaveVMatrix::get OUT OF BOUNDS");
#endif
    int n = sources.size();
    int m = i%n; // which source
    int pos = int(i/n) % sources[m].length(); // position within sources[m]
    return sources[m]->get(pos,j);
}

Here is the call graph for this function:

OptionList & PLearn::InterleaveVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file InterleaveVMatrix.cc.

OptionMap & PLearn::InterleaveVMatrix::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file InterleaveVMatrix.cc.

RemoteMethodMap & PLearn::InterleaveVMatrix::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 63 of file InterleaveVMatrix.cc.

void PLearn::InterleaveVMatrix::getSubRow ( int  i,
int  j,
Vec  v 
) const [virtual]

It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).

Fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive).

Reimplemented from PLearn::VMatrix.

Definition at line 135 of file InterleaveVMatrix.cc.

References PLearn::VMatrix::length(), PLearn::TVec< T >::length(), m, n, PLERROR, PLearn::TVec< T >::size(), sources, and PLearn::VMatrix::width().

{
#ifdef BOUNDCHECK
    if(i<0 || i>=length() || j<0 || j+v.length()>width())
        PLERROR("In InterleaveVMatrix::getRow OUT OF BOUNDS");
#endif
    int n = sources.size();
    int m = i%n; // which source
    int pos = int(i/n) % sources[m].length(); // position within sources[m]
    sources[m]->getSubRow(pos, j, v);
}

Here is the call graph for this function:

void PLearn::InterleaveVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::VMatrix.

Definition at line 147 of file InterleaveVMatrix.cc.

References PLearn::deepCopyField(), PLearn::VMatrix::makeDeepCopyFromShallowCopy(), and sources.

Here is the call graph for this function:

virtual void PLearn::InterleaveVMatrix::reset_dimensions ( ) [inline, virtual]

In case the dimensions of an underlying VMat has changed, recompute it.

Reimplemented from PLearn::VMatrix.

Definition at line 98 of file InterleaveVMatrix.h.

References i, n, and PLERROR.

    {
        for (int i=0;i<sources.size();i++) sources[i]->reset_dimensions();
        width_=sources[0]->width();
        int maxl = 0;
        int n=sources.size();
        for (int i=0;i<n;i++)
        {
            if (sources[i]->width()!=width_)
                PLERROR("InterleaveVMatrix: source %d has %d width, while 0-th has %d",
                        i, sources[i]->width(), width_);
            int l= sources[i]->length();
            if (l>maxl) maxl=l;
        }
        length_=n*maxl;
    }

Member Data Documentation

Reimplemented from PLearn::VMatrix.

Definition at line 87 of file InterleaveVMatrix.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines