Mercurial > pylearn
comparison pmat.py @ 115:01aa97a2212d
removed dependency to plearn
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Wed, 07 May 2008 12:19:36 -0400 |
parents | d6d42a0c1275 |
children | 9330d941fa1f |
comparison
equal
deleted
inserted
replaced
114:d6d42a0c1275 | 115:01aa97a2212d |
---|---|
34 | 34 |
35 # Author: Pascal Vincent | 35 # Author: Pascal Vincent |
36 | 36 |
37 #import numarray, sys, os, os.path | 37 #import numarray, sys, os, os.path |
38 import numpy.numarray, sys, os, os.path | 38 import numpy.numarray, sys, os, os.path |
39 pyplearn_import_failed = False | |
40 try: | |
41 from plearn.pyplearn.plearn_repr import plearn_repr, format_list_elements | |
42 except ImportError: | |
43 pyplearn_import_failed = True | |
44 | |
45 | |
46 | 39 |
47 def array_columns( a, cols ): | 40 def array_columns( a, cols ): |
48 indices = None | 41 indices = None |
49 if isinstance( cols, int ): | 42 if isinstance( cols, int ): |
50 indices = [ cols ] | 43 indices = [ cols ] |
420 self.putRow(i,row) | 413 self.putRow(i,row) |
421 | 414 |
422 def __len__(self): | 415 def __len__(self): |
423 return self.length | 416 return self.length |
424 | 417 |
425 if not pyplearn_import_failed: | |
426 def __str__( self ): | |
427 return plearn_repr(self, indent_level=0) | |
428 | |
429 def plearn_repr( self, indent_level=0, inner_repr=plearn_repr ): | |
430 # asking for plearn_repr could be to send specification over | |
431 # to another prg so that will open the .pmat | |
432 # So we make sure data is flushed to disk. | |
433 self.flush() | |
434 | |
435 def elem_format( elem ): | |
436 k, v = elem | |
437 return '%s = %s' % ( k, inner_repr(v, indent_level+1) ) | |
438 | |
439 options = [ ( 'filename', self.fname ), | |
440 ( 'inputsize', self.inputsize ), | |
441 ( 'targetsize', self.targetsize ), | |
442 ( 'weightsize', self.weightsize ) ] | |
443 return 'FileVMatrix(%s)' % format_list_elements( options, elem_format, indent_level+1 ) | |
444 | 418 |
445 if __name__ == '__main__': | 419 if __name__ == '__main__': |
446 pmat = PMat( 'tmp.pmat', 'w', fieldnames=['F1', 'F2'] ) | 420 pmat = PMat( 'tmp.pmat', 'w', fieldnames=['F1', 'F2'] ) |
447 pmat.append( [1, 2] ) | 421 pmat.append( [1, 2] ) |
448 pmat.append( [3, 4] ) | 422 pmat.append( [3, 4] ) |