|
14 | 14 |
|
15 | 15 | import pprint
|
16 | 16 | import numpy
|
| 17 | +from numpy.testing import assert_almost_equal |
17 | 18 | import matplotlib.pyplot as plt
|
18 | 19 | from pandas import DataFrame, concat
|
19 | 20 | from td3a_cpp.tutorial.mul_cython_omp import dmul_cython_omp
|
|
38 | 39 | dfs[-1]['fct'] = 'numpy'
|
39 | 40 | pprint.pprint(dfs[-1].tail(n=2))
|
40 | 41 |
|
| 42 | + |
41 | 43 | ##############################
|
42 | 44 | # Simple multiplication
|
43 | 45 | # +++++++++++++++++++++
|
|
57 | 59 | # Other scenarios
|
58 | 60 | # +++++++++++++++
|
59 | 61 | #
|
| 62 | +# 3 differents algorithms, each of them parallelized. |
| 63 | +# See :func:`dmul_cython_omp |
| 64 | +# <td3a_cpp.tutorial.mul_cython_omp.dmul_cython_omp>`. |
60 | 65 |
|
61 | 66 | for algo in range(0, 2):
|
62 | 67 | for parallel in (0, 1):
|
|
73 | 78 | dfs[-1]['fct'] = 'a=%d-p=%d' % (algo, parallel)
|
74 | 79 | pprint.pprint(dfs[-1].tail(n=2))
|
75 | 80 |
|
| 81 | +######################################## |
| 82 | +# One left issue |
| 83 | +# ++++++++++++++ |
| 84 | +# |
| 85 | +# Will you find it in :func:`dmul_cython_omp |
| 86 | +# <td3a_cpp.tutorial.mul_cython_omp.dmul_cython_omp>`. |
| 87 | + |
| 88 | + |
| 89 | +va = numpy.random.randn(3, 4).astype(numpy.float64) |
| 90 | +vb = numpy.random.randn(4, 5).astype(numpy.float64) |
| 91 | +numpy_mul = va @ vb |
| 92 | + |
| 93 | +try: |
| 94 | + for a in range(0, 50): |
| 95 | + wrong_mul = dmul_cython_omp(va, vb, algo=2, parallel=1) |
| 96 | + assert_almost_equal(numpy_mul, wrong_mul) |
| 97 | + print("Iteration %d is Ok" % a) |
| 98 | + print("All iterations are unexpectedly Ok. Don't push your luck.") |
| 99 | +except AssertionError as e: |
| 100 | + print(e) |
| 101 | + |
| 102 | + |
76 | 103 | ##############################
|
77 | 104 | # Other scenarios but transposed
|
78 | 105 | # ++++++++++++++++++++++++++++++
|
79 | 106 | #
|
| 107 | +# Same differents algorithms but the second matrix |
| 108 | +# is transposed first: ``b_trans=1``. |
| 109 | + |
80 | 110 |
|
81 | 111 | for algo in range(0, 2):
|
82 | 112 | for parallel in (0, 1):
|
|
0 commit comments