@@ -135,20 +135,22 @@ public
135135 end match;
136136 end invert;
137137
138+ type TypeRestriction = enumeration(SCALAR , VECTOR , MATRIX , ARRAY , OTHER );
139+
138140 function typeRestriction
139141 input Type ty;
140- output Integer i ;
142+ output TypeRestriction restriction ;
141143 algorithm
142144 if Type . isScalar(ty) then
143- i := 0 ;
145+ restriction := TypeRestriction . SCALAR ;
144146 elseif Type . isVector(ty) then
145- i := 1 ;
147+ restriction := TypeRestriction . VECTOR ;
146148 elseif Type . isMatrix(ty) then
147- i := 2 ;
149+ restriction := TypeRestriction . MATRIX ;
148150 elseif Type . isArray(ty) then
149- i := 3 ;
151+ restriction := TypeRestriction . ARRAY ;
150152 else
151- i := 4 ;
153+ restriction := TypeRestriction . OTHER ;
152154 end if ;
153155 end typeRestriction;
154156
@@ -158,25 +160,25 @@ public
158160 protected
159161 MathClassification mc = getMathClassification(operator);
160162 SizeClassification sc;
161- list< tuple< Integer , Type >> lst;
162- tuple< Integer , Type > min_, max_;
163+ list< tuple< TypeRestriction , Type >> lst;
164+ tuple< TypeRestriction , Type > min_, max_;
163165 Type ty;
164166 function tplLt
165- input tuple< Integer , Type > tpl1;
166- input tuple< Integer , Type > tpl2;
167+ input tuple< TypeRestriction , Type > tpl1;
168+ input tuple< TypeRestriction , Type > tpl2;
167169 output Boolean b = Util . tuple21(tpl1) < Util . tuple21(tpl2);
168170 end tplLt;
169171 algorithm
170172 lst := list((typeRestriction(t), t) for t in types);
171173 min_ := List . minElement(lst, tplLt);
172174 max_ := List . maxElement(lst, tplLt);
173175 (sc, ty) := match (min_, max_)
174- case ((0 , _), (0 , ty)) then (SizeClassification . SCALAR , ty);
175- case ((0 , _), (_ ,ty)) then (SizeClassification . SCALAR_ARRAY , ty);
176- case ((1 , _), (1 , ty)) then (SizeClassification . ELEMENT_WISE , ty);
177- case ((1 , _), (2 , ty)) then (SizeClassification . VECTOR_MATRIX , ty);
178- case ((2 , _), (2 , ty)) then (SizeClassification . ELEMENT_WISE , ty);
179- case ((3 , _), (3 , ty)) then (SizeClassification . ELEMENT_WISE , ty);
176+ case ((TypeRestriction . SCALAR , _), (TypeRestriction . SCALAR , ty)) then (SizeClassification . SCALAR , ty);
177+ case ((TypeRestriction . SCALAR , _), (_ ,ty)) then (SizeClassification . SCALAR_ARRAY , ty);
178+ case ((TypeRestriction . VECTOR , _), (TypeRestriction . VECTOR , ty)) then (SizeClassification . ELEMENT_WISE , ty);
179+ case ((TypeRestriction . VECTOR , _), (TypeRestriction . MATRIX , ty)) then (SizeClassification . VECTOR_MATRIX , ty);
180+ case ((TypeRestriction . MATRIX , _), (TypeRestriction . MATRIX , ty)) then (SizeClassification . ELEMENT_WISE , ty);
181+ case ((TypeRestriction . ARRAY , _), (TypeRestriction . ARRAY , ty)) then (SizeClassification . ELEMENT_WISE , ty);
180182 else algorithm
181183 Error . assertion(false , getInstanceName() + " failed because the multary arguments have incompatible sizes: "
182184 + List . toString(types, Type . toString), sourceInfo());
@@ -196,13 +198,13 @@ public
196198 algorithm
197199 (sc, ty) := match (typeRestriction(ty1), typeRestriction(ty2))
198200 local
199- Integer i1, i2 ;
200- case (0 , 0 ) then (SizeClassification . SCALAR , ty1);
201- case (0 , i2 ) guard(i2 > 0 ) then (SizeClassification . SCALAR_ARRAY , ty2);
202- case (i1, 0 ) guard(i1 > 0 ) then (SizeClassification . ARRAY_SCALAR , ty1);
203- case (1 , 2 ) then (SizeClassification . VECTOR_MATRIX , ty1);
204- case (2 , 1 ) then (SizeClassification . MATRIX_VECTOR , ty2);
205- case (i1, i2 ) guard(i1 == i2) then (getSizeClassification(operator), ty1);
201+ TypeRestriction r1, r2 ;
202+ case (TypeRestriction . SCALAR , TypeRestriction . SCALAR ) then (SizeClassification . SCALAR , ty1);
203+ case (TypeRestriction . SCALAR , r2 ) guard(r2 > TypeRestriction . SCALAR ) then (SizeClassification . SCALAR_ARRAY , ty2);
204+ case (r1, TypeRestriction . SCALAR ) guard(r1 > TypeRestriction . SCALAR ) then (SizeClassification . ARRAY_SCALAR , ty1);
205+ case (TypeRestriction . VECTOR , TypeRestriction . MATRIX ) then (SizeClassification . VECTOR_MATRIX , ty1);
206+ case (TypeRestriction . MATRIX , TypeRestriction . VECTOR ) then (SizeClassification . MATRIX_VECTOR , ty2);
207+ case (r1, r2 ) guard(r1 == r2) then (getSizeClassification(operator), ty1);
206208 else algorithm
207209 Error . assertion(false , getInstanceName() + " failed because the binary arguments have incompatible sizes: "
208210 + Type . toString(ty1) + ", " + Type . toString(ty2), sourceInfo());
@@ -216,10 +218,10 @@ public
216218 output Boolean b;
217219 algorithm
218220 b := match operator. op
219- case Op . AND then true ;
220- case Op . OR then true ;
221- case Op . NOT then true ;
222- else false ;
221+ case Op . AND then true ;
222+ case Op . OR then true ;
223+ case Op . NOT then true ;
224+ else false ;
223225 end match;
224226 end isLogical;
225227
@@ -987,16 +989,15 @@ public
987989 input MathClassification mcl2;
988990 output Boolean b;
989991 algorithm
990- b := (Util . intCompare(Integer (mcl1), Integer (mcl2)) == 0 )
991- or (isDashClassification(mcl1) and isDashClassification(mcl2));
992+ b := mcl1 == mcl2 or (isDashClassification(mcl1) and isDashClassification(mcl2));
992993 end isCombineableMath;
993994
994995 function isCombineableSize
995996 input SizeClassification scl1;
996997 input SizeClassification scl2;
997998 output Boolean b;
998999 algorithm
999- b := ( Util . intCompare( Integer ( scl1), Integer (scl2)) == 0 ) ;
1000+ b := scl1 == scl2 ;
10001001 end isCombineableSize;
10011002
10021003 function toDebugString
0 commit comments