@@ -49,38 +49,38 @@ def __init__(self, *args, shape: tuple = None): # pylint: disable=unused-argumen
49
49
50
50
def __add__ (self , other ):
51
51
if type (self ) == type (other ):
52
- (elems , _ ) = matadd (self .get_field_values (), self ._shape ,
52
+ (elems , _ ) = mat_add (self .get_field_values (), self ._shape ,
53
53
other .get_field_values (), other ._shape )
54
54
return type (self )(* elems )
55
55
else :
56
56
raise TypeError
57
57
58
58
def __sub__ (self , other ):
59
59
if type (self ) == type (other ):
60
- (elems , _ ) = matsub (self .get_field_values (), self ._shape ,
60
+ (elems , _ ) = mat_sub (self .get_field_values (), self ._shape ,
61
61
other .get_field_values (), other ._shape )
62
62
return type (self )(* elems )
63
63
64
64
raise TypeError
65
65
66
66
def __mul__ (self , other ):
67
67
if isinstance (other , (float , int )):
68
- (elems , _ ) = compmul (self .get_field_values (), self ._shape , other )
68
+ (elems , _ ) = comp_mul (self .get_field_values (), self ._shape , other )
69
69
return type (self )(* elems )
70
70
71
71
# All other cases should already have been handled in instance classes
72
72
raise TypeError
73
73
74
74
def __rmul__ (self , other ):
75
75
if isinstance (other , (float , int )):
76
- (elems , _ ) = compmul (self .get_field_values (), self ._shape , other )
76
+ (elems , _ ) = comp_mul (self .get_field_values (), self ._shape , other )
77
77
return type (self )(* elems )
78
78
79
79
raise TypeError
80
80
81
81
def __truediv__ (self , other ):
82
82
if isinstance (other , (float , int )):
83
- (elems , _ ) = compdiv (self .get_field_values (), self ._shape , other )
83
+ (elems , _ ) = comp_div (self .get_field_values (), self ._shape , other )
84
84
return type (self )(* elems )
85
85
86
86
raise TypeError
@@ -162,19 +162,21 @@ def tr(self): # pylint: disable=invalid-name
162
162
class MixinVector (MixinAlgebra ):
163
163
"""Mixin providing additional functionalty for vectors based on typing.NamedTuple."""
164
164
def __mul__ (self , other ):
165
- if isinstance (self , MixinVector ) and isinstance (other , MixinVector ) and \
166
- self ._shape [0 ] < other ._shape [0 ]:
167
- # Calc scalar product
168
- (elems , _ ) = matmul (self .get_field_values (), self ._shape ,
169
- other .get_field_values (), other ._shape )
165
+ if isinstance (self , MixinVector ) and isinstance (other , MixinVector ):
166
+ if self ._shape [0 ] > other ._shape [0 ]:
167
+ raise ShapeMissmatchException
168
+ else :
169
+ # Calc scalar product
170
+ (elems , _ ) = matmul (self .get_field_values (), self ._shape ,
171
+ other .get_field_values (), other ._shape )
170
172
return elems [0 ]
171
173
172
174
# Fallback to MixinAlgebra __mul__
173
175
return super ().__mul__ (other )
174
176
175
177
def __floordiv__ (self , other ):
176
178
if isinstance (other , (float , int )):
177
- (elems , _ ) = compfloor (self .get_field_values (), self ._shape , other )
179
+ (elems , _ ) = comp_floor (self .get_field_values (), self ._shape , other )
178
180
return type (self )(elems , shape = self ._shape )
179
181
180
182
return ValueError
@@ -439,7 +441,7 @@ def unpack_nested_iterable_to_list(it_er: Iterable):
439
441
it_er = list (chain .from_iterable (it_er ))
440
442
return it_er
441
443
442
- def compmul (mat_0 : list , shape_0 : tuple , factor : float ):
444
+ def comp_mul (mat_0 : list , shape_0 : tuple , factor : float ):
443
445
"""Performing componentwise multiplication with factor c."""
444
446
(rows_0 , cols_0 ) = shape_0
445
447
@@ -450,7 +452,7 @@ def compmul(mat_0: list, shape_0: tuple, factor: float):
450
452
# Return coefficients and shape tuple
451
453
return [e * factor for e in mat_0 ], shape_0
452
454
453
- def compdiv (mat_0 : list , shape_0 : tuple , divisor : float ):
455
+ def comp_div (mat_0 : list , shape_0 : tuple , divisor : float ):
454
456
"""Performing componentwise real division by divisor."""
455
457
(rows_0 , cols_0 ) = shape_0
456
458
@@ -461,7 +463,7 @@ def compdiv(mat_0: list, shape_0: tuple, divisor: float):
461
463
# Return coefficients and shape tuple
462
464
return [e / divisor for e in mat_0 ], shape_0
463
465
464
- def compfloor (mat_0 : list , shape_0 : tuple , divisor : float ):
466
+ def comp_floor (mat_0 : list , shape_0 : tuple , divisor : float ):
465
467
"""Performing componentwise floor division."""
466
468
(rows_0 , cols_0 ) = shape_0
467
469
@@ -477,7 +479,7 @@ def vect_norm(all_elems: list):
477
479
squared = [elem ** 2 for elem in all_elems ]
478
480
return sqrt (reduce (operator .add , squared ))
479
481
480
- def matadd (mat_0 : list , shape_0 : tuple , mat_1 : list , shape_1 : tuple ):
482
+ def mat_add (mat_0 : list , shape_0 : tuple , mat_1 : list , shape_1 : tuple ):
481
483
"""Performing componentwise addition."""
482
484
(rows_0 , cols_0 ) = shape_0
483
485
(rows_1 , cols_1 ) = shape_1
@@ -491,10 +493,10 @@ def matadd(mat_0: list, shape_0: tuple, mat_1: list, shape_1: tuple):
491
493
# Return coefficients and shape tuple
492
494
return map (operator .add , mat_0 , mat_1 ), shape_0
493
495
494
- def matsub (mat_0 : list , shape_0 : tuple , mat_1 : list , shape_1 : tuple ):
496
+ def mat_sub (mat_0 : list , shape_0 : tuple , mat_1 : list , shape_1 : tuple ):
495
497
"""Performing componentwise substraction."""
496
498
mat_1 = [e * - 1 for e in mat_1 ]
497
- return matadd (mat_0 , shape_0 , mat_1 , shape_1 )
499
+ return mat_add (mat_0 , shape_0 , mat_1 , shape_1 )
498
500
499
501
def is_row_vect (shape : tuple ):
500
502
"""Returning true if vector shape is row space e.g. shape = (1,4)"""
0 commit comments