~registry/ferari/main

« back to all changes in this revision

Viewing changes to FErari/binary.py

  • Committer: Robert C. Kirby
  • Date: 2006-09-26 14:39:49 UTC
  • Revision ID: kirby@uchicago.edu-20060926143949-cmiw3oqwpx7o9qb2
added "optimize_action" function to binary.py
Use this to get a Ferari-ized action of an operator.

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
                code_list.append( (lvalue,rvalue) )
334
334
        return code_list
335
335
 
 
336
def opt_code_action( A0 , p , Adict ):
 
337
        """Constructs optimized code from the original reference
 
338
        tensor, the minimimum spanning tree, and the dictionary."""
 
339
        if len( Adict.keys()[0] ) != 1:
 
340
                raise RuntimeError, "Illegal input"
 
341
        cs = abstract_code( p , Adict )
 
342
 
 
343
        code_list = []
 
344
 
 
345
        def flatten( iota ): return iota[0]
 
346
 
 
347
        def convert( a ):
 
348
                if a[1] == 0:
 
349
                        return (a[0],a[1],flatten(a[2]))
 
350
 
 
351
        for c in cs:
 
352
                lvalue = (0,flatten(c[0]))
 
353
                rvalue = c[1]
 
354
                code_list.append( (lvalue,rvalue) )
 
355
        return code_list
 
356
 
336
357
def optimize( A0 ):
337
358
        """Takes the reference tensor as input and returns
338
359
        abstract code for forming the element tensor."""
346
367
#    p = snip( p , Adict )
347
368
        return opt_code(A0,p,Adict )
348
369
 
 
370
def optimize_action( A0 ):
 
371
        """Takes the reference tensor as input and
 
372
        returns abstract code for forming the action of the
 
373
        element matrix on a vector."""
 
374
        Adict = {}
 
375
        for i in range( A0.shape[0] ):
 
376
                Adict[(i,)] = sigdig.vec_round_sig( Numeric.reshape( A0[i],(-1,) ), 10 )
 
377
 
 
378
        p = process( Adict )
 
379
        print cost( p , Adict )
 
380
        return opt_code_action( A0 , p , Adict )
 
381
 
 
382
 
349
383
def optimize_from_dict( Adict ):
350
384
        """Takes the reference tensor as input and returns
351
385
        abstract code for forming the element tensor."""
359
393
        shape = "triangle"
360
394
        degree = 2
361
395
        A0 = build_tensors.laplacianform(shape,degree)
 
396
#       for c in optimize( A0 ):
 
397
#               print c
 
398
        for c in optimize_action( A0 ):
 
399
                print c
 
400
        print 
362
401
        for c in optimize( A0 ):
363
402
                print c
364
 
    
 
403
 
365
404
if __name__ == "__main__":
366
405
    main()
367
406