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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 4236 - (download) (as text) (annotate)
Wed Jul 20 03:02:00 2016 UTC (3 years, 6 months ago) by cchiw
File size: 2735 byte(s)
added generic cases for trace|det and added test cases
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

class operator:
    def __init__(self, id, name, arity, symb, placement):
    def toStr(self):
        self.name, str(arity)
    def get_name(self):
        return self.name
    def isEq_id(a,b):
        return (a.id==b.id)
    def isEq_idNum(a,b):
        return (a.id==b)
    def toStr(self,s):
            return self.name+"("+s+"0"+")"
            return self.name+"("+s+"0,"+s+ "1"+")"

#------------------------------ constants -----------------------------------------------------
#  Constants
# id, name, arity, symbol
#unay operators
place_left = "left"
place_right = "right"
place_middle = "middle"
place_split = "split"
place_special = "-special"

#op_none= operator(id,"none", 1,"", place_left)
op_probe= operator(id,"probe", 1,"", place_left)
#op_sine= operator(id,"none", 1,"sine", place_left)

op_negation = operator(id+1,"neg", 1,"-", place_left)
op_gradient = operator(id+2,"grad", 1, u'∇', place_left)
op_divergence = operator(id+3,"div", 1, u'∇•', place_left)
op_curl= operator(id+4,"curl", 1, u'∇×',place_left)
op_jacob= operator(id+5,"jacob", 1, u'∇⊗', place_left)
op_slice = operator(id+6,"slice", 1, u'[:,0]', place_right)
op_norm = operator(id+6,"norm", 1, u'|', place_split)
op_normalize = operator(id+7,"normalize", 1, u'normalize', place_left)
op_trace = operator(id+8,"trace", 1, u'trace', place_left)
op_transpose = operator(id+9,"transpose", 1, u'transpose', place_left)
op_det = operator(id+10,"det", 1, u'det', place_left)
op_unary = [op_probe, op_negation, op_gradient, op_divergence,
            op_curl, op_jacob, op_norm, op_normalize, op_trace, op_transpose,op_det]
#binary operators
op_add = operator(id,"addition", 2,"+", place_middle)
op_subtract = operator(id+1,"subtraction", 2, "-", place_middle)
op_cross = operator(id+2,"cross product", 2, u'×', place_middle)
op_outer = operator(id+3,"outer product", 2, u'⊗', place_middle)
op_inner = operator(id+4,"inner product", 2, u'•', place_middle)
op_scale = operator(id+5,"multiplication", 2, u'*', place_middle)
op_division = operator(id+6,"division", 2, u'/', place_middle)
op_binary = [op_add, op_subtract, op_cross, op_outer, op_inner, op_scale, op_division]

def idToStr(n):
    for i in  (op_unary+op_binary):
        if (n==i.id):
            return i.name
    return "no match"
def idToStrBinary(n):
    n =n+6
    for i in  (op_binary):
        if (n==i.id):
            return i.name
        return "no match"

ViewVC Help
Powered by ViewVC 1.0.0