예제 #1
0
파일: __init__.py 프로젝트: zbxzc35/PLearn
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 )
예제 #2
0
파일: __init__.py 프로젝트: zbxzc35/PLearn
    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)
예제 #3
0
def elemFormat(e):
    if isinstance(e, str):
        return e  # Not quoted...
    elif isinstance(e, float):
        return "%.2f" % e
    return plearn_repr(e)
예제 #4
0
파일: serialize.py 프로젝트: zbxzc35/PLearn
 def write_typed(self, x):
     spec = plearn_repr(x) + ' '
     self.write(spec)
예제 #5
0
파일: formatter.py 프로젝트: deccs/PLearn
def elemFormat(e):
    if isinstance(e, str):
        return e # Not quoted...
    elif isinstance(e, float):
        return "%.2f"%e
    return plearn_repr(e)
예제 #6
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 )
예제 #7
0
파일: serialize.py 프로젝트: deccs/PLearn
 def write_typed(self, x):
     spec = plearn_repr(x)+' '
     self.write(spec)
예제 #8
0
파일: PMat.py 프로젝트: zbxzc35/PLearn
 def __str__( self ):
     return plearn_repr(self, indent_level=0)
예제 #9
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)