Created
November 24, 2017 08:01
-
-
Save fospathi/2ae0ad118d53ca0dc0d93794e5e7cc19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Print the calculation which multiplies two 3x3 matrices. | |
/// | |
/// The matrices store their elements in a flat array in column order. | |
void main() { | |
StringBuffer buffer = new StringBuffer(); | |
String l = "m1"; | |
String r = "m2"; | |
for (int col in new Iterable.generate(3)) { | |
for (int row in new Iterable.generate(3)) { | |
buffer.writeAll([ | |
"$l[${0 + row}]*$r[${col * 3 + 0}]", | |
"$l[${3 + row}]*$r[${col * 3 + 1}]", | |
"$l[${6 + row}]*$r[${col * 3 + 2}]", | |
], " + "); | |
buffer.write(",\n"); | |
} | |
} | |
print(buffer.toString()); | |
} | |
/* | |
m1[0]*m2[0] + m1[3]*m2[1] + m1[6]*m2[2], | |
m1[1]*m2[0] + m1[4]*m2[1] + m1[7]*m2[2], | |
m1[2]*m2[0] + m1[5]*m2[1] + m1[8]*m2[2], | |
m1[0]*m2[3] + m1[3]*m2[4] + m1[6]*m2[5], | |
m1[1]*m2[3] + m1[4]*m2[4] + m1[7]*m2[5], | |
m1[2]*m2[3] + m1[5]*m2[4] + m1[8]*m2[5], | |
m1[0]*m2[6] + m1[3]*m2[7] + m1[6]*m2[8], | |
m1[1]*m2[6] + m1[4]*m2[7] + m1[7]*m2[8], | |
m1[2]*m2[6] + m1[5]*m2[7] + m1[8]*m2[8], | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment