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 3998 - (download) (as text) (annotate)
Sun Jun 19 17:12:03 2016 UTC (3 years ago) by cchiw
File size: 2462 byte(s)
added modulate, normalize,.. to mkops and testing
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

class operator:
    def __init__(self, id, name, arity, symb, placement):
        self.id=id
        self.name=name
        self.arity=arity
        self.symb=symb
        self.placement=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)

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

id=0
op_probe = operator(id,"probe", 1,"", 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
id=id+11
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]
#:,*,|()|,normalize,transpose,trace..

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
    else:
        return "no match"



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