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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4485 - (download) (as text) (annotate)
Fri Sep 2 20:11:13 2016 UTC (2 years, 6 months ago) by cchiw
File size: 4182 byte(s)
adjustments to shape-forward
from obj_field import *
from obj_operator import *
from obj_ty import *


#########################################################################################################
#given a field of a particular dim, return all types with that dimension.
def d_tofield(dim):
    if(dim==1):
        return [ty_scalarF_d1, ty_vec2F_d1, ty_vec3F_d1, ty_vec4F_d1, ty_mat2x2F_d1, ty_mat3x3F_d1]
    elif(dim==2):
        return  [ty_scalarF_d2, ty_vec2F_d2, ty_vec3F_d2, ty_vec4F_d2, ty_mat2x2F_d2, ty_mat3x3F_d2]
    elif(dim==3):
        return  [ty_scalarF_d3, ty_vec2F_d3, ty_vec3F_d3, ty_vec4F_d3, ty_mat2x2F_d3, ty_mat3x3F_d3]
    else:
        return l_all1

# moving backwards
# given opr_outer what are the allowed result types
def expected_inshape(op1):
    # (op1) input type -> output type
    if(op1 == op_gradient):
        d1 = [(ty_scalarF_d1, ty_scalarF_d1)]
        d2 = [(ty_scalarF_d2, ty_vec2F_d2)]
        d3 =[(ty_scalarF_d3, ty_vec3F_d3)]
        return d1+d2+d3
    elif(op1 == op_divergence):
        d2 = [(ty_vec2F_d2, ty_scalarF_d2)]
        d3 =[(ty_vec3F_d3, ty_scalarF_d3)]
        return d2+d3
    elif(op1 == op_curl):
        d2 = [(ty_vec2F_d2, ty_scalarF_d2)]
        d3 =[(ty_vec3F_d3, ty_vec3F_d3)]
        return d2+d3
    elif(op1 == op_jacob):
        d2 = [(ty_vec2F_d2, ty_mat2x2F_d2),(ty_mat2x2F_d2, ty_ten2x2x2F_d2)]
        d3 =[(ty_vec3F_d3, ty_mat3x3F_d3), (ty_mat3x3F_d3, ty_ten3x3x3F_d3)]
        return d2+d3
    elif(op1==op_normalize):
        m =[]
        for i in l_all1:
            if(not (tty.isSca(i))):
                m.append([i, i])
        return m
    elif((op1 ==op_norm)):
        m =[]
        for i in l_all1:
            m.append((i, shape_to_fty(ty_scalarT)))
        return m

    elif((op1 == op_negation) or (op1==op_copy)):
        m =[]
        for i in l_all1:
            m.append([i, i])
        return m
    elif((op1==op_trace)):
        d1 = [(ty_mat2x2F_d1, ty_scalarF_d1), (ty_mat3x3F_d1, ty_scalarF_d1), (ty_mat4x4F_d1, ty_scalarF_d1)]
        d2 = [(ty_mat2x2F_d2, ty_scalarF_d2), (ty_mat3x3F_d2, ty_scalarF_d2), (ty_mat4x4F_d2, ty_scalarF_d2)]
        d3 = [(ty_mat2x2F_d3, ty_scalarF_d3), (ty_mat3x3F_d3, ty_scalarF_d3), (ty_mat4x4F_d3, ty_scalarF_d3)]
        return d1+d2+d3
    elif((op1==op_det)):
        d1 = [(ty_mat2x2F_d1, ty_scalarF_d1), (ty_mat3x3F_d1, ty_scalarF_d1)]
        d2 = [(ty_mat2x2F_d2, ty_scalarF_d2), (ty_mat3x3F_d2, ty_scalarF_d2)]
        d3 = [(ty_mat2x2F_d3, ty_scalarF_d3), (ty_mat3x3F_d3, ty_scalarF_d3)]
        return d1+d2+d3
    else:
        raise Exception ("op1:"+op1.name)

#given tshape, and arg1, what is arg2 (shape)
def backwards_op2_arg1(op1, tshape, arg1):
    # inner product operation
    #print "op1:",op1.name, "tshape:", tshape.name, "arg1:",arg1.name
    if(op1  == op_inner):
        #(arg1, _) -> tshape
        if(fty.is_ScalarField(tshape)):
            if(fty.is_VectorField(arg1)):
                return arg1.tensorType
            else:
                # no other types
                return None
        else:
            #print "notrightthsape", tshape.name,"-",ty_vec2F_d2.name
            return None
    elif((op1  == op_add) or  (op1  == op_subtract)):
        if(tshape==arg1):
            return arg1.tensorType
        else:
            return None
    else:
        #print "not rightoperator"
        raise Exception ("op1:"+op1.name)

#given tshape, and arg1, what is arg2 (shape)
def backwards_op2_arg2(op1, tshape, arg2):
    # inner product operation
    #print "op1:",op1.name, "tshape:", tshape.name, "arg1:",arg1.name
    if(op1  == op_inner):
        #(arg1, _) -> tshape
        if(fty.is_ScalarField(tshape)):
            if(fty.is_VectorField(arg2)):
                return arg2.tensorType
            else:
                # no other types
                return None
        else:
            #print "notrightthsape", tshape.name,"-",ty_vec2F_d2.name
            return None
    elif((op1  == op_add) or  (op1  == op_subtract)):
        if(tshape==arg2):
            return arg2.tensorType
        else:
            return None
    else:
        #print "not rightoperator"
        raise Exception ("op1:"+op1.name)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0