Changeset 150
- Timestamp:
- 11/29/07 03:11:11 (4 years ago)
- Files:
-
- trunk/blade/BladeDemo.d (modified) (1 diff)
- trunk/blade/BladeRank.d (modified) (8 diffs)
- trunk/blade/BladeSimplify.d (modified) (1 diff)
- trunk/blade/BladeUtil.d (modified) (2 diffs)
- trunk/blade/SyntaxTree.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/blade/BladeDemo.d
r148 r150 34 34 //mixin(vectorize("dot(q,q*dot(q,q))")); 35 35 // should simplify to: dot(q.q) * dot(q,q) 36 /*36 37 37 mixin(vectorize(` a += (d[2..$-1]*2.01*a[2]-another[][1])["abc".length-3..$]`)); 38 38 39 39 mixin(vectorize(" a-= 2.01*( 3.04+k)*r")); 40 40 mixin(vectorize("q+= q*2.01")); 41 */ 42 // mixin(vectorize("a+=d[2,[1,$]]")); 41 42 // This parses OK, but isn't get supported at the codegen step. 43 // mixin(vectorize("a+=another[1,[1,$]]")); 43 44 writefln("a=", a); 44 45 } trunk/blade/BladeRank.d
r148 r150 1 1 // Written in the D programming language 1.0 2 // Part of BLADE : Basic Linear Algebra D Expressions 2 3 /** 3 * Part of BLADE : Basic Linear Algebra D Expressions4 * Determine the tensor rank of an expression. 4 5 * 5 6 */ … … 100 101 RankMismatch = -8, 101 102 RankMismatchConcatenation = -9, 102 RankMismatchDotProduct = -10 103 RankMismatchDotProduct = -10, 104 ExtraCharsAfterArrayLiteral = -11, 105 ArrayLiteralRankMismatch = -12 103 106 } 104 107 … … 114 117 "Dimensionality mismatch (addition or subtraction)", 115 118 "Dimensionality mismatch in concatenation", 116 "Dimenionality error in dot product"][-err-1]; 119 "Dimenionality error in dot product" 120 "Extra characters after array literal" 121 "Rank mismatch in array literal" 122 ][-err-1]; 117 123 } 118 124 … … 153 159 // Deal with unary operators 154 160 if (expr[0]=='+' || expr[0]=='-') return subexprRank(expr[1..$], rank); 155 // if (expr[0]=='~' || expr[0]=='*') { return 0; }156 161 157 162 int x = exprLength(expr); 163 if (expr[0]=='[') { // array literal 164 if (x!=expr.length-1) return RankError.ExtraCharsAfterArrayLiteral; 165 expr = expr[1..$-1]; 166 x = exprLength(expr); 167 int lrank = subexprRank(expr[0..x+1], rank); 168 while (x<expr.length-1) { 169 if (expr[x+1]!=',') return RankError.CommaExpected; 170 expr = expr[x+2.. $]; 171 x = exprLength(expr); 172 int rrank = subexprRank(expr[0..x+1], rank); 173 if (lrank!=rrank) return RankError.ArrayLiteralRankMismatch; 174 } 175 return lrank+1; 176 } 158 177 int y = x+1; 159 178 // Deal with shifts, op=, and NCEG operators … … 163 182 char [] left = expr[0..x+1]; 164 183 char [] right = expr[y+1..$]; 165 if (expr[0]=='[') { // array literal166 assert(0, expr);167 }168 184 if (expr[x+1]=='[') right = expr[y+1..$-1]; // drop off the ']'. 169 185 int lrank = subexprRank(left, rank); … … 185 201 // allow rank of 1 to be a slice operation 186 202 // (so A[1,[2,$-1], $] is possible). 203 // if (z>1) assert(0, right[0..z+1]); 187 204 int rrank = subexprRank(right[0..z+1], rank); 188 205 if (rrank<0) return rrank; 189 206 if (rrank>1) return RankError.NonScalarIndex; 190 207 if (rrank==0) --totrank; 191 if (rrank==1) assert(0, right); 192 208 193 209 if (z==right.length-1) return totrank; 194 210 right = right[z+2..$]; … … 239 255 240 256 unittest { 241 // assert(exprRank("A[B,[B,C],B]", "600")==4);242 // const y = exprRank("A+=(B[C,$])", "1100");243 257 assert(exprRank("A+((((++B)+D)--)*C)", "1010")==1); 244 258 assert(exprRank("A+(B*C)", "000")==0); … … 255 269 assert(exprRank("d(A)", "1")==RankError.CommaExpected); 256 270 assert(exprRank("d(A,B)", "10")==RankError.RankMismatchDotProduct); 257 assert(exprRank("d(B,(A*(d(B,B))))", "11")==0); 258 259 assert(exprRank("A[B,B,B]", "6034")==3); 260 } 261 262 // Return true if the entire expression contains a multiplucation by a scalar 271 assert(exprRank("d(B,(A*(d(B,B))))", "11")==0); 272 assert(exprRank("A[B,B,B]", "60")==3); 273 assert(exprRank("A[B,B,C,B]", "600")==2); 274 assert(exprRank("A[B,([B,C]),B]", "600")==4); 275 assert(exprRank("A[B,(([B,C])[B]),B]", "600")==3); 276 assert(exprRank("A+=(B[C..$])", "110")==1); 277 } 278 279 // Return true if the entire expression contains a multiplication by a scalar 263 280 bool hasScalarMultiply(char [] expr, char [] rank) 264 281 { trunk/blade/BladeSimplify.d
r148 r150 61 61 else { 62 62 char [] expr2 = removeDuplicates(tree); 63 assert(0, ranks);64 63 // Check for rank errors 65 64 int wholerank = exprRank(expr2, ranks); trunk/blade/BladeUtil.d
r145 r150 1 1 // Written in the D programming language 1.0 2 2 /** 3 * General CTFE string utilityfunctions3 * General CTFE functions 4 4 * BLADE 0.3Alpha -- Basic Linear Algebra D Expressions 5 5 */ … … 42 42 for(int i=0; i<instr.length; ++i) { 43 43 if (instr[i]=='"' || instr[i]=='\\') { 44 char [] str =instr[0..i] ~ escape;44 char [] str = instr[0..i] ~ escape; 45 45 int m = i; 46 46 foreach(int k, char c; instr[i+1..$]) { trunk/blade/SyntaxTree.d
r149 r150 344 344 // ==== SEMANTIC PASS ==== 345 345 346 // Returns typeof(sym).stringof , with workarounds for compiler bugs346 // Returns typeof(sym).stringof. 347 347 char [] mixin_typeOf(char [] sym) 348 348 { 349 // typeof(x).stringof doesn't compile if x is a function. 350 // If it doesn't compile at all, return an empty string. 349 // If sym is a function, we take its address, since 350 // typeof(x).stringof doesn't compile if x is a function. 351 // If sym doesn't compile at all, return an empty string. 351 352 return `mixin(!is(typeof(` ~ sym ~ `))?"\"\"" : is(typeof(` ~ sym ~ `)==function)?"` ~ enquote("typeof(&" ~ sym ~ ").stringof")~`":"` ~ enquote("typeof(" ~ sym ~ ").stringof") ~ `")`; 352 353 }
