Skip to content

Commit 8d1f2c6

Browse files
committed
add wrong example
1 parent ab2bbc3 commit 8d1f2c6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

doc/api.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ dot
6060

6161
.. autofunction:: td3a_cpp.tutorial.dot_cython_omp.ddot_array_openmp_16
6262

63-
6463
filter
6564
^^^^^^
6665

@@ -80,3 +79,7 @@ filter
8079

8180
.. autofunction:: td3a_cpp.tutorial.experiment_cython.cfilter_dmax16
8281

82+
matrix multiplication
83+
^^^^^^^^^^^^^^^^^^^^^
84+
85+
.. autofunction:: td3a_cpp.tutorial.mul_cython_omp.dmul_cython_omp

examples/plot_benchmark_dot_mul.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import pprint
1616
import numpy
17+
from numpy.testing import assert_almost_equal
1718
import matplotlib.pyplot as plt
1819
from pandas import DataFrame, concat
1920
from td3a_cpp.tutorial.mul_cython_omp import dmul_cython_omp
@@ -38,6 +39,7 @@
3839
dfs[-1]['fct'] = 'numpy'
3940
pprint.pprint(dfs[-1].tail(n=2))
4041

42+
4143
##############################
4244
# Simple multiplication
4345
# +++++++++++++++++++++
@@ -57,6 +59,9 @@
5759
# Other scenarios
5860
# +++++++++++++++
5961
#
62+
# 3 differents algorithms, each of them parallelized.
63+
# See :func:`dmul_cython_omp
64+
# <td3a_cpp.tutorial.mul_cython_omp.dmul_cython_omp>`.
6065

6166
for algo in range(0, 2):
6267
for parallel in (0, 1):
@@ -73,10 +78,35 @@
7378
dfs[-1]['fct'] = 'a=%d-p=%d' % (algo, parallel)
7479
pprint.pprint(dfs[-1].tail(n=2))
7580

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+
76103
##############################
77104
# Other scenarios but transposed
78105
# ++++++++++++++++++++++++++++++
79106
#
107+
# Same differents algorithms but the second matrix
108+
# is transposed first: ``b_trans=1``.
109+
80110

81111
for algo in range(0, 2):
82112
for parallel in (0, 1):

0 commit comments

Comments
 (0)