|
PLearn 0.1
|
#include <PrecomputedVMatrix.h>


Public Member Functions | |
| PrecomputedVMatrix () | |
| virtual void | setMetaDataDir (const PPath &the_metadatadir) |
| Also sets the source's meta-data dir if it's not already set. | |
| virtual void | build () |
| Simply calls inherited::build() then build_(). | |
| virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
| Transforms a shallow copy into a deep copy. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual PrecomputedVMatrix * | deepCopy (CopiesMap &copies) const |
Static Public Member Functions | |
| static string | _classname_ () |
| Declares name and deepCopy methods. | |
| 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 () |
Public Attributes | |
| string | precomp_type |
| bool | temporary |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
| virtual void | getNewRow (int i, const Vec &v) const |
| This is the only method requiring implementation. | |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares this class' options. | |
Protected Attributes | |
| VMat | precomp_source |
| The precomputed source (FileVMatrix or DiskVMatrix). | |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
| void | usePrecomputed () |
Definition at line 53 of file PrecomputedVMatrix.h.
typedef SourceVMatrix PLearn::PrecomputedVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 55 of file PrecomputedVMatrix.h.
| PLearn::PrecomputedVMatrix::PrecomputedVMatrix | ( | ) |
Definition at line 57 of file PrecomputedVMatrix.cc.
:
precomp_type("dmat"),
temporary(false)
{}
| string PLearn::PrecomputedVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| OptionList & PLearn::PrecomputedVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| RemoteMethodMap & PLearn::PrecomputedVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| Object * PLearn::PrecomputedVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| StaticInitializer PrecomputedVMatrix::_static_initializer_ & PLearn::PrecomputedVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| void PLearn::PrecomputedVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 194 of file PrecomputedVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
Referenced by PLearn::LocallyPrecomputedVMatrix::build(), and PLearn::LocallyPrecomputedVMatrix::build_().
{
inherited::build();
build_();
}


| void PLearn::PrecomputedVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 185 of file PrecomputedVMatrix.cc.
References PLearn::VMatrix::hasMetaDataDir(), PLearn::VMat::length(), PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::SourceVMatrix::source, and PLearn::VMat::width().
Referenced by build().
{
//We don't always call it as some matrix(FilteredVMatrix) are only
//completly set if they have a metadatadir.
if(hasMetaDataDir() ||(source->width()>0 && source->length()>0))
setMetaInfoFromSource();
}


| string PLearn::PrecomputedVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| void PLearn::PrecomputedVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 87 of file PrecomputedVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), PLearn::VMatrix::inputsize_, PLearn::VMatrix::length_, PLearn::OptionBase::nosave, precomp_type, PLearn::redeclareOption(), PLearn::VMatrix::targetsize_, temporary, PLearn::VMatrix::weightsize_, PLearn::VMatrix::width_, and PLearn::VMatrix::writable.
Referenced by PLearn::LocallyPrecomputedVMatrix::declareOptions().
{
declareOption(ol, "precomp_type", &PrecomputedVMatrix::precomp_type, OptionBase::buildoption,
"The type of VMatrix to be used for the cached precomputed version\n"
"of the source. Currently supported are 'dmat' and 'pmat'.");
declareOption(ol, "temporary", &PrecomputedVMatrix::temporary, OptionBase::buildoption,
"If set to 1, the created precomputed data will be temporary, i.e.\n"
"will be deleted when not used anymore.");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
// Hide useless options.
redeclareOption(ol, "writable", &PrecomputedVMatrix::writable, OptionBase::nosave,
"Unused option.");
redeclareOption(ol, "length", &PrecomputedVMatrix::length_, OptionBase::nosave,
"Unused option.");
redeclareOption(ol, "width", &PrecomputedVMatrix::width_, OptionBase::nosave,
"Unused option.");
redeclareOption(ol, "inputsize", &PrecomputedVMatrix::inputsize_, OptionBase::nosave,
"Unused option.");
redeclareOption(ol, "targetsize", &PrecomputedVMatrix::targetsize_, OptionBase::nosave,
"Unused option.");
redeclareOption(ol, "weightsize", &PrecomputedVMatrix::weightsize_, OptionBase::nosave,
"Unused option.");
}


| static const PPath& PLearn::PrecomputedVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 108 of file PrecomputedVMatrix.h.
| PrecomputedVMatrix * PLearn::PrecomputedVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
This is the only method requiring implementation.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 76 of file PrecomputedVMatrix.cc.
References PLearn::PP< T >::isNull(), PLERROR, and precomp_source.
{
if(precomp_source.isNull())
PLERROR("Source has not been precomputed. Did you properly set the "
"MetaDataDir?");
precomp_source->getRow(i,v);
}

| OptionList & PLearn::PrecomputedVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| OptionMap & PLearn::PrecomputedVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| RemoteMethodMap & PLearn::PrecomputedVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 71 of file PrecomputedVMatrix.cc.
| void PLearn::PrecomputedVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 200 of file PrecomputedVMatrix.cc.
References PLearn::deepCopyField(), PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), and precomp_source.
Referenced by PLearn::LocallyPrecomputedVMatrix::makeDeepCopyFromShallowCopy().
{
inherited::makeDeepCopyFromShallowCopy(copies);
// ### Call deepCopyField on all "pointer-like" fields
// ### that you wish to be deepCopied rather than
// ### shallow-copied.
// ### ex:
deepCopyField(precomp_source, copies);
}


| void PLearn::PrecomputedVMatrix::setMetaDataDir | ( | const PPath & | the_metadatadir | ) | [virtual] |
Also sets the source's meta-data dir if it's not already set.
If there are fields that have no corresponding .smap .notes or .binning info files but the source has those files for a field with the same name, then those of the source will be set also for this vmatrix.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 118 of file PrecomputedVMatrix.cc.
References PLearn::VMatrix::hasMetaDataDir(), PLearn::SourceVMatrix::setMetaDataDir(), PLearn::SourceVMatrix::setMetaInfoFromSource(), and usePrecomputed().
{
inherited::setMetaDataDir(the_metadatadir);
if ( hasMetaDataDir() ) // don't do anything if the meta-data-dir is not yet set.
{
setMetaInfoFromSource();
usePrecomputed();
}
}

| void PLearn::PrecomputedVMatrix::usePrecomputed | ( | ) | [private] |
Definition at line 128 of file PrecomputedVMatrix.cc.
References PLearn::force_rmdir(), PLearn::VMatrix::getMetaDataDir(), PLearn::isdir(), PLearn::isfile(), PLearn::VMatrix::isUpToDate(), PLearn::VMat::length(), PLearn::VMatrix::length_, PLERROR, precomp_source, precomp_type, PLearn::rm(), PLearn::SourceVMatrix::source, and temporary.
Referenced by setMetaDataDir().
{
PPath mdir = getMetaDataDir();
if ( precomp_type == "dmat" )
{
PPath dmatdir = mdir / "precomp.dmat";
bool recompute = true;
if ( isdir(dmatdir) )
{
precomp_source = temporary ? new TemporaryDiskVMatrix(dmatdir,
false)
: new DiskVMatrix(dmatdir);
if(isUpToDate(precomp_source))
recompute = false;
}
if(recompute)
{
force_rmdir(dmatdir);
source->saveDMAT(dmatdir);
precomp_source = temporary ? new TemporaryDiskVMatrix(dmatdir,
false)
: new DiskVMatrix(dmatdir);
}
length_ = precomp_source->length();
}
else if ( precomp_type == "pmat" )
{
PPath pmatfile = mdir / "precomp.pmat";
bool recompute = true;
if ( isfile(pmatfile) )
{
precomp_source = temporary ? new TemporaryFileVMatrix(pmatfile)
: new FileVMatrix(pmatfile);
if(isUpToDate(pmatfile))
recompute = false;
}
if(recompute)
{
rm(pmatfile);
source->savePMAT(pmatfile);
precomp_source = temporary ? new TemporaryFileVMatrix(pmatfile)
: new FileVMatrix(pmatfile);
}
length_ = precomp_source->length();
}
else
PLERROR("Invalid precomp_type=%s. Must be one of: dmat, pmat.",
precomp_type.c_str());
}


Reimplemented from PLearn::SourceVMatrix.
Reimplemented in PLearn::LocallyPrecomputedVMatrix.
Definition at line 108 of file PrecomputedVMatrix.h.
VMat PLearn::PrecomputedVMatrix::precomp_source [protected] |
The precomputed source (FileVMatrix or DiskVMatrix).
Definition at line 60 of file PrecomputedVMatrix.h.
Referenced by PLearn::LocallyPrecomputedVMatrix::build_(), getNewRow(), makeDeepCopyFromShallowCopy(), usePrecomputed(), and PLearn::LocallyPrecomputedVMatrix::~LocallyPrecomputedVMatrix().
Definition at line 67 of file PrecomputedVMatrix.h.
Referenced by declareOptions(), PLearn::LocallyPrecomputedVMatrix::LocallyPrecomputedVMatrix(), usePrecomputed(), and PLearn::LocallyPrecomputedVMatrix::~LocallyPrecomputedVMatrix().
Definition at line 68 of file PrecomputedVMatrix.h.
Referenced by PLearn::LocallyPrecomputedVMatrix::build_(), declareOptions(), PLearn::LocallyPrecomputedVMatrix::LocallyPrecomputedVMatrix(), usePrecomputed(), and PLearn::LocallyPrecomputedVMatrix::~LocallyPrecomputedVMatrix().
1.7.4