Skip to content

Commit

Permalink
updated numpy as numexpr versions
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgfierro committed Jan 21, 2019
1 parent c6e8375 commit 49af421
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 8 deletions.
116 changes: 110 additions & 6 deletions Benchmark_Matrix_Multiplication/Benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.66 µs ± 9.51 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"461 µs ± 35.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"5.36 µs ± 43.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"1.82 ms ± 4.06 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"84.5 µs ± 2.91 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"620 µs ± 17.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"529 µs ± 1.36 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"6.22 ms ± 39.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"38.4 ms ± 1.4 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"43.2 ms ± 516 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"211 ms ± 5.35 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"318 ms ± 39.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"367 ms ± 5.14 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"409 ms ± 6.44 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"2.06 s ± 8.51 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"3.2 s ± 6.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"3.71 s ± 161 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"3.63 s ± 110 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"26.2 s ± 7.23 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"OOM for size (100000,100000)\n"
]
}
],
"source": [
"for s1, s2 in size_combinations:\n",
" a, b, c = factors_float3(s1, s2)\n",
Expand All @@ -545,11 +572,53 @@
" df.loc[len(df)] = row"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Multiple matrix multiplication (5 factors)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"14.5 µs ± 36.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"495 µs ± 22.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"8.77 µs ± 58.9 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"2.68 ms ± 216 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"158 µs ± 1.48 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"668 µs ± 14 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"732 µs ± 4.28 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"10.3 ms ± 58.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"68.2 ms ± 2.72 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"65.9 ms ± 1.34 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"338 ms ± 2.79 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"486 ms ± 41 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"654 ms ± 29 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"581 ms ± 26.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"2.85 s ± 6.48 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"OOM for size (100000,10000)\n"
]
},
{
"ename": "MemoryError",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mMemoryError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-44-aba38e6dd697>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msize_combinations\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactors_float5\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0moperation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"a * b * c * d * e\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mr1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-o multiply5(a,b,c,d,e)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-o ne_multiply5(a,b,c,d,e)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-39-cf23e28c4542>\u001b[0m in \u001b[0;36mfactors_float5\u001b[0;34m(s1, s2)\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muniform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhigh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 21\u001b[0;31m \u001b[0md\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muniform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhigh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 22\u001b[0m \u001b[0me\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muniform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhigh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mMemoryError\u001b[0m: "
]
}
],
"source": [
"for s1, s2 in size_combinations:\n",
" a, b, c, d, e = factors_float5(s1, s2)\n",
Expand All @@ -576,9 +645,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"28 µs ± 316 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"472 µs ± 8.91 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"249 µs ± 3.26 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"1.85 ms ± 16 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"590 µs ± 58.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"1.36 ms ± 9.41 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"25 ms ± 391 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"7.12 ms ± 89.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"57.3 ms ± 665 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"100 ms ± 379 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"2.57 s ± 18.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"347 ms ± 39.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"556 ms ± 20 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"982 ms ± 14.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"25.7 s ± 217 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"3.38 s ± 24.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
},
{
"ename": "MemoryError",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mMemoryError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-45-810794d23589>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msize_combinations\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactors_float3\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0moperation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"a * exp(b) * sin(c)\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mr1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-o exponential_sine(a,b,c)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'-o ne_exponential_sine(a,b,c)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-39-cf23e28c4542>\u001b[0m in \u001b[0;36mfactors_float3\u001b[0;34m(s1, s2)\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mfactors_float3\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muniform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhigh\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ms2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mMemoryError\u001b[0m: "
]
}
],
"source": [
"for s1, s2 in size_combinations:\n",
" a, b, c = factors_float3(s1, s2)\n",
Expand Down
4 changes: 2 additions & 2 deletions Benchmark_Matrix_Multiplication/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ channels:
- defaults
dependencies:
- python==3.6.7
- numpy>=1.13.3
- numpy>=1.16.0
- pandas>=0.23.4
- cudatoolkit>=9.2
- pip:
- ipykernel>=5.1.0
- numexpr>=2.6.8
- numexpr>=2.6.9
- numba>=0.38.0
- bokeh>=0.12.16
- psutil>=5.4.8
Expand Down

0 comments on commit 49af421

Please sign in to comment.