|
PLearn 0.1
|
#include <InstanceSnippetTest.h>


Public Member Functions | |
| InstanceSnippetTest () | |
| Default constructor. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual InstanceSnippetTest * | deepCopy (CopiesMap &copies) const |
| virtual void | build () |
| Post-constructor. | |
| virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
| Transforms a shallow copy into a deep copy. | |
| virtual void | perform () |
| The method performing the test. | |
Static Public Member Functions | |
| static string | _classname_ () |
| 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 Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares the class options. | |
Private Types | |
| typedef PTest | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Definition at line 127 of file InstanceSnippetTest.h.
typedef PTest PLearn::InstanceSnippetTest::inherited [private] |
Reimplemented from PLearn::PTest.
Definition at line 129 of file InstanceSnippetTest.h.
| PLearn::InstanceSnippetTest::InstanceSnippetTest | ( | ) |
Default constructor.
Definition at line 58 of file InstanceSnippetTest.cc.
{
// ...
// ### You may (or not) want to call build_() to finish building the object
// ### (doing so assumes the parent classes' build_() have been called too
// ### in the parent classes' constructors, something that you must ensure)
}
| string PLearn::InstanceSnippetTest::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| OptionList & PLearn::InstanceSnippetTest::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| RemoteMethodMap & PLearn::InstanceSnippetTest::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| Object * PLearn::InstanceSnippetTest::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| StaticInitializer InstanceSnippetTest::_static_initializer_ & PLearn::InstanceSnippetTest::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| void PLearn::InstanceSnippetTest::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::PTest.
Definition at line 71 of file InstanceSnippetTest.cc.
{
inherited::build();
build_();
}
| void PLearn::InstanceSnippetTest::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PTest.
Definition at line 120 of file InstanceSnippetTest.cc.
{
// ### This method should do the real building of the object,
// ### according to set 'options', in *any* situation.
// ### Typical situations include:
// ### - Initial building of an object from a few user-specified options
// ### - Building of a "reloaded" object: i.e. from the complete set of
// ### all serialised options.
// ### - Updating or "re-building" of an object after a few "tuning"
// ### options have been modified.
// ### You should assume that the parent class' build_() has already been
// ### called.
}
| string PLearn::InstanceSnippetTest::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| void PLearn::InstanceSnippetTest::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PTest.
Definition at line 97 of file InstanceSnippetTest.cc.
{
// ### Declare all of this object's options here.
// ### For the "flags" of each option, you should typically specify
// ### one of OptionBase::buildoption, OptionBase::learntoption or
// ### OptionBase::tuningoption. If you don't provide one of these three,
// ### this option will be ignored when loading values from a script.
// ### You can also combine flags, for example with OptionBase::nosave:
// ### (OptionBase::buildoption | OptionBase::nosave)
// ### ex:
// declareOption(ol, "myoption", &InstanceSnippetTest::myoption,
// OptionBase::buildoption,
// "Help text describing this option");
// ...
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}
| static const PPath& PLearn::InstanceSnippetTest::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PTest.
Definition at line 155 of file InstanceSnippetTest.h.
:
//##### Protected Options ###############################################
| InstanceSnippetTest * PLearn::InstanceSnippetTest::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| OptionList & PLearn::InstanceSnippetTest::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| OptionMap & PLearn::InstanceSnippetTest::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| RemoteMethodMap & PLearn::InstanceSnippetTest::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PTest.
Definition at line 53 of file InstanceSnippetTest.cc.
| void PLearn::InstanceSnippetTest::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PTest.
Definition at line 80 of file InstanceSnippetTest.cc.
References PLERROR.
{
inherited::makeDeepCopyFromShallowCopy(copies);
// ### Call deepCopyField on all "pointer-like" fields
// ### that you wish to be deepCopied rather than
// ### shallow-copied.
// ### ex:
// deepCopyField(trainvec, copies);
// ### Remove this line when you have fully implemented this method.
PLERROR("InstanceSnippetTest::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}
| void PLearn::InstanceSnippetTest::perform | ( | ) | [virtual] |
The method performing the test.
A typical test consists in some output (to pout and / or perr), and updates of this object's options.
Reimplemented from PLearn::PTest.
Definition at line 137 of file InstanceSnippetTest.cc.
References PLearn::PythonCodeSnippet::build(), PLearn::TestSnippet::build(), PLearn::endl(), PLearn::getProcessDataMemory(), PLearn::PythonObjectWrapper::getPyObject(), i, PLearn::PythonCodeSnippet::invoke(), PLearn::TestSnippet::ll, PLearn::PythonCodeSnippet::m_compiled_code, PLearn::PythonCodeSnippet::m_instance, PLearn::PLearnError::message(), n, and PLearn::pout.
{
TestSnippet zz1;
zz1.build();
int n= zz1.invoke("getN");
zz1.invoke("test0");
PP<PTester> t= new PTester();//on heap, please
t->final_commands= TVec<string>(2, "allo");
t->splitter= new TrainTestSplitter();
t->learner= zz1.ll;
zz1.invoke("chkObj", t);
zz1.invoke("testRec", n);
zz1.invoke("testRec2", (Object*)zz1.ll);
try
{
zz1.invoke("testRecCrash", 3);
}
catch(const PythonException& e)
{
string exception_msg = e.message();
// Remove memory addresses from the exception message, as they may
// differ from one computer to another, causing the test to fail.
boost::regex memory_adr("0x[abcdef0123456789]{6,}",
boost::regex::perl|boost::regex::icase);
string msg_without_sys_dependent_data =
regex_replace(exception_msg, memory_adr,
"0x[memory_address]");
boost::regex python_ver("Python 2\\.[0-9]\\.[0-9]",
boost::regex::perl|boost::regex::icase);
msg_without_sys_dependent_data =
regex_replace(msg_without_sys_dependent_data, python_ver,
"Python 2.X.Y");
boost::regex plearn_path("(/[a-zA-Z0-9_-]+)+/python_modules/",
boost::regex::perl);
msg_without_sys_dependent_data =
regex_replace(msg_without_sys_dependent_data, plearn_path,
"PLEARN_PYTHON_PATH:");
pout << "[INTENDED ERROR] Caught Python Exception: '"
<< msg_without_sys_dependent_data
<< "'" << endl;
}
PythonCodeSnippet zz2("\nimport gc\n"
"gc.collect()\n"
"print 'nrefs 1010', len(gc.get_referrers(1010))\n");
zz2.build();
TVec<PyObject*> refs= zz1.invoke("getRecTestReferrers");
pout << "refs0: " << (refs[0] == zz1.m_compiled_code.getPyObject()) << endl;
PyObject* dic= PyObject_GetAttrString(zz1.m_instance.getPyObject(), "__dict__");
pout << "refs1: " << (refs[1] == dic) << endl;
Py_DECREF(dic);
#ifndef PYTEST_ACTIVE
for(int i= 0; i < 1000; ++i)
{
zz1.invoke("testRec", n);
zz1.ll->nstages= n;
zz1.invoke("testRec2", (Object*)zz1.ll);
pout << "at iter " << i << "\t: " << getProcessDataMemory() << endl;
}
#endif //ndef PYTEST_ACTIVE
zz1.invoke("fini");
}

Reimplemented from PLearn::PTest.
Definition at line 155 of file InstanceSnippetTest.h.
1.7.4