|
PLearn 0.1
|
Interleave several VMats row-wise. More...
#include <InterleaveVMatrix.h>


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 OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual InterleaveVMatrix * | deepCopy (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 PPath & | declaringFile () |
| static void | declareOptions (OptionList &ol) |
| Declare this class' options. | |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Attributes | |
| TVec< VMat > | sources |
Private Types | |
| typedef VMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
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.
typedef VMatrix PLearn::InterleaveVMatrix::inherited [private] |
Reimplemented from PLearn::VMatrix.
Definition at line 70 of file InterleaveVMatrix.h.
| PLearn::InterleaveVMatrix::InterleaveVMatrix | ( | ) |
default constructor (for automatic deserialization)
Definition at line 65 of file InterleaveVMatrix.cc.
{ }
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.

| string PLearn::InterleaveVMatrix::_classname_ | ( | ) | [static] |
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.
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().
{
inherited::build();
build_();
}


| 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]);
}
}


| 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);
}

| static const PPath& PLearn::InterleaveVMatrix::declaringFile | ( | ) | [inline, static] |
| InterleaveVMatrix * PLearn::InterleaveVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::VMatrix.
Definition at line 63 of file InterleaveVMatrix.cc.
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);
}

| 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.
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);
}

| 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.
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(sources, copies);
}

| 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.
{
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;
}
Reimplemented from PLearn::VMatrix.
Definition at line 87 of file InterleaveVMatrix.h.
TVec<VMat> PLearn::InterleaveVMatrix::sources [protected] |
Definition at line 73 of file InterleaveVMatrix.h.
Referenced by build_(), declareOptions(), get(), getSubRow(), InterleaveVMatrix(), and makeDeepCopyFromShallowCopy().
1.7.4