Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/ein16/synth/d2/obj_ex.py
ViewVC logotype

View of /branches/ein16/synth/d2/obj_ex.py

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3946 - (download) (as text) (annotate)
Sat Jun 11 00:39:19 2016 UTC (2 years, 11 months ago) by cchiw
File size: 3729 byte(s)
 added outer prod
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from obj_ty import *
from obj_operator import *

class example:
    def __init__(self, opr, tys):
    def toStr(self, i):
        name = self.opr.name+" ( "
        curty = self.tys[i]
        for j in curty:
        name+=" )"
        return name
    def get_oprname(self):
        return self.opr.name
    def get_opr(self):
        return self.opr
    def get_ty(self, i):
        if (i >= len(self.tys)):
            raise Exception("unsupported type("+str(i)+") for "+ self.opr.name)
        print ("unsupported type("+str(i)+") for "+ "l"+str(len(self.tys))+self.opr.name)
        return self.tys[i]

#--------------  put list in parameter form  ----------------------
# make list of unary args
def get_unu(fall):
    rtn = []
    # binary operator
    for f in fall:
        #print ("["+f.name+"]")
    return rtn

# binary operator
def get_bin_same(fall):
    rtn = []
    for f in fall:
        #print ("["+f.name+","+g.name+"]")
    return rtn

#binary operators between vector field
# and higher order tensor/tensor field
def get_vF_n(lb, ub):
    rtn = []
    for f in vectorFlds:
        for b in l_all:
            n = len(fty.get_shape(b))
            if((fty.is_Field(b)) and (not check_dim(f,b))): # check equal dim
                #print ("["+f.name+","+b.name+"]")
            if(not fty.isEq_id(f,b)):
                    #print ("["+b.name+","+f.name+"]")
    return rtn

#-------------- make list of type args  ----------------------
# unary args
ps_unu_all =        get_unu(l_all_F)
ex_probe = example(op_probe, ps_unu_all) # 0 probe
ex_negation = example(op_negation,ps_unu_all) #1 negation
# unary operators for all scalar fields
ps_unu_s =          get_unu(scalarFlds)
ex_gradient = example(op_gradient, ps_unu_s) #2 gradient
# unary operators for all vector fields
ps_unu_vec =        get_unu(vectorFlds)
ex_divergence = example(op_divergence, ps_unu_vec)  #3 divergence
ex_curl =  example(op_curl, ps_unu_vec)  #4 curl
ex_jacobian = example(op_jacob, ps_unu_vec) #5 jacobian
#binary operators for the same field
ps_bin_add =         get_bin_same(l_all_F) # 6addition
ex_add = example(op_add, ps_bin_add) #6     addition
ex_subtract = example(op_subtract, ps_bin_add) #7 subtraction
#binary operators between a vector field and higher order tensors with specific shape
ps_bin_vec_cross =  get_vF_n(1,1)
ex_cross = example(op_cross, ps_bin_vec_cross) #8 cross product
ps_bin_vec_outer =  get_vF_n(1,2)           # outer product
ex_outer = example(op_outer, ps_bin_vec_outer) #9  outer product
ps_bin_vec_inner =  get_vF_n(1,3)           # inner product
ex_inner = example(op_inner, ps_bin_vec_inner) #10   inner product
# binar operators, one arg is a scalar 
ps_bin_sca_all = get_mul()
ex_scale = example (op_scale, ps_bin_sca_all)   # scaling
exs = [ex_probe, ex_negation, ex_gradient, ex_divergence, ex_curl, ex_jacobian, ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale]

# returns example object
def get_ex(opr_num):
    return exs[opr_num]

# gets a single examples
def get_single_example(opr_num, ty_num):
    ex = get_ex(opr_num)
    ty = example.get_ty(ex, ty_num)
    name = example.toStr(ex, ty_num)
    opr = example.get_opr(ex)
    return (name, opr,ty)

ViewVC Help
Powered by ViewVC 1.0.0