blob: 13e6301f21ae715ef855f45711c7d3e7104d7eb2 [file] [log] [blame]
Wenzel Jakob9e0a0562016-05-05 20:33:54 +02001#!/usr/bin/env python
2from __future__ import print_function
3import sys
4sys.path.append('.')
5
6from example import fixed_r, fixed_c
7from example import fixed_passthrough_r, fixed_passthrough_c
8from example import dense_r, dense_c
9from example import dense_passthrough_r, dense_passthrough_c
10from example import sparse_r, sparse_c
11from example import sparse_passthrough_r, sparse_passthrough_c
Ben North4a220912016-07-05 20:03:02 +010012from example import double_row, double_col
Wenzel Jakob9e0a0562016-05-05 20:33:54 +020013import numpy as np
14
15ref = 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
23def check(mat):
24 return 'OK' if np.sum(mat - ref) == 0 else 'NOT OK'
25
26print("fixed_r = %s" % check(fixed_r()))
27print("fixed_c = %s" % check(fixed_c()))
28print("pt_r(fixed_r) = %s" % check(fixed_passthrough_r(fixed_r())))
29print("pt_c(fixed_c) = %s" % check(fixed_passthrough_c(fixed_c())))
30print("pt_r(fixed_c) = %s" % check(fixed_passthrough_r(fixed_c())))
31print("pt_c(fixed_r) = %s" % check(fixed_passthrough_c(fixed_r())))
32
33print("dense_r = %s" % check(dense_r()))
34print("dense_c = %s" % check(dense_c()))
35print("pt_r(dense_r) = %s" % check(dense_passthrough_r(dense_r())))
36print("pt_c(dense_c) = %s" % check(dense_passthrough_c(dense_c())))
37print("pt_r(dense_c) = %s" % check(dense_passthrough_r(dense_c())))
38print("pt_c(dense_r) = %s" % check(dense_passthrough_c(dense_r())))
39
40print("sparse_r = %s" % check(sparse_r()))
41print("sparse_c = %s" % check(sparse_c()))
42print("pt_r(sparse_r) = %s" % check(sparse_passthrough_r(sparse_r())))
43print("pt_c(sparse_c) = %s" % check(sparse_passthrough_c(sparse_c())))
44print("pt_r(sparse_c) = %s" % check(sparse_passthrough_r(sparse_c())))
45print("pt_c(sparse_r) = %s" % check(sparse_passthrough_c(sparse_r())))
Ben North4a220912016-07-05 20:03:02 +010046
47def check_got_vs_ref(got_x, ref_x):
48 return 'OK' if np.array_equal(got_x, ref_x) else 'NOT OK'
49
50counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
51first_row = counting_mat[0, :]
52first_col = counting_mat[:, 0]
53
54print("double_row(first_row) = %s" % check_got_vs_ref(double_row(first_row), 2.0 * first_row))
55print("double_col(first_row) = %s" % check_got_vs_ref(double_col(first_row), 2.0 * first_row))
56print("double_row(first_col) = %s" % check_got_vs_ref(double_row(first_col), 2.0 * first_col))
57print("double_col(first_col) = %s" % check_got_vs_ref(double_col(first_col), 2.0 * first_col))