Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:52

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 
0023 * https://stackoverflow.com/questions/5181320/under-what-circumstances-are-rmul-called
0024 
0025 
0026 (mul) a * b 
0027 (rmul) c * 2 
0028 (rmul) d * 6 
0029 (rmul) e * 24 
0030 120
0031 
0032 
0033 * https://jameshensman.wordpress.com/2010/06/14/multiple-matrix-multiplication-in-numpy/
0034 * http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
0035 
0036 
0037 
0038 
0039 
0040 """
0041 
0042 from operator import mul
0043 from functools import reduce
0044 
0045 class A(object):
0046 
0047    @classmethod
0048    def prod(cls, a, b):
0049        return a * b 
0050    
0051    def __init__(self, name, val):
0052        self.name = name
0053        self.val = val
0054    def __repr__(self):
0055        return self.name
0056 
0057    def __mul__(self, other):
0058        print("(mul) %r * %r " % (self, other))
0059        return self.val * other.val 
0060 
0061    def __rmul__(self, other):
0062        print("(rmul) %r * %r " % (self, other))
0063        return self.val * other
0064 
0065 
0066 
0067 
0068 
0069 if __name__ == '__main__':
0070 
0071 
0072    a = A("a",1) 
0073    b = A("b",2) 
0074    c = A("c",3) 
0075    d = A("d",4) 
0076    e = A("e",5) 
0077 
0078 
0079    res = reduce(mul, [a,b,c,d,e] )
0080 
0081    print(res) 
0082 
0083 
0084