def plvar( varname, value ): """Emulating PLearn's $DEFINE statement. An old .plearn script (included with include()) may depend on some variables to be defined externally. If one wants to define that variable within a PyPLearn script, he must use this function with two arguments:: plvar( 'DATASET', pl.AutoVMatrix( specification = "somefile.pmat", inputsize = 10, targetsize = 1 ) ) which is strictly equivalent to the old:: $DEFINE{DATASET}{ AutoVMatrix( specification = "somefile.pmat"; inputsize = 10; targetsize = 1 ) } If, on the other hand, a variable is defined within the PLearn script and must be referenced within PyPLearn, the simple C{plvar('DATASET')} will refer to the variable just as C{${DATASET}} would have. """ if value is None: snippet = '${%s}' % varname else: snippet = '$DEFINE{%s}{ %s }' % ( varname, plearn_repr( value, indent_level+1 ) ) return PLearnSnippet( snippet )
print sub2.__class__.__name__, id(sub2.__class__) print sub2 print sub3 = pl.Subclass() print sub3.__class__.__name__, id(sub3.__class__) print sub3 print if __name__ == "__main__": print TMat(2, 2, ["allo", "mon", "petit", "coco"]).plearn_repr() print print "Simple list:\n" a = [1, 2, 3] print plearn_repr(a) print plearn_repr(a) print "---" print print "TVec( list ):\n" b = TVec(a) print plearn_repr(b) print plearn_repr(b) print "---" print print "copy.deepcopy( tvec ):\n" c = copy.deepcopy(b) print plearn_repr(c) print plearn_repr(c)
def elemFormat(e): if isinstance(e, str): return e # Not quoted... elif isinstance(e, float): return "%.2f" % e return plearn_repr(e)
def write_typed(self, x): spec = plearn_repr(x) + ' ' self.write(spec)
def elemFormat(e): if isinstance(e, str): return e # Not quoted... elif isinstance(e, float): return "%.2f"%e return plearn_repr(e)
def __str__( self ): """Calls plearn_repr global function over itself.""" # It is most important no to call this instance's plearn_repr # method!!! Indeed, if we did so, we'd neglect to add the current # instance in the representations map... return plearn_repr( self, indent_level = 0 )
def write_typed(self, x): spec = plearn_repr(x)+' ' self.write(spec)
def __str__( self ): return plearn_repr(self, indent_level=0)
def __str__(self): """Calls plearn_repr global function over itself.""" # It is most important no to call this instance's plearn_repr # method!!! Indeed, if we did so, we'd neglect to add the current # instance in the representations map... return plearn_repr(self, indent_level=0)