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 4210 - (download) (as text) (annotate)
Thu Jul 14 18:01:19 2016 UTC (3 years, 8 months ago) by cchiw
File size: 5061 byte(s)
build on testing
# -*- 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  ----------------------
# ps_..  list of unary args   [[a],[b],..]
# unary args
ps_unu_all =        get_unu(l_all_F)    # all fields
ps_unu_s =          get_unu(scalarFlds) # all scalar fields
ps_unu_s_notd1 =    get_unu(scalarFldsnotd1) # all scalar fields
ps_unu_vec =        get_unu(vectorFlds) # all vector fields
ps_unu_mat =        get_unu(matrixFlds) # all matrix fields
# unary operators
ex_probe = example(op_probe, ps_unu_all)            # probe
ex_negation = example(op_negation,ps_unu_all)       # negation
ex_gradient = example(op_gradient, ps_unu_s_notd1)  # gradient
ex_divergence = example(op_divergence, ps_unu_vec)  # divergence
ex_curl =  example(op_curl, ps_unu_vec)             # curl
ex_jacobian = example(op_jacob, ps_unu_vec)         # jacobian
ex_norm = example(op_norm, ps_unu_all)              # norm
ex_normalize = example(op_normalize, ps_unu_all)    # normalize
ex_trace = example(op_trace, ps_unu_mat)            # trace
ex_transpose = example(op_transpose, ps_unu_mat)    # tranpose
ex_det = example(op_det, ps_unu_mat)            # det

# binary args
# makes sure one arg is a field and the other has the same shape
ps_bin_add = get_add()
#binary ops between a vector field and higher-order tensors with specific shape
ps_bin_vec_cross =  get_vF_n(1,1)           # cross product
ps_bin_vec_outer =  get_vF_n(1,2)           # outer product
ps_bin_vec_inner =  get_vF_n(1,3)           # inner product
ps_bin_sca_all =    get_mul()                  # one arg is a scalar
ps_bin_sca_second = get_division()          # second arg is a scalar
#binary opertaors
ex_add = example(op_add, ps_bin_add) #     addition
ex_subtract = example(op_subtract, ps_bin_add) # subtraction
ex_cross = example(op_cross, ps_bin_vec_cross) # cross product
ex_outer = example(op_outer, ps_bin_vec_outer) # outer product
ex_inner = example(op_inner, ps_bin_vec_inner) # inner product
ex_scale = example (op_scale, ps_bin_sca_all)   # scaling
ex_division= example (op_division, ps_bin_sca_second)   # 11 division

# order of edxamples
exs_unary = [ex_probe, ex_negation, ex_gradient, ex_divergence, ex_curl, ex_jacobian, ex_norm, ex_normalize, ex_trace, ex_transpose, ex_det]
exs_binary = [ex_add, ex_subtract, ex_cross, ex_outer, ex_inner, ex_scale, ex_division]

exs = exs_unary+exs_binary

def get_exname(opr_num):
    n =len(exs)
        return ("not enough examples on list: "+str(opr_num)+ "|"+str(n))
    return exs[opr_num].opr.name

# returns example object
def get_ex(opr_num):
    n =len(exs)
        raise Exception ("not enough examples on list: "+str(opr_num)+ "|"+str(n))
    l = exs[opr_num]
    return l

# gets a single examples
def get_single_exampleName(opr_num):
    return example.get_opr(get_ex(opr_num)).name

# gets a single examples
def get_single_example(opr_num, ty_num):
    ex = get_ex(opr_num)
    print "cup -a"
    ty = example.get_ty(ex, ty_num)
    print "cup -b"
    name = example.toStr(ex, ty_num)
    print "cup -c"
    opr = example.get_opr(ex)
    print "cup -d"
    return (name, opr,ty)

ViewVC Help
Powered by ViewVC 1.0.0