Wenzel Jakob | 9e0a056 | 2016-05-05 20:33:54 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | from __future__ import print_function |
| 3 | import sys |
| 4 | sys.path.append('.') |
| 5 | |
| 6 | from example import fixed_r, fixed_c |
| 7 | from example import fixed_passthrough_r, fixed_passthrough_c |
| 8 | from example import dense_r, dense_c |
| 9 | from example import dense_passthrough_r, dense_passthrough_c |
| 10 | from example import sparse_r, sparse_c |
| 11 | from example import sparse_passthrough_r, sparse_passthrough_c |
Ben North | 4a22091 | 2016-07-05 20:03:02 +0100 | [diff] [blame^] | 12 | from example import double_row, double_col |
Wenzel Jakob | 9e0a056 | 2016-05-05 20:33:54 +0200 | [diff] [blame] | 13 | import numpy as np |
| 14 | |
| 15 | ref = np.array( |
| 16 | [[0, 3, 0, 0, 0, 11], |
| 17 | [22, 0, 0, 0, 17, 11], |
| 18 | [7, 5, 0, 1, 0, 11], |
| 19 | [0, 0, 0, 0, 0, 11], |
| 20 | [0, 0, 14, 0, 8, 11]]) |
| 21 | |
| 22 | |
| 23 | def check(mat): |
| 24 | return 'OK' if np.sum(mat - ref) == 0 else 'NOT OK' |
| 25 | |
| 26 | print("fixed_r = %s" % check(fixed_r())) |
| 27 | print("fixed_c = %s" % check(fixed_c())) |
| 28 | print("pt_r(fixed_r) = %s" % check(fixed_passthrough_r(fixed_r()))) |
| 29 | print("pt_c(fixed_c) = %s" % check(fixed_passthrough_c(fixed_c()))) |
| 30 | print("pt_r(fixed_c) = %s" % check(fixed_passthrough_r(fixed_c()))) |
| 31 | print("pt_c(fixed_r) = %s" % check(fixed_passthrough_c(fixed_r()))) |
| 32 | |
| 33 | print("dense_r = %s" % check(dense_r())) |
| 34 | print("dense_c = %s" % check(dense_c())) |
| 35 | print("pt_r(dense_r) = %s" % check(dense_passthrough_r(dense_r()))) |
| 36 | print("pt_c(dense_c) = %s" % check(dense_passthrough_c(dense_c()))) |
| 37 | print("pt_r(dense_c) = %s" % check(dense_passthrough_r(dense_c()))) |
| 38 | print("pt_c(dense_r) = %s" % check(dense_passthrough_c(dense_r()))) |
| 39 | |
| 40 | print("sparse_r = %s" % check(sparse_r())) |
| 41 | print("sparse_c = %s" % check(sparse_c())) |
| 42 | print("pt_r(sparse_r) = %s" % check(sparse_passthrough_r(sparse_r()))) |
| 43 | print("pt_c(sparse_c) = %s" % check(sparse_passthrough_c(sparse_c()))) |
| 44 | print("pt_r(sparse_c) = %s" % check(sparse_passthrough_r(sparse_c()))) |
| 45 | print("pt_c(sparse_r) = %s" % check(sparse_passthrough_c(sparse_r()))) |
Ben North | 4a22091 | 2016-07-05 20:03:02 +0100 | [diff] [blame^] | 46 | |
| 47 | def check_got_vs_ref(got_x, ref_x): |
| 48 | return 'OK' if np.array_equal(got_x, ref_x) else 'NOT OK' |
| 49 | |
| 50 | counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3)) |
| 51 | first_row = counting_mat[0, :] |
| 52 | first_col = counting_mat[:, 0] |
| 53 | |
| 54 | print("double_row(first_row) = %s" % check_got_vs_ref(double_row(first_row), 2.0 * first_row)) |
| 55 | print("double_col(first_row) = %s" % check_got_vs_ref(double_col(first_row), 2.0 * first_row)) |
| 56 | print("double_row(first_col) = %s" % check_got_vs_ref(double_row(first_col), 2.0 * first_col)) |
| 57 | print("double_col(first_col) = %s" % check_got_vs_ref(double_col(first_col), 2.0 * first_col)) |