From 497eecd9a83eae3aaace16783d07d9a6a9e961ca Mon Sep 17 00:00:00 2001 From: glyh Date: Fri, 8 Nov 2024 10:50:44 +0800 Subject: [PATCH] refactor external --- src/bin/main.mbt | 1 - src/{bin => closureps_eval}/externals.mbt | 6 +- src/closureps_eval/interpreter.mbt | 1 + src/closureps_eval/moon.pkg.json | 3 +- src/{externals.mbt => externals_header.mbt} | 0 test/source_generator/matmul.py | 30 ++-- test/source_generator/matmul_int.py | 177 ++++++++++++++++++++ test/test_src/matmul_gen.ans | 42 +++-- test/test_src/matmul_gen.mbt | 47 +++--- test/test_src/matmul_gen_int.ans | 70 ++++++++ test/test_src/matmul_gen_int.mbt | 126 ++++++++++++++ 11 files changed, 456 insertions(+), 47 deletions(-) rename src/{bin => closureps_eval}/externals.mbt (91%) rename src/{externals.mbt => externals_header.mbt} (100%) create mode 100755 test/source_generator/matmul_int.py create mode 100644 test/test_src/matmul_gen_int.ans create mode 100644 test/test_src/matmul_gen_int.mbt diff --git a/src/bin/main.mbt b/src/bin/main.mbt index f24198a..ff84ee0 100644 --- a/src/bin/main.mbt +++ b/src/bin/main.mbt @@ -304,7 +304,6 @@ fn main { if closureps_interpreter.val { let clops = status.clops.unwrap() let interpreter = @closureps_eval.CloPSInterpreter::new(clops) - add_clops_interp_fns(interpreter) try { interpreter.eval!(clops.root) } catch { diff --git a/src/bin/externals.mbt b/src/closureps_eval/externals.mbt similarity index 91% rename from src/bin/externals.mbt rename to src/closureps_eval/externals.mbt index 7e7f573..649c787 100644 --- a/src/bin/externals.mbt +++ b/src/closureps_eval/externals.mbt @@ -1,4 +1,4 @@ -fn add_clops_interp_fns(interpreter : @closureps_eval.CloPSInterpreter) -> Unit { +fn CloPSInterpreter::init_extern_fns(interpreter : CloPSInterpreter) -> Unit { interpreter.add_extern_fn( "print_char", fn(args) { @@ -29,9 +29,9 @@ fn add_clops_interp_fns(interpreter : @closureps_eval.CloPSInterpreter) -> Unit }, 0, ) - let create_array = fn(args : Array[@closureps_eval.Value]) { + let create_array = fn(args : Array[Value]) { match args[0] { - Int(n) => @closureps_eval.Value::Array(Array::make(n, args[1])) + Int(n) => Value::Array(Array::make(n, args[1])) _ => @util.die("create_array expects Int") } } diff --git a/src/closureps_eval/interpreter.mbt b/src/closureps_eval/interpreter.mbt index ce9fe2b..94d4a02 100644 --- a/src/closureps_eval/interpreter.mbt +++ b/src/closureps_eval/interpreter.mbt @@ -56,6 +56,7 @@ fn CloPSInterpreter::reset_env(self : CloPSInterpreter) -> Unit { pub fn CloPSInterpreter::new(clops : @closureps.ClosurePS) -> CloPSInterpreter { let ret = { extern_fns: Map::new(), clops, cur_env: @hashmap.new() } ret.reset_env() + ret.init_extern_fns() ret } diff --git a/src/closureps_eval/moon.pkg.json b/src/closureps_eval/moon.pkg.json index 2464606..476d487 100644 --- a/src/closureps_eval/moon.pkg.json +++ b/src/closureps_eval/moon.pkg.json @@ -7,7 +7,8 @@ "path": "moonbitlang/minimbt", "alias": "types" }, - "moonbitlang/minimbt/util" + "moonbitlang/minimbt/util", + "lijunchen/unstable_io/io" ], "test-import": [ "moonbitlang/minimbt/parser", diff --git a/src/externals.mbt b/src/externals_header.mbt similarity index 100% rename from src/externals.mbt rename to src/externals_header.mbt diff --git a/test/source_generator/matmul.py b/test/source_generator/matmul.py index 4608bc4..2b92fc1 100755 --- a/test/source_generator/matmul.py +++ b/test/source_generator/matmul.py @@ -5,7 +5,7 @@ [l, n, m] = [10, 10, 10] -def generate_mat(m: int, n: int, min_value: float = -10.0, max_value: float = 10.0) -> List[List[float]]: +def generate_mat(m: int, n: int, min_value: float = 0.0, max_value: float = 10.0) -> List[List[float]]: """ Generates an m x n matrix filled with random floating-point numbers. @@ -48,8 +48,12 @@ def format_mat(symbol: str, m: int, n: int, mat: List[List[float]]) -> str: operate_mat += "\n" + indent_str + f"let _ = matmul({l},{n},{m},a,b,c);" -operate_mat += "\n" + indent_str + f"matshow({l}, {m}, c)" - +operate_mat += "\n" + indent_str + f"let _ = matshow({l}, {n}, a);" +operate_mat += "\n" + indent_str + f"let _ = print_endline();" +operate_mat += "\n" + indent_str + f"let _ = matshow({n}, {m}, b);" +operate_mat += "\n" + indent_str + f"let _ = print_endline();" +operate_mat += "\n" + indent_str + f"let _ = matshow({l}, {m}, c);" +operate_mat += "\n" + indent_str + f"()" operate_mat += "\n" generated = """ @@ -150,17 +154,21 @@ def matrix_multiply(matrix_a, matrix_b): return result -def float_to_ieee754(float_value): - import struct - # Pack the float as a binary string (double precision) - packed = struct.pack('>d', float_value) # '>d' means big-endian double - # Convert the packed binary string to an integer representation - integer_representation = int.from_bytes(packed, byteorder='big') - return integer_representation - mat_c = matrix_multiply(mat_a, mat_b) with open(ans_path, 'w') as ans_file: + for row in mat_a: + for ele in row: + ans_file.write(f'{int(ele)} ') + ans_file.write('\n') + ans_file.write('\n') + + for row in mat_b: + for ele in row: + ans_file.write(f'{int(ele)} ') + ans_file.write('\n') + ans_file.write('\n') + for row in mat_c: for ele in row: ans_file.write(f'{int(ele)} ') diff --git a/test/source_generator/matmul_int.py b/test/source_generator/matmul_int.py new file mode 100755 index 0000000..e2d881b --- /dev/null +++ b/test/source_generator/matmul_int.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python +# Multiply a n by m matrix and a m by k matrix +import random +from typing import List + +[l, n, m] = [18, 15, 16] + +def generate_mat(m: int, n: int, min_value: int = -8, max_value: int = 8) -> List[List[int]]: + """ + Generates an m x n matrix filled with random floating-point numbers. + + :param m: Number of rows + :param n: Number of columns + :param min_value: Minimum value for random floats (inclusive) + :param max_value: Maximum value for random floats (inclusive) + :return: m x n matrix with random floating-point numbers + """ + return [[random.randint(min_value, max_value) for _ in range(n)] for _ in range(m)] + + +indent = 2 +indent_str = " " * indent + +def format_mat(symbol: str, m: int, n: int, mat: List[List[int]]) -> str: + ret = "" + for row in range(m): + for col in range(n): + ret += indent_str if col == 0 else "; " + ret += f"{symbol}[{row}][{col}] = {mat[row][col]}" + ret += ";\n" + + return ret + + +operate_mat = \ +f""" + let a = gen_arr({l}, {n}); + let b = gen_arr({n}, {m}); + let c = gen_arr({l}, {m}); +""" + +mat_a = generate_mat(l, n) +operate_mat += "\n" + format_mat("a", l, n, mat_a) + +mat_b = generate_mat(n, m) +operate_mat += "\n" + format_mat("b", n, m, mat_b) + +operate_mat += "\n" + indent_str + f"let _ = matmul({l},{n},{m},a,b,c);" + + +operate_mat += "\n" + indent_str + f"let _ = matshow({l}, {n}, a);" +operate_mat += "\n" + indent_str + f"let _ = print_endline();" +operate_mat += "\n" + indent_str + f"let _ = matshow({n}, {m}, b);" +operate_mat += "\n" + indent_str + f"let _ = print_endline();" +operate_mat += "\n" + indent_str + f"let _ = matshow({l}, {m}, c);" +operate_mat += "\n" + indent_str + f"()" +operate_mat += "\n" + +generated = """ +fn matshow(m: Int, n: Int, mat: Array[Array[Int]]) -> Unit { + fn loop1(i: Int) -> Unit { + if i <= m - 1 { + fn loop2(j: Int) -> Unit { + if j <= n - 1 { + let _ = print_int(mat[i][j]); + let _ = print_char(32); + loop2(j+1) + } else { + print_endline() + } + }; + let _ = loop2(0); + loop1(i+1) + } else { + () + } + }; + loop1(0) +}; + +fn matmul(l: Int, m: Int, n: Int, a: Array[Array[Int]], b: Array[Array[Int]], c: Array[Array[Int]]) -> Unit { + fn loop1(i: Int) -> Unit { + if 0 <= i { + fn loop2(j: Int) -> Unit { + if 0 <= j { + fn loop3(k: Int) -> Unit { + if 0 <= k { + c[i][j] = c[i][j] + a[i][k] * b[k][j]; + loop3(k - 1) + } else { + () + } + }; + let _ = loop3(m - 1); + loop2(j - 1) + } else { + () + } + }; + let _ = loop2(n - 1); + loop1(i - 1) + } else { + () + } + }; + loop1(l - 1) +}; + +fn main { + let dummy = Array::make(0, 0); + fn gen_arr(m: Int, n: Int) -> Array[Array[Int]] { + let mat = Array::make(m, dummy); + fn init_arr(i: Int) -> Unit { + if 0 <= i { + mat[i] = Array::make(n, 0); + init_arr(i - 1) + } else { + () + } + }; + let _ = init_arr(m - 1); + mat + }; +""" \ + + operate_mat + \ +""" +};""" + +source_path = "../test_src/matmul_gen_int.mbt" +ans_path = "../test_src/matmul_gen_int.ans" + +with open(source_path, 'w') as source_file: + source_file.write(generated) + +def matrix_multiply(matrix_a, matrix_b): + # Get the dimensions of the matrices + rows_a = len(matrix_a) + cols_a = len(matrix_a[0]) + rows_b = len(matrix_b) + cols_b = len(matrix_b[0]) + + # Check if multiplication is possible + if cols_a != rows_b: + raise ValueError("Cannot multiply: The number of columns in matrix A must equal the number of rows in matrix B.") + + # Initialize the result matrix with zeros + result = [[0 for _ in range(cols_b)] for _ in range(rows_a)] + + # Perform multiplication + for i in range(rows_a): + for j in range(cols_b): + for k in range(cols_a): + result[i][j] += matrix_a[i][k] * matrix_b[k][j] + + return result + +mat_c = matrix_multiply(mat_a, mat_b) + +with open(ans_path, 'w') as ans_file: + for row in mat_a: + for ele in row: + ans_file.write(f'{int(ele)} ') + ans_file.write('\n') + ans_file.write('\n') + + for row in mat_b: + for ele in row: + ans_file.write(f'{int(ele)} ') + ans_file.write('\n') + ans_file.write('\n') + + for row in mat_c: + for ele in row: + ans_file.write(f'{int(ele)} ') + ans_file.write('\n') + + diff --git a/test/test_src/matmul_gen.ans b/test/test_src/matmul_gen.ans index 25eff84..e2bc001 100644 --- a/test/test_src/matmul_gen.ans +++ b/test/test_src/matmul_gen.ans @@ -1,10 +1,32 @@ --67 24 124 106 -53 -82 -114 82 -165 15 --30 -93 -94 -36 -44 23 -56 58 -15 29 --85 -91 171 67 132 5 22 116 -112 12 -152 4 -76 29 -39 -40 -139 -28 -75 25 --49 137 208 21 72 46 28 -1 -39 -2 -104 -9 -213 41 -71 -39 -22 -181 67 34 -45 122 -27 -54 -18 -15 102 101 -86 -141 --145 8 -90 -46 -180 -57 190 48 71 -47 -117 -184 -129 -50 179 83 47 -42 40 42 --38 -99 57 140 124 88 -91 35 57 153 +6 7 7 6 5 6 8 8 2 4 +8 2 5 2 9 6 0 2 5 9 +2 7 8 8 3 9 7 2 3 2 +1 1 9 6 3 4 4 7 6 9 +8 3 2 9 6 9 2 2 7 6 +8 6 5 6 1 2 9 0 2 9 +3 1 4 7 1 2 1 7 9 0 +9 9 2 2 2 1 9 0 3 5 +7 9 2 4 5 1 7 10 7 7 +1 8 4 9 7 6 5 7 2 3 + +2 7 1 7 3 5 9 8 7 8 +8 4 4 1 3 9 6 5 9 2 +5 1 5 5 8 4 0 3 3 2 +6 6 5 8 8 8 9 0 0 3 +2 1 6 8 2 4 7 2 8 0 +2 4 5 0 4 8 9 1 2 2 +8 3 0 9 4 1 2 1 2 5 +9 5 8 1 7 3 4 7 7 3 +9 0 1 1 1 6 8 1 1 6 +4 5 7 9 2 2 5 9 8 8 + +391 277 307 340 327 348 380 281 342 255 +264 222 274 311 217 296 370 262 319 250 +335 227 250 286 288 343 350 188 239 200 +354 210 291 302 282 277 311 226 254 233 +312 258 264 323 254 366 451 235 280 269 +317 247 207 351 241 281 329 253 277 277 +289 156 180 173 207 243 281 144 160 177 +295 220 168 284 193 267 306 240 283 248 +430 279 288 332 281 338 399 319 379 300 +365 247 301 300 297 340 371 225 294 197 diff --git a/test/test_src/matmul_gen.mbt b/test/test_src/matmul_gen.mbt index 2563952..3d25dc2 100644 --- a/test/test_src/matmul_gen.mbt +++ b/test/test_src/matmul_gen.mbt @@ -68,29 +68,34 @@ fn main { let b = gen_arr(10, 10); let c = gen_arr(10, 10); - a[0][0] = 5.71; a[0][1] = 2.99; a[0][2] = 1.27; a[0][3] = -1.2; a[0][4] = 3.85; a[0][5] = -2.38; a[0][6] = 7.07; a[0][7] = -3.66; a[0][8] = -0.77; a[0][9] = 7.66; - a[1][0] = -7.72; a[1][1] = -3.64; a[1][2] = -4.7; a[1][3] = 0.96; a[1][4] = -3.05; a[1][5] = -5.44; a[1][6] = 5.15; a[1][7] = -9.01; a[1][8] = -0.81; a[1][9] = 1.0; - a[2][0] = 6.42; a[2][1] = 3.88; a[2][2] = 1.39; a[2][3] = -6.05; a[2][4] = -0.51; a[2][5] = 5.65; a[2][6] = 7.8; a[2][7] = 5.27; a[2][8] = -0.85; a[2][9] = 2.36; - a[3][0] = -3.69; a[3][1] = -6.34; a[3][2] = -1.18; a[3][3] = 0.18; a[3][4] = 6.54; a[3][5] = 3.33; a[3][6] = -3.95; a[3][7] = -5.8; a[3][8] = 2.27; a[3][9] = 1.84; - a[4][0] = 6.37; a[4][1] = 5.16; a[4][2] = 9.95; a[4][3] = 4.57; a[4][4] = 3.51; a[4][5] = 6.27; a[4][6] = 3.89; a[4][7] = 9.66; a[4][8] = 0.43; a[4][9] = -2.1; - a[5][0] = -2.21; a[5][1] = -8.26; a[5][2] = -7.76; a[5][3] = -3.47; a[5][4] = 9.23; a[5][5] = -3.59; a[5][6] = -4.49; a[5][7] = -1.02; a[5][8] = -0.53; a[5][9] = -6.34; - a[6][0] = 8.49; a[6][1] = 8.29; a[6][2] = 3.39; a[6][3] = -6.45; a[6][4] = -4.2; a[6][5] = 9.37; a[6][6] = -7.88; a[6][7] = -3.89; a[6][8] = 3.7; a[6][9] = -8.51; - a[7][0] = -1.3; a[7][1] = 9.36; a[7][2] = -7.58; a[7][3] = -2.48; a[7][4] = -5.52; a[7][5] = -6.25; a[7][6] = 0.95; a[7][7] = -5.38; a[7][8] = -6.98; a[7][9] = -1.37; - a[8][0] = -6.29; a[8][1] = -8.16; a[8][2] = -6.31; a[8][3] = -5.41; a[8][4] = 0.72; a[8][5] = 8.89; a[8][6] = -1.03; a[8][7] = 3.63; a[8][8] = 2.56; a[8][9] = -8.58; - a[9][0] = -9.7; a[9][1] = -6.76; a[9][2] = 8.55; a[9][3] = -6.56; a[9][4] = 1.11; a[9][5] = -6.31; a[9][6] = 7.5; a[9][7] = 2.46; a[9][8] = 1.38; a[9][9] = -4.59; + a[0][0] = 6.31; a[0][1] = 7.15; a[0][2] = 7.98; a[0][3] = 6.0; a[0][4] = 5.97; a[0][5] = 6.64; a[0][6] = 8.35; a[0][7] = 8.73; a[0][8] = 2.27; a[0][9] = 4.85; + a[1][0] = 8.03; a[1][1] = 2.96; a[1][2] = 5.47; a[1][3] = 2.95; a[1][4] = 9.4; a[1][5] = 6.64; a[1][6] = 0.7; a[1][7] = 2.87; a[1][8] = 5.56; a[1][9] = 9.94; + a[2][0] = 2.94; a[2][1] = 7.27; a[2][2] = 8.14; a[2][3] = 8.42; a[2][4] = 3.82; a[2][5] = 9.53; a[2][6] = 7.19; a[2][7] = 2.6; a[2][8] = 3.39; a[2][9] = 2.6; + a[3][0] = 1.04; a[3][1] = 1.34; a[3][2] = 9.74; a[3][3] = 6.77; a[3][4] = 3.73; a[3][5] = 4.77; a[3][6] = 4.71; a[3][7] = 7.22; a[3][8] = 6.39; a[3][9] = 9.43; + a[4][0] = 8.74; a[4][1] = 3.57; a[4][2] = 2.89; a[4][3] = 9.43; a[4][4] = 6.62; a[4][5] = 9.37; a[4][6] = 2.04; a[4][7] = 2.07; a[4][8] = 7.97; a[4][9] = 6.7; + a[5][0] = 8.65; a[5][1] = 6.86; a[5][2] = 5.11; a[5][3] = 6.66; a[5][4] = 1.59; a[5][5] = 2.54; a[5][6] = 9.67; a[5][7] = 0.32; a[5][8] = 2.83; a[5][9] = 9.32; + a[6][0] = 3.88; a[6][1] = 1.13; a[6][2] = 4.18; a[6][3] = 7.37; a[6][4] = 1.26; a[6][5] = 2.89; a[6][6] = 1.56; a[6][7] = 7.53; a[6][8] = 9.79; a[6][9] = 0.84; + a[7][0] = 9.31; a[7][1] = 9.95; a[7][2] = 2.23; a[7][3] = 2.76; a[7][4] = 2.6; a[7][5] = 1.96; a[7][6] = 9.16; a[7][7] = 0.87; a[7][8] = 3.59; a[7][9] = 5.92; + a[8][0] = 7.85; a[8][1] = 9.66; a[8][2] = 2.9; a[8][3] = 4.67; a[8][4] = 5.05; a[8][5] = 1.36; a[8][6] = 7.63; a[8][7] = 10.0; a[8][8] = 7.09; a[8][9] = 7.7; + a[9][0] = 1.67; a[9][1] = 8.16; a[9][2] = 4.85; a[9][3] = 9.2; a[9][4] = 7.42; a[9][5] = 6.94; a[9][6] = 5.88; a[9][7] = 7.84; a[9][8] = 2.55; a[9][9] = 3.77; - b[0][0] = -2.63; b[0][1] = 3.98; b[0][2] = 1.61; b[0][3] = -1.89; b[0][4] = 0.13; b[0][5] = 1.19; b[0][6] = -1.68; b[0][7] = 0.28; b[0][8] = -5.81; b[0][9] = -8.44; - b[1][0] = -4.75; b[1][1] = 9.77; b[1][2] = 4.18; b[1][3] = 2.71; b[1][4] = -9.21; b[1][5] = -9.9; b[1][6] = 8.85; b[1][7] = 1.44; b[1][8] = -1.18; b[1][9] = 1.05; - b[2][0] = -0.99; b[2][1] = 6.96; b[2][2] = 9.88; b[2][3] = 4.38; b[2][4] = 0.98; b[2][5] = 4.82; b[2][6] = -5.71; b[2][7] = 6.05; b[2][8] = -1.27; b[2][9] = 0.28; - b[3][0] = 0.06; b[3][1] = 8.84; b[3][2] = -1.21; b[3][3] = -9.9; b[3][4] = -4.34; b[3][5] = 3.51; b[3][6] = 0.17; b[3][7] = -5.78; b[3][8] = 2.15; b[3][9] = -3.5; - b[4][0] = 5.02; b[4][1] = 9.02; b[4][2] = 0.08; b[4][3] = 9.65; b[4][4] = -8.58; b[4][5] = -8.78; b[4][6] = -5.9; b[4][7] = -7.91; b[4][8] = -4.82; b[4][9] = 5.38; - b[5][0] = 5.08; b[5][1] = -3.86; b[5][2] = 3.38; b[5][3] = -4.63; b[5][4] = 6.48; b[5][5] = 3.64; b[5][6] = 0.95; b[5][7] = 6.73; b[5][8] = -7.37; b[5][9] = -2.45; - b[6][0] = -7.99; b[6][1] = -6.09; b[6][2] = 7.38; b[6][3] = 1.78; b[6][4] = 6.5; b[6][5] = 3.65; b[6][6] = -3.25; b[6][7] = 6.81; b[6][8] = -7.96; b[6][9] = 3.74; - b[7][0] = -1.79; b[7][1] = -4.53; b[7][2] = 5.25; b[7][3] = 2.04; b[7][4] = 9.67; b[7][5] = 1.1; b[7][6] = 6.72; b[7][7] = -7.87; b[7][8] = 9.71; b[7][9] = 4.72; - b[8][0] = 7.46; b[8][1] = 0.52; b[8][2] = 0.21; b[8][3] = 3.48; b[8][4] = 8.02; b[8][5] = -7.27; b[8][6] = -9.31; b[8][7] = -3.12; b[8][8] = -7.3; b[8][9] = 4.97; - b[9][0] = 1.5; b[9][1] = -5.62; b[9][2] = 8.34; b[9][3] = 5.42; b[9][4] = 1.48; b[9][5] = -6.05; b[9][6] = -7.68; b[9][7] = 3.84; b[9][8] = -4.91; b[9][9] = 3.17; + b[0][0] = 2.02; b[0][1] = 7.28; b[0][2] = 1.17; b[0][3] = 7.19; b[0][4] = 3.7; b[0][5] = 5.99; b[0][6] = 9.42; b[0][7] = 8.49; b[0][8] = 7.97; b[0][9] = 8.95; + b[1][0] = 8.18; b[1][1] = 4.6; b[1][2] = 4.47; b[1][3] = 1.45; b[1][4] = 3.6; b[1][5] = 9.14; b[1][6] = 6.36; b[1][7] = 5.98; b[1][8] = 9.16; b[1][9] = 2.4; + b[2][0] = 5.72; b[2][1] = 1.34; b[2][2] = 5.94; b[2][3] = 5.4; b[2][4] = 8.43; b[2][5] = 4.75; b[2][6] = 0.65; b[2][7] = 3.19; b[2][8] = 3.51; b[2][9] = 2.16; + b[3][0] = 6.69; b[3][1] = 6.1; b[3][2] = 5.43; b[3][3] = 8.81; b[3][4] = 8.12; b[3][5] = 8.02; b[3][6] = 9.91; b[3][7] = 0.88; b[3][8] = 0.06; b[3][9] = 3.12; + b[4][0] = 2.19; b[4][1] = 1.89; b[4][2] = 6.85; b[4][3] = 8.73; b[4][4] = 2.11; b[4][5] = 4.48; b[4][6] = 7.25; b[4][7] = 2.83; b[4][8] = 8.08; b[4][9] = 0.63; + b[5][0] = 2.39; b[5][1] = 4.83; b[5][2] = 5.05; b[5][3] = 0.65; b[5][4] = 4.59; b[5][5] = 8.7; b[5][6] = 9.11; b[5][7] = 1.7; b[5][8] = 2.49; b[5][9] = 2.34; + b[6][0] = 8.91; b[6][1] = 3.72; b[6][2] = 0.13; b[6][3] = 9.1; b[6][4] = 4.53; b[6][5] = 1.97; b[6][6] = 2.67; b[6][7] = 1.92; b[6][8] = 2.42; b[6][9] = 5.23; + b[7][0] = 9.89; b[7][1] = 5.62; b[7][2] = 8.5; b[7][3] = 1.06; b[7][4] = 7.61; b[7][5] = 3.62; b[7][6] = 4.59; b[7][7] = 7.37; b[7][8] = 7.92; b[7][9] = 3.33; + b[8][0] = 9.95; b[8][1] = 0.36; b[8][2] = 1.23; b[8][3] = 1.42; b[8][4] = 1.14; b[8][5] = 6.96; b[8][6] = 8.51; b[8][7] = 1.03; b[8][8] = 1.7; b[8][9] = 6.18; + b[9][0] = 4.66; b[9][1] = 5.5; b[9][2] = 7.44; b[9][3] = 9.1; b[9][4] = 2.53; b[9][5] = 2.16; b[9][6] = 5.21; b[9][7] = 9.08; b[9][8] = 8.29; b[9][9] = 8.15; let _ = matmul(10,10,10,a,b,c); - matshow(10, 10, c) + let _ = matshow(10, 10, a); + let _ = print_endline(); + let _ = matshow(10, 10, b); + let _ = print_endline(); + let _ = matshow(10, 10, c); + () }; \ No newline at end of file diff --git a/test/test_src/matmul_gen_int.ans b/test/test_src/matmul_gen_int.ans new file mode 100644 index 0000000..008fe25 --- /dev/null +++ b/test/test_src/matmul_gen_int.ans @@ -0,0 +1,70 @@ +-8 -5 4 -8 4 -3 -2 6 0 -3 -5 4 8 4 1 5 -2 -1 2 5 -7 1 +-4 -4 -4 1 7 1 -6 -8 -8 -6 1 6 7 -5 0 1 0 -1 4 8 -6 -4 +-1 6 8 1 -1 5 -5 -4 -7 2 -6 8 -1 -5 -8 -7 0 -4 -4 -6 2 -5 +-7 -8 6 -8 -5 0 -7 3 0 -6 -3 -8 1 1 1 3 8 -3 0 -4 2 2 +-5 8 1 -5 -3 0 5 2 -7 -1 -4 -4 -5 -3 -2 2 -7 6 7 5 7 7 +5 -6 4 6 8 -3 -3 -6 -2 -2 0 -6 2 0 -7 8 -5 -3 -8 -2 6 3 +-4 5 -1 1 3 4 -3 -3 7 -8 -4 -4 4 8 4 7 4 4 2 0 1 2 +-4 3 6 6 -1 -6 -3 2 0 -1 1 4 0 8 4 -6 5 0 -2 1 -8 -8 +-1 8 -7 0 1 1 -5 5 5 -8 -4 -7 -7 8 2 7 8 4 2 3 8 1 +5 -8 6 -2 3 -8 -1 -4 6 -6 -6 -4 -6 -3 -6 -3 5 0 -7 2 4 -6 +2 -3 5 -6 -8 -6 -1 -8 3 1 3 6 -4 -4 1 8 7 8 2 -5 4 -7 +-1 -7 -3 4 -8 -8 8 -2 6 -3 -8 -5 6 8 -3 -8 8 -3 -3 -3 -5 -3 +5 3 -6 2 6 -3 2 4 6 6 8 -5 -7 -5 -4 1 -2 -8 -1 -2 6 0 +1 -4 -1 -1 -4 -8 8 3 -4 2 7 2 8 6 -1 4 -7 -4 6 5 4 -5 +2 -2 3 4 -2 -7 6 -2 2 -4 -2 0 -4 3 4 -1 0 3 -8 -2 8 1 +4 6 2 -8 -3 -3 -7 -3 -1 3 -2 4 5 5 5 -3 6 -2 0 -7 -1 1 +-5 1 6 -8 -1 -4 -8 2 -8 3 -6 -2 3 3 4 -5 -3 -2 -8 7 1 2 +4 7 -3 6 4 4 -8 -4 -8 -5 4 -2 -3 5 -5 -4 -7 -4 0 -8 0 -8 +-3 -2 -7 8 0 6 -8 7 -4 -4 -8 -5 -4 -6 1 7 4 -6 -1 0 5 0 +-4 -1 0 1 -4 -4 -8 7 3 0 5 5 -8 5 1 0 3 -8 8 0 -8 -1 +-7 6 0 -2 -4 -5 0 5 -3 -5 0 -3 0 3 1 8 -8 7 1 8 -8 -5 +2 -7 -5 -4 5 -7 -8 6 -5 -6 -7 -5 -8 5 5 -3 7 -6 2 -7 -2 -3 +-6 2 -1 1 0 8 -1 6 8 7 -7 2 2 -7 6 -4 6 -2 -6 3 -2 -8 + +1 -5 -2 5 -3 -6 -4 -3 7 -6 -7 -1 3 -3 2 -6 1 -8 4 -6 7 +-1 6 4 7 2 2 1 -2 6 -4 1 -5 6 -1 7 6 3 -4 6 -5 -3 +1 7 8 0 7 2 -4 7 8 7 8 -6 3 0 8 -2 -6 -3 5 6 -3 +-3 -2 0 0 0 -3 6 8 -7 -8 -4 0 -3 8 -2 3 2 -8 -5 -7 -5 +7 4 8 3 -3 -3 -2 8 -7 1 -4 -4 -3 -3 -2 -2 -2 4 -5 8 0 +-5 -2 8 4 5 -7 7 6 8 1 4 -2 0 -1 -4 3 -8 -1 -4 -4 4 +-1 -1 7 0 -3 -7 5 -1 -8 -7 2 -8 -7 0 -6 8 -2 -8 -4 -3 5 +6 -1 -2 8 4 -8 5 -3 -4 4 7 -1 3 8 -4 -6 -6 5 -8 4 2 +-5 3 5 5 7 5 5 1 8 4 1 1 1 8 7 -4 -2 -4 2 -2 -1 +-6 3 6 -5 1 4 -5 7 0 6 8 -5 7 5 8 -4 -7 3 5 -3 8 +3 3 7 3 -3 -4 -1 -1 7 -3 -5 4 7 -7 -3 3 -8 5 -2 -1 7 +1 5 -3 -5 7 2 4 7 7 -7 2 7 0 4 -8 -7 -7 -8 3 8 -3 +3 -5 6 -4 -4 -8 -3 8 -4 -1 -8 8 2 4 -6 8 -2 -5 1 3 -6 +4 -4 6 -7 3 8 7 8 -3 3 -8 -4 4 8 6 3 1 5 1 3 8 +-5 3 -7 7 6 8 -2 -6 -8 -2 -4 7 3 -8 -7 -1 -1 0 -2 0 -7 +2 8 -8 -1 -3 1 7 4 -4 2 2 -1 -4 4 -1 -8 4 3 4 -7 -3 +-7 -3 -2 7 7 5 -6 0 3 -3 7 7 -5 4 -5 0 0 -1 -5 5 3 +-5 -3 0 -6 -8 3 3 3 5 -5 -4 0 -5 -7 -3 -2 -3 6 -8 -3 4 +-4 8 2 -6 -5 3 -2 5 1 6 -1 -3 -1 7 1 6 8 -7 -6 1 5 +5 -8 8 4 3 -1 -5 0 3 4 -4 3 6 -5 0 -5 -8 -7 4 -6 -4 +-7 3 -5 0 -5 -4 -2 1 -3 -3 -1 5 -3 2 -8 -1 -3 -3 3 1 0 +1 -5 6 0 -2 2 -3 2 -3 7 5 8 0 0 0 -6 5 -7 2 6 6 + +244 14 59 -105 88 60 18 120 -113 251 24 50 25 90 -17 -89 -34 91 -6 238 -146 +150 -37 -7 -104 -73 -51 -106 106 -31 -60 -213 167 -40 -164 -193 66 10 -43 -50 60 -227 +-50 101 -14 -67 121 -60 -59 95 225 -82 197 -97 9 25 82 59 -67 -63 146 113 -109 +-25 -7 -163 30 92 116 -85 -103 -33 254 177 124 -75 56 2 -37 100 207 -35 196 -51 +-25 67 25 -66 -199 -23 -9 -77 -57 106 108 -125 -40 -109 11 36 97 -55 18 -76 49 +141 -28 -12 -65 -198 -154 -22 135 -156 3 -125 -33 -95 -17 51 -108 78 35 135 -33 -52 +-53 17 23 40 36 157 147 117 -41 42 -126 59 -83 86 5 66 142 14 -46 -17 -96 +58 6 30 7 244 198 21 51 38 -60 -53 -30 111 79 105 82 -64 64 -41 97 -126 +-84 -10 -167 197 21 156 134 -98 -43 19 -48 38 -80 98 -4 -67 171 103 -84 -95 18 +10 -77 -121 67 31 27 -129 -133 79 -20 9 -42 -149 -55 97 -147 20 24 63 51 -79 +-225 220 -286 -122 -17 222 -53 -53 258 -113 77 70 -113 -58 -19 -119 6 52 89 -33 3 +-49 -278 -17 -93 71 77 27 -65 -179 -71 -69 4 -133 244 54 214 164 -80 -70 35 0 +9 113 25 199 -80 -147 -23 -117 -38 -8 47 -101 64 48 81 -73 -14 25 41 -115 145 +158 23 38 -188 -165 -141 16 56 -174 -14 -201 -25 91 103 -89 110 -55 -66 55 -45 42 +-64 -45 -134 16 -8 53 43 -88 -129 -169 -59 31 -114 -44 -68 -50 13 -49 38 -3 -50 +-63 52 -80 -20 121 216 -152 -17 131 21 10 117 131 22 97 9 73 23 155 172 18 +143 -111 5 -17 108 106 -210 -71 -62 207 46 67 191 -145 103 -93 -93 149 190 161 -152 +97 57 -43 -39 -106 -101 92 18 50 -160 -230 -170 66 -52 103 208 124 133 1 -73 8 +-53 -30 -323 180 34 -102 78 -84 -220 17 120 97 -138 126 -161 -107 134 49 -109 -91 -174 +74 137 -76 31 235 221 44 -38 98 175 112 20 154 210 145 -93 55 77 -34 111 37 +193 28 -41 -54 -59 64 151 -85 -50 63 -101 -129 69 -87 90 22 43 168 -13 -162 -155 +79 -33 -354 85 56 160 -84 -228 -239 76 -11 19 -88 39 -10 -80 257 262 -157 221 16 +-163 0 6 227 322 5 25 -22 54 8 221 32 41 85 -47 -38 -246 11 -48 -31 -196 diff --git a/test/test_src/matmul_gen_int.mbt b/test/test_src/matmul_gen_int.mbt new file mode 100644 index 0000000..a2efbc3 --- /dev/null +++ b/test/test_src/matmul_gen_int.mbt @@ -0,0 +1,126 @@ + +fn matshow(m: Int, n: Int, mat: Array[Array[Int]]) -> Unit { + fn loop1(i: Int) -> Unit { + if i <= m - 1 { + fn loop2(j: Int) -> Unit { + if j <= n - 1 { + let _ = print_int(mat[i][j]); + let _ = print_char(32); + loop2(j+1) + } else { + print_endline() + } + }; + let _ = loop2(0); + loop1(i+1) + } else { + () + } + }; + loop1(0) +}; + +fn matmul(l: Int, m: Int, n: Int, a: Array[Array[Int]], b: Array[Array[Int]], c: Array[Array[Int]]) -> Unit { + fn loop1(i: Int) -> Unit { + if 0 <= i { + fn loop2(j: Int) -> Unit { + if 0 <= j { + fn loop3(k: Int) -> Unit { + if 0 <= k { + c[i][j] = c[i][j] + a[i][k] * b[k][j]; + loop3(k - 1) + } else { + () + } + }; + let _ = loop3(m - 1); + loop2(j - 1) + } else { + () + } + }; + let _ = loop2(n - 1); + loop1(i - 1) + } else { + () + } + }; + loop1(l - 1) +}; + +fn main { + let dummy = Array::make(0, 0); + fn gen_arr(m: Int, n: Int) -> Array[Array[Int]] { + let mat = Array::make(m, dummy); + fn init_arr(i: Int) -> Unit { + if 0 <= i { + mat[i] = Array::make(n, 0); + init_arr(i - 1) + } else { + () + } + }; + let _ = init_arr(m - 1); + mat + }; + + let a = gen_arr(23, 22); + let b = gen_arr(22, 21); + let c = gen_arr(23, 21); + + a[0][0] = -8; a[0][1] = -5; a[0][2] = 4; a[0][3] = -8; a[0][4] = 4; a[0][5] = -3; a[0][6] = -2; a[0][7] = 6; a[0][8] = 0; a[0][9] = -3; a[0][10] = -5; a[0][11] = 4; a[0][12] = 8; a[0][13] = 4; a[0][14] = 1; a[0][15] = 5; a[0][16] = -2; a[0][17] = -1; a[0][18] = 2; a[0][19] = 5; a[0][20] = -7; a[0][21] = 1; + a[1][0] = -4; a[1][1] = -4; a[1][2] = -4; a[1][3] = 1; a[1][4] = 7; a[1][5] = 1; a[1][6] = -6; a[1][7] = -8; a[1][8] = -8; a[1][9] = -6; a[1][10] = 1; a[1][11] = 6; a[1][12] = 7; a[1][13] = -5; a[1][14] = 0; a[1][15] = 1; a[1][16] = 0; a[1][17] = -1; a[1][18] = 4; a[1][19] = 8; a[1][20] = -6; a[1][21] = -4; + a[2][0] = -1; a[2][1] = 6; a[2][2] = 8; a[2][3] = 1; a[2][4] = -1; a[2][5] = 5; a[2][6] = -5; a[2][7] = -4; a[2][8] = -7; a[2][9] = 2; a[2][10] = -6; a[2][11] = 8; a[2][12] = -1; a[2][13] = -5; a[2][14] = -8; a[2][15] = -7; a[2][16] = 0; a[2][17] = -4; a[2][18] = -4; a[2][19] = -6; a[2][20] = 2; a[2][21] = -5; + a[3][0] = -7; a[3][1] = -8; a[3][2] = 6; a[3][3] = -8; a[3][4] = -5; a[3][5] = 0; a[3][6] = -7; a[3][7] = 3; a[3][8] = 0; a[3][9] = -6; a[3][10] = -3; a[3][11] = -8; a[3][12] = 1; a[3][13] = 1; a[3][14] = 1; a[3][15] = 3; a[3][16] = 8; a[3][17] = -3; a[3][18] = 0; a[3][19] = -4; a[3][20] = 2; a[3][21] = 2; + a[4][0] = -5; a[4][1] = 8; a[4][2] = 1; a[4][3] = -5; a[4][4] = -3; a[4][5] = 0; a[4][6] = 5; a[4][7] = 2; a[4][8] = -7; a[4][9] = -1; a[4][10] = -4; a[4][11] = -4; a[4][12] = -5; a[4][13] = -3; a[4][14] = -2; a[4][15] = 2; a[4][16] = -7; a[4][17] = 6; a[4][18] = 7; a[4][19] = 5; a[4][20] = 7; a[4][21] = 7; + a[5][0] = 5; a[5][1] = -6; a[5][2] = 4; a[5][3] = 6; a[5][4] = 8; a[5][5] = -3; a[5][6] = -3; a[5][7] = -6; a[5][8] = -2; a[5][9] = -2; a[5][10] = 0; a[5][11] = -6; a[5][12] = 2; a[5][13] = 0; a[5][14] = -7; a[5][15] = 8; a[5][16] = -5; a[5][17] = -3; a[5][18] = -8; a[5][19] = -2; a[5][20] = 6; a[5][21] = 3; + a[6][0] = -4; a[6][1] = 5; a[6][2] = -1; a[6][3] = 1; a[6][4] = 3; a[6][5] = 4; a[6][6] = -3; a[6][7] = -3; a[6][8] = 7; a[6][9] = -8; a[6][10] = -4; a[6][11] = -4; a[6][12] = 4; a[6][13] = 8; a[6][14] = 4; a[6][15] = 7; a[6][16] = 4; a[6][17] = 4; a[6][18] = 2; a[6][19] = 0; a[6][20] = 1; a[6][21] = 2; + a[7][0] = -4; a[7][1] = 3; a[7][2] = 6; a[7][3] = 6; a[7][4] = -1; a[7][5] = -6; a[7][6] = -3; a[7][7] = 2; a[7][8] = 0; a[7][9] = -1; a[7][10] = 1; a[7][11] = 4; a[7][12] = 0; a[7][13] = 8; a[7][14] = 4; a[7][15] = -6; a[7][16] = 5; a[7][17] = 0; a[7][18] = -2; a[7][19] = 1; a[7][20] = -8; a[7][21] = -8; + a[8][0] = -1; a[8][1] = 8; a[8][2] = -7; a[8][3] = 0; a[8][4] = 1; a[8][5] = 1; a[8][6] = -5; a[8][7] = 5; a[8][8] = 5; a[8][9] = -8; a[8][10] = -4; a[8][11] = -7; a[8][12] = -7; a[8][13] = 8; a[8][14] = 2; a[8][15] = 7; a[8][16] = 8; a[8][17] = 4; a[8][18] = 2; a[8][19] = 3; a[8][20] = 8; a[8][21] = 1; + a[9][0] = 5; a[9][1] = -8; a[9][2] = 6; a[9][3] = -2; a[9][4] = 3; a[9][5] = -8; a[9][6] = -1; a[9][7] = -4; a[9][8] = 6; a[9][9] = -6; a[9][10] = -6; a[9][11] = -4; a[9][12] = -6; a[9][13] = -3; a[9][14] = -6; a[9][15] = -3; a[9][16] = 5; a[9][17] = 0; a[9][18] = -7; a[9][19] = 2; a[9][20] = 4; a[9][21] = -6; + a[10][0] = 2; a[10][1] = -3; a[10][2] = 5; a[10][3] = -6; a[10][4] = -8; a[10][5] = -6; a[10][6] = -1; a[10][7] = -8; a[10][8] = 3; a[10][9] = 1; a[10][10] = 3; a[10][11] = 6; a[10][12] = -4; a[10][13] = -4; a[10][14] = 1; a[10][15] = 8; a[10][16] = 7; a[10][17] = 8; a[10][18] = 2; a[10][19] = -5; a[10][20] = 4; a[10][21] = -7; + a[11][0] = -1; a[11][1] = -7; a[11][2] = -3; a[11][3] = 4; a[11][4] = -8; a[11][5] = -8; a[11][6] = 8; a[11][7] = -2; a[11][8] = 6; a[11][9] = -3; a[11][10] = -8; a[11][11] = -5; a[11][12] = 6; a[11][13] = 8; a[11][14] = -3; a[11][15] = -8; a[11][16] = 8; a[11][17] = -3; a[11][18] = -3; a[11][19] = -3; a[11][20] = -5; a[11][21] = -3; + a[12][0] = 5; a[12][1] = 3; a[12][2] = -6; a[12][3] = 2; a[12][4] = 6; a[12][5] = -3; a[12][6] = 2; a[12][7] = 4; a[12][8] = 6; a[12][9] = 6; a[12][10] = 8; a[12][11] = -5; a[12][12] = -7; a[12][13] = -5; a[12][14] = -4; a[12][15] = 1; a[12][16] = -2; a[12][17] = -8; a[12][18] = -1; a[12][19] = -2; a[12][20] = 6; a[12][21] = 0; + a[13][0] = 1; a[13][1] = -4; a[13][2] = -1; a[13][3] = -1; a[13][4] = -4; a[13][5] = -8; a[13][6] = 8; a[13][7] = 3; a[13][8] = -4; a[13][9] = 2; a[13][10] = 7; a[13][11] = 2; a[13][12] = 8; a[13][13] = 6; a[13][14] = -1; a[13][15] = 4; a[13][16] = -7; a[13][17] = -4; a[13][18] = 6; a[13][19] = 5; a[13][20] = 4; a[13][21] = -5; + a[14][0] = 2; a[14][1] = -2; a[14][2] = 3; a[14][3] = 4; a[14][4] = -2; a[14][5] = -7; a[14][6] = 6; a[14][7] = -2; a[14][8] = 2; a[14][9] = -4; a[14][10] = -2; a[14][11] = 0; a[14][12] = -4; a[14][13] = 3; a[14][14] = 4; a[14][15] = -1; a[14][16] = 0; a[14][17] = 3; a[14][18] = -8; a[14][19] = -2; a[14][20] = 8; a[14][21] = 1; + a[15][0] = 4; a[15][1] = 6; a[15][2] = 2; a[15][3] = -8; a[15][4] = -3; a[15][5] = -3; a[15][6] = -7; a[15][7] = -3; a[15][8] = -1; a[15][9] = 3; a[15][10] = -2; a[15][11] = 4; a[15][12] = 5; a[15][13] = 5; a[15][14] = 5; a[15][15] = -3; a[15][16] = 6; a[15][17] = -2; a[15][18] = 0; a[15][19] = -7; a[15][20] = -1; a[15][21] = 1; + a[16][0] = -5; a[16][1] = 1; a[16][2] = 6; a[16][3] = -8; a[16][4] = -1; a[16][5] = -4; a[16][6] = -8; a[16][7] = 2; a[16][8] = -8; a[16][9] = 3; a[16][10] = -6; a[16][11] = -2; a[16][12] = 3; a[16][13] = 3; a[16][14] = 4; a[16][15] = -5; a[16][16] = -3; a[16][17] = -2; a[16][18] = -8; a[16][19] = 7; a[16][20] = 1; a[16][21] = 2; + a[17][0] = 4; a[17][1] = 7; a[17][2] = -3; a[17][3] = 6; a[17][4] = 4; a[17][5] = 4; a[17][6] = -8; a[17][7] = -4; a[17][8] = -8; a[17][9] = -5; a[17][10] = 4; a[17][11] = -2; a[17][12] = -3; a[17][13] = 5; a[17][14] = -5; a[17][15] = -4; a[17][16] = -7; a[17][17] = -4; a[17][18] = 0; a[17][19] = -8; a[17][20] = 0; a[17][21] = -8; + a[18][0] = -3; a[18][1] = -2; a[18][2] = -7; a[18][3] = 8; a[18][4] = 0; a[18][5] = 6; a[18][6] = -8; a[18][7] = 7; a[18][8] = -4; a[18][9] = -4; a[18][10] = -8; a[18][11] = -5; a[18][12] = -4; a[18][13] = -6; a[18][14] = 1; a[18][15] = 7; a[18][16] = 4; a[18][17] = -6; a[18][18] = -1; a[18][19] = 0; a[18][20] = 5; a[18][21] = 0; + a[19][0] = -4; a[19][1] = -1; a[19][2] = 0; a[19][3] = 1; a[19][4] = -4; a[19][5] = -4; a[19][6] = -8; a[19][7] = 7; a[19][8] = 3; a[19][9] = 0; a[19][10] = 5; a[19][11] = 5; a[19][12] = -8; a[19][13] = 5; a[19][14] = 1; a[19][15] = 0; a[19][16] = 3; a[19][17] = -8; a[19][18] = 8; a[19][19] = 0; a[19][20] = -8; a[19][21] = -1; + a[20][0] = -7; a[20][1] = 6; a[20][2] = 0; a[20][3] = -2; a[20][4] = -4; a[20][5] = -5; a[20][6] = 0; a[20][7] = 5; a[20][8] = -3; a[20][9] = -5; a[20][10] = 0; a[20][11] = -3; a[20][12] = 0; a[20][13] = 3; a[20][14] = 1; a[20][15] = 8; a[20][16] = -8; a[20][17] = 7; a[20][18] = 1; a[20][19] = 8; a[20][20] = -8; a[20][21] = -5; + a[21][0] = 2; a[21][1] = -7; a[21][2] = -5; a[21][3] = -4; a[21][4] = 5; a[21][5] = -7; a[21][6] = -8; a[21][7] = 6; a[21][8] = -5; a[21][9] = -6; a[21][10] = -7; a[21][11] = -5; a[21][12] = -8; a[21][13] = 5; a[21][14] = 5; a[21][15] = -3; a[21][16] = 7; a[21][17] = -6; a[21][18] = 2; a[21][19] = -7; a[21][20] = -2; a[21][21] = -3; + a[22][0] = -6; a[22][1] = 2; a[22][2] = -1; a[22][3] = 1; a[22][4] = 0; a[22][5] = 8; a[22][6] = -1; a[22][7] = 6; a[22][8] = 8; a[22][9] = 7; a[22][10] = -7; a[22][11] = 2; a[22][12] = 2; a[22][13] = -7; a[22][14] = 6; a[22][15] = -4; a[22][16] = 6; a[22][17] = -2; a[22][18] = -6; a[22][19] = 3; a[22][20] = -2; a[22][21] = -8; + + b[0][0] = 1; b[0][1] = -5; b[0][2] = -2; b[0][3] = 5; b[0][4] = -3; b[0][5] = -6; b[0][6] = -4; b[0][7] = -3; b[0][8] = 7; b[0][9] = -6; b[0][10] = -7; b[0][11] = -1; b[0][12] = 3; b[0][13] = -3; b[0][14] = 2; b[0][15] = -6; b[0][16] = 1; b[0][17] = -8; b[0][18] = 4; b[0][19] = -6; b[0][20] = 7; + b[1][0] = -1; b[1][1] = 6; b[1][2] = 4; b[1][3] = 7; b[1][4] = 2; b[1][5] = 2; b[1][6] = 1; b[1][7] = -2; b[1][8] = 6; b[1][9] = -4; b[1][10] = 1; b[1][11] = -5; b[1][12] = 6; b[1][13] = -1; b[1][14] = 7; b[1][15] = 6; b[1][16] = 3; b[1][17] = -4; b[1][18] = 6; b[1][19] = -5; b[1][20] = -3; + b[2][0] = 1; b[2][1] = 7; b[2][2] = 8; b[2][3] = 0; b[2][4] = 7; b[2][5] = 2; b[2][6] = -4; b[2][7] = 7; b[2][8] = 8; b[2][9] = 7; b[2][10] = 8; b[2][11] = -6; b[2][12] = 3; b[2][13] = 0; b[2][14] = 8; b[2][15] = -2; b[2][16] = -6; b[2][17] = -3; b[2][18] = 5; b[2][19] = 6; b[2][20] = -3; + b[3][0] = -3; b[3][1] = -2; b[3][2] = 0; b[3][3] = 0; b[3][4] = 0; b[3][5] = -3; b[3][6] = 6; b[3][7] = 8; b[3][8] = -7; b[3][9] = -8; b[3][10] = -4; b[3][11] = 0; b[3][12] = -3; b[3][13] = 8; b[3][14] = -2; b[3][15] = 3; b[3][16] = 2; b[3][17] = -8; b[3][18] = -5; b[3][19] = -7; b[3][20] = -5; + b[4][0] = 7; b[4][1] = 4; b[4][2] = 8; b[4][3] = 3; b[4][4] = -3; b[4][5] = -3; b[4][6] = -2; b[4][7] = 8; b[4][8] = -7; b[4][9] = 1; b[4][10] = -4; b[4][11] = -4; b[4][12] = -3; b[4][13] = -3; b[4][14] = -2; b[4][15] = -2; b[4][16] = -2; b[4][17] = 4; b[4][18] = -5; b[4][19] = 8; b[4][20] = 0; + b[5][0] = -5; b[5][1] = -2; b[5][2] = 8; b[5][3] = 4; b[5][4] = 5; b[5][5] = -7; b[5][6] = 7; b[5][7] = 6; b[5][8] = 8; b[5][9] = 1; b[5][10] = 4; b[5][11] = -2; b[5][12] = 0; b[5][13] = -1; b[5][14] = -4; b[5][15] = 3; b[5][16] = -8; b[5][17] = -1; b[5][18] = -4; b[5][19] = -4; b[5][20] = 4; + b[6][0] = -1; b[6][1] = -1; b[6][2] = 7; b[6][3] = 0; b[6][4] = -3; b[6][5] = -7; b[6][6] = 5; b[6][7] = -1; b[6][8] = -8; b[6][9] = -7; b[6][10] = 2; b[6][11] = -8; b[6][12] = -7; b[6][13] = 0; b[6][14] = -6; b[6][15] = 8; b[6][16] = -2; b[6][17] = -8; b[6][18] = -4; b[6][19] = -3; b[6][20] = 5; + b[7][0] = 6; b[7][1] = -1; b[7][2] = -2; b[7][3] = 8; b[7][4] = 4; b[7][5] = -8; b[7][6] = 5; b[7][7] = -3; b[7][8] = -4; b[7][9] = 4; b[7][10] = 7; b[7][11] = -1; b[7][12] = 3; b[7][13] = 8; b[7][14] = -4; b[7][15] = -6; b[7][16] = -6; b[7][17] = 5; b[7][18] = -8; b[7][19] = 4; b[7][20] = 2; + b[8][0] = -5; b[8][1] = 3; b[8][2] = 5; b[8][3] = 5; b[8][4] = 7; b[8][5] = 5; b[8][6] = 5; b[8][7] = 1; b[8][8] = 8; b[8][9] = 4; b[8][10] = 1; b[8][11] = 1; b[8][12] = 1; b[8][13] = 8; b[8][14] = 7; b[8][15] = -4; b[8][16] = -2; b[8][17] = -4; b[8][18] = 2; b[8][19] = -2; b[8][20] = -1; + b[9][0] = -6; b[9][1] = 3; b[9][2] = 6; b[9][3] = -5; b[9][4] = 1; b[9][5] = 4; b[9][6] = -5; b[9][7] = 7; b[9][8] = 0; b[9][9] = 6; b[9][10] = 8; b[9][11] = -5; b[9][12] = 7; b[9][13] = 5; b[9][14] = 8; b[9][15] = -4; b[9][16] = -7; b[9][17] = 3; b[9][18] = 5; b[9][19] = -3; b[9][20] = 8; + b[10][0] = 3; b[10][1] = 3; b[10][2] = 7; b[10][3] = 3; b[10][4] = -3; b[10][5] = -4; b[10][6] = -1; b[10][7] = -1; b[10][8] = 7; b[10][9] = -3; b[10][10] = -5; b[10][11] = 4; b[10][12] = 7; b[10][13] = -7; b[10][14] = -3; b[10][15] = 3; b[10][16] = -8; b[10][17] = 5; b[10][18] = -2; b[10][19] = -1; b[10][20] = 7; + b[11][0] = 1; b[11][1] = 5; b[11][2] = -3; b[11][3] = -5; b[11][4] = 7; b[11][5] = 2; b[11][6] = 4; b[11][7] = 7; b[11][8] = 7; b[11][9] = -7; b[11][10] = 2; b[11][11] = 7; b[11][12] = 0; b[11][13] = 4; b[11][14] = -8; b[11][15] = -7; b[11][16] = -7; b[11][17] = -8; b[11][18] = 3; b[11][19] = 8; b[11][20] = -3; + b[12][0] = 3; b[12][1] = -5; b[12][2] = 6; b[12][3] = -4; b[12][4] = -4; b[12][5] = -8; b[12][6] = -3; b[12][7] = 8; b[12][8] = -4; b[12][9] = -1; b[12][10] = -8; b[12][11] = 8; b[12][12] = 2; b[12][13] = 4; b[12][14] = -6; b[12][15] = 8; b[12][16] = -2; b[12][17] = -5; b[12][18] = 1; b[12][19] = 3; b[12][20] = -6; + b[13][0] = 4; b[13][1] = -4; b[13][2] = 6; b[13][3] = -7; b[13][4] = 3; b[13][5] = 8; b[13][6] = 7; b[13][7] = 8; b[13][8] = -3; b[13][9] = 3; b[13][10] = -8; b[13][11] = -4; b[13][12] = 4; b[13][13] = 8; b[13][14] = 6; b[13][15] = 3; b[13][16] = 1; b[13][17] = 5; b[13][18] = 1; b[13][19] = 3; b[13][20] = 8; + b[14][0] = -5; b[14][1] = 3; b[14][2] = -7; b[14][3] = 7; b[14][4] = 6; b[14][5] = 8; b[14][6] = -2; b[14][7] = -6; b[14][8] = -8; b[14][9] = -2; b[14][10] = -4; b[14][11] = 7; b[14][12] = 3; b[14][13] = -8; b[14][14] = -7; b[14][15] = -1; b[14][16] = -1; b[14][17] = 0; b[14][18] = -2; b[14][19] = 0; b[14][20] = -7; + b[15][0] = 2; b[15][1] = 8; b[15][2] = -8; b[15][3] = -1; b[15][4] = -3; b[15][5] = 1; b[15][6] = 7; b[15][7] = 4; b[15][8] = -4; b[15][9] = 2; b[15][10] = 2; b[15][11] = -1; b[15][12] = -4; b[15][13] = 4; b[15][14] = -1; b[15][15] = -8; b[15][16] = 4; b[15][17] = 3; b[15][18] = 4; b[15][19] = -7; b[15][20] = -3; + b[16][0] = -7; b[16][1] = -3; b[16][2] = -2; b[16][3] = 7; b[16][4] = 7; b[16][5] = 5; b[16][6] = -6; b[16][7] = 0; b[16][8] = 3; b[16][9] = -3; b[16][10] = 7; b[16][11] = 7; b[16][12] = -5; b[16][13] = 4; b[16][14] = -5; b[16][15] = 0; b[16][16] = 0; b[16][17] = -1; b[16][18] = -5; b[16][19] = 5; b[16][20] = 3; + b[17][0] = -5; b[17][1] = -3; b[17][2] = 0; b[17][3] = -6; b[17][4] = -8; b[17][5] = 3; b[17][6] = 3; b[17][7] = 3; b[17][8] = 5; b[17][9] = -5; b[17][10] = -4; b[17][11] = 0; b[17][12] = -5; b[17][13] = -7; b[17][14] = -3; b[17][15] = -2; b[17][16] = -3; b[17][17] = 6; b[17][18] = -8; b[17][19] = -3; b[17][20] = 4; + b[18][0] = -4; b[18][1] = 8; b[18][2] = 2; b[18][3] = -6; b[18][4] = -5; b[18][5] = 3; b[18][6] = -2; b[18][7] = 5; b[18][8] = 1; b[18][9] = 6; b[18][10] = -1; b[18][11] = -3; b[18][12] = -1; b[18][13] = 7; b[18][14] = 1; b[18][15] = 6; b[18][16] = 8; b[18][17] = -7; b[18][18] = -6; b[18][19] = 1; b[18][20] = 5; + b[19][0] = 5; b[19][1] = -8; b[19][2] = 8; b[19][3] = 4; b[19][4] = 3; b[19][5] = -1; b[19][6] = -5; b[19][7] = 0; b[19][8] = 3; b[19][9] = 4; b[19][10] = -4; b[19][11] = 3; b[19][12] = 6; b[19][13] = -5; b[19][14] = 0; b[19][15] = -5; b[19][16] = -8; b[19][17] = -7; b[19][18] = 4; b[19][19] = -6; b[19][20] = -4; + b[20][0] = -7; b[20][1] = 3; b[20][2] = -5; b[20][3] = 0; b[20][4] = -5; b[20][5] = -4; b[20][6] = -2; b[20][7] = 1; b[20][8] = -3; b[20][9] = -3; b[20][10] = -1; b[20][11] = 5; b[20][12] = -3; b[20][13] = 2; b[20][14] = -8; b[20][15] = -1; b[20][16] = -3; b[20][17] = -3; b[20][18] = 3; b[20][19] = 1; b[20][20] = 0; + b[21][0] = 1; b[21][1] = -5; b[21][2] = 6; b[21][3] = 0; b[21][4] = -2; b[21][5] = 2; b[21][6] = -3; b[21][7] = 2; b[21][8] = -3; b[21][9] = 7; b[21][10] = 5; b[21][11] = 8; b[21][12] = 0; b[21][13] = 0; b[21][14] = 0; b[21][15] = -6; b[21][16] = 5; b[21][17] = -7; b[21][18] = 2; b[21][19] = 6; b[21][20] = 6; + + let _ = matmul(23,22,21,a,b,c); + let _ = matshow(23, 22, a); + let _ = print_endline(); + let _ = matshow(22, 21, b); + let _ = print_endline(); + let _ = matshow(23, 21, c); + () + +}; \ No newline at end of file