diff --git a/examples/3.pautomac_light.train.gv b/examples/3.pautomac_light.train.gv deleted file mode 100644 index 630afa0c022bca2912dd7c273fa6247b5aacb683..0000000000000000000000000000000000000000 --- a/examples/3.pautomac_light.train.gv +++ /dev/null @@ -1,41 +0,0 @@ -//3.pautomac_light.train.dot -digraph { - 0 [label="0 -______"] - 1 [label="1 -______"] - 2 [label="2 -______ --0.45 >"] - 3 [label="3 -______ -0.63 >"] - 4 [label="4 -______ --0.55 >"] - 0 -> 1 [label="0:-0.24"] - 0 -> 2 [label="0:0.35"] - 0 -> 3 [label="0:-0.28"] - 0 -> 4 [label="0:-0.21"] - 1 -> 1 [label="0:-0.30"] - 1 -> 2 [label="0:0.21"] - 1 -> 4 [label="0:-0.56"] - 2 -> 3 [label="0:-0.21"] - 4 -> 4 [label="0:0.24"] - 0 -> 2 [label="1:-0.30"] - 0 -> 3 [label="1:0.28"] - 0 -> 4 [label="1:0.20"] - 1 -> 2 [label="1:0.26"] - 0 -> 2 [label="2:0.38"] - 0 -> 3 [label="2:-0.22"] - 0 -> 4 [label="2:-0.23"] - 1 -> 4 [label="2:0.35"] - 1 -> 2 [label="3:0.28"] - 1 -> 3 [label="3:-0.24"] - 2 -> 2 [label="3:-0.63"] - 2 -> 3 [label="3:0.47"] - 3 -> 2 [label="3:-0.37"] - 3 -> 4 [label="3:0.65"] - 4 -> 3 [label="3:-0.38"] - 4 -> 4 [label="3:0.66"] -} diff --git a/examples/3.pautomac_light.train.gv.pdf b/examples/3.pautomac_light.train.gv.pdf deleted file mode 100644 index 13325f666807d2f6f0e6e5f37700589d688fa25b..0000000000000000000000000000000000000000 Binary files a/examples/3.pautomac_light.train.gv.pdf and /dev/null differ diff --git a/examples/3.pautomac_light.train.json b/examples/3.pautomac_light.train.json deleted file mode 100644 index 9f45619b654f3e643a0478fb6e237b7b406fa8a3..0000000000000000000000000000000000000000 --- a/examples/3.pautomac_light.train.json +++ /dev/null @@ -1 +0,0 @@ -{"automaton": {"nbL": 4, "nbS": 5, "initial": {"numpy.ndarray": {"values": [-0.0004934419970497512, 0.0030634697107912346, -0.044073932015580415, -0.1077770261654714, -0.0866391379316952], "dtype": "float64"}}, "final": {"numpy.ndarray": {"values": [0.07757136847945045, -0.024220294003132026, -0.4468125366321221, 0.627732084089759, -0.554674433356224], "dtype": "float64"}}, "transitions": [{"numpy.ndarray": {"values": [[0.04512120959511772, -0.24038969827844062, 0.34944999592135334, -0.2811680730534579, -0.21402523377497645], [0.0692580056243761, -0.30062293462829204, 0.20641375368520157, -0.14960814319756124, -0.5580573163749153], [0.02980115192176571, -0.13866480809160409, 0.18362212572805459, -0.20969545230657607, -0.14481622025561292], [0.005699344003198349, -0.023385825120201414, -0.06600665373981851, 0.10749935271466007, -0.15103654604159977], [-0.02008655193147911, 0.09026347555230492, -0.005525585655539262, -0.031355317090308935, 0.2432902242047721]], "dtype": "float64"}}, {"numpy.ndarray": {"values": [[0.0774477207917058, 0.09007073705762021, -0.3047220063293013, 0.2767624549859105, 0.20289396030628148], [-0.09902980483670844, -0.08061846818727973, 0.25853170692250554, -0.12086330214608881, -0.11085207725068251], [-0.061710792028537534, -0.06244151779954751, 0.12007654564862075, 0.0025063746277943564, -0.1567967473145572], [-0.002736973749965403, -0.009005721984277787, -0.00046003295909181354, -0.008550426472005344, -0.053754646789681754], [0.030987327588710728, 0.03972680066723246, -0.04997113350910248, 0.0035769411874962344, 0.1418257620585633]], "dtype": "float64"}}, {"numpy.ndarray": {"values": [[-0.06791915236220235, -0.11357937659088102, 0.37955392604054394, -0.21784979894046635, -0.22977695089938127], [0.11596642335411328, 0.14914956804629287, -0.13357508376686902, -0.008916063072034974, 0.3484153673774836], [0.011730817547426673, 0.019273800531955612, 0.0414265834586712, -0.035346588560982, 0.02316491010895583], [0.007328911075541707, 0.005536509132796312, -0.022456082950666856, 0.03611543477693187, -0.038514339001406585], [-0.010589894686551544, -0.010626616553723532, -0.000543105645661794, -0.025567476700160314, 0.04984888818929034]], "dtype": "float64"}}, {"numpy.ndarray": {"values": [[0.07276211427780357, -0.0157195576855797, 0.07428592814590385, -0.10369861539249735, 0.024753473688328077], [-0.05607105449779142, -0.08896207276035666, 0.27638225397521243, -0.2371125582838589, 0.07372294122306285], [-0.007391294007753122, -0.048741797963875705, -0.6291239733858526, 0.46816276521577677, 0.09251699239093385], [-0.007110224931878467, -0.05623317735898056, -0.36606658567620365, -0.013297798115225407, 0.6491033177492604], [0.002335515008556511, -0.021561151264484414, 0.09096243479437888, -0.38438823493062646, 0.6616477207948602]], "dtype": "float64"}}], "type": "classic"}} \ No newline at end of file diff --git a/examples/3.pautomac_light.train.yaml b/examples/3.pautomac_light.train.yaml deleted file mode 100644 index 09108d5a4dba3467ec25520429c52b27916876dc..0000000000000000000000000000000000000000 --- a/examples/3.pautomac_light.train.yaml +++ /dev/null @@ -1,67 +0,0 @@ -automaton: - final: - numpy.ndarray: - dtype: float64 - values: [0.07757136847945045, -0.024220294003132026, -0.4468125366321221, 0.627732084089759, - -0.554674433356224] - initial: - numpy.ndarray: - dtype: float64 - values: [-0.0004934419970497512, 0.0030634697107912346, -0.044073932015580415, - -0.1077770261654714, -0.0866391379316952] - nbL: 4 - nbS: 5 - transitions: - - numpy.ndarray: - dtype: float64 - values: - - [0.04512120959511772, -0.24038969827844062, 0.34944999592135334, -0.2811680730534579, - -0.21402523377497645] - - [0.0692580056243761, -0.30062293462829204, 0.20641375368520157, -0.14960814319756124, - -0.5580573163749153] - - [0.02980115192176571, -0.13866480809160409, 0.18362212572805459, -0.20969545230657607, - -0.14481622025561292] - - [0.005699344003198349, -0.023385825120201414, -0.06600665373981851, 0.10749935271466007, - -0.15103654604159977] - - [-0.02008655193147911, 0.09026347555230492, -0.005525585655539262, -0.031355317090308935, - 0.2432902242047721] - - numpy.ndarray: - dtype: float64 - values: - - [0.0774477207917058, 0.09007073705762021, -0.3047220063293013, 0.2767624549859105, - 0.20289396030628148] - - [-0.09902980483670844, -0.08061846818727973, 0.25853170692250554, -0.12086330214608881, - -0.11085207725068251] - - [-0.061710792028537534, -0.06244151779954751, 0.12007654564862075, 0.0025063746277943564, - -0.1567967473145572] - - [-0.002736973749965403, -0.009005721984277787, -0.00046003295909181354, -0.008550426472005344, - -0.053754646789681754] - - [0.030987327588710728, 0.03972680066723246, -0.04997113350910248, 0.0035769411874962344, - 0.1418257620585633] - - numpy.ndarray: - dtype: float64 - values: - - [-0.06791915236220235, -0.11357937659088102, 0.37955392604054394, -0.21784979894046635, - -0.22977695089938127] - - [0.11596642335411328, 0.14914956804629287, -0.13357508376686902, -0.008916063072034974, - 0.3484153673774836] - - [0.011730817547426673, 0.019273800531955612, 0.0414265834586712, -0.035346588560982, - 0.02316491010895583] - - [0.007328911075541707, 0.005536509132796312, -0.022456082950666856, 0.03611543477693187, - -0.038514339001406585] - - [-0.010589894686551544, -0.010626616553723532, -0.000543105645661794, -0.025567476700160314, - 0.04984888818929034] - - numpy.ndarray: - dtype: float64 - values: - - [0.07276211427780357, -0.0157195576855797, 0.07428592814590385, -0.10369861539249735, - 0.024753473688328077] - - [-0.05607105449779142, -0.08896207276035666, 0.27638225397521243, -0.2371125582838589, - 0.07372294122306285] - - [-0.007391294007753122, -0.048741797963875705, -0.6291239733858526, 0.46816276521577677, - 0.09251699239093385] - - [-0.007110224931878467, -0.05623317735898056, -0.36606658567620365, -0.013297798115225407, - 0.6491033177492604] - - [0.002335515008556511, -0.021561151264484414, 0.09096243479437888, -0.38438823493062646, - 0.6616477207948602] - type: classic diff --git a/examples/PythonOptimizations.ipynb b/examples/PythonOptimizations.ipynb deleted file mode 100644 index 386c4d339a122e7cad01df2a0be4a8152f21b165..0000000000000000000000000000000000000000 --- a/examples/PythonOptimizations.ipynb +++ /dev/null @@ -1,394 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from timeit import default_timer as timer\n", - "import random\n", - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "*** With setdefault ***\n", - "Mean time = 2.9573e-07 +/- 5.1021e-07 sigma\n", - "{33: 969, 23: 1030, 10: 1002, 54: 990, 37: 1055, 28: 983, 34: 964, 25: 1023, 55: 1016, 46: 958, 17: 979, 0: 1003, 98: 1025, 19: 977, 66: 1002, 73: 979, 42: 1038, 52: 986, 80: 1007, 45: 1044, 62: 942, 40: 1001, 77: 996, 26: 995, 11: 971, 97: 985, 59: 1024, 63: 939, 43: 1036, 88: 977, 47: 967, 44: 964, 93: 967, 51: 962, 69: 1003, 12: 988, 81: 1008, 82: 962, 61: 1003, 30: 985, 3: 1017, 79: 975, 29: 979, 35: 989, 31: 1019, 72: 1017, 78: 977, 100: 977, 7: 947, 91: 973, 90: 966, 38: 960, 20: 927, 8: 983, 75: 999, 92: 1020, 99: 1030, 64: 976, 57: 1030, 86: 1041, 16: 941, 39: 1017, 94: 996, 18: 940, 13: 1024, 27: 990, 53: 1042, 68: 952, 2: 1031, 85: 984, 21: 1009, 36: 1009, 71: 990, 84: 1022, 49: 1010, 60: 990, 70: 967, 9: 949, 67: 989, 87: 980, 74: 970, 32: 983, 89: 999, 96: 998, 50: 991, 56: 1010, 76: 1001, 95: 964, 24: 1004, 14: 950, 83: 1053, 5: 988, 22: 1043, 65: 980, 6: 967, 15: 966, 41: 922, 1: 960, 48: 958, 58: 955, 4: 999}\n", - "*** With if syntax ***\n", - "Mean time = 2.9544e-07 +/- 5.2105e-07 sigma\n", - "{33: 969, 23: 1030, 10: 1002, 54: 990, 37: 1055, 28: 983, 34: 964, 25: 1023, 55: 1016, 46: 958, 17: 979, 0: 1003, 98: 1025, 19: 977, 66: 1002, 73: 979, 42: 1038, 52: 986, 80: 1007, 45: 1044, 62: 942, 40: 1001, 77: 996, 26: 995, 11: 971, 97: 985, 59: 1024, 63: 939, 43: 1036, 88: 977, 47: 967, 44: 964, 93: 967, 51: 962, 69: 1003, 12: 988, 81: 1008, 82: 962, 61: 1003, 30: 985, 3: 1017, 79: 975, 29: 979, 35: 989, 31: 1019, 72: 1017, 78: 977, 100: 977, 7: 947, 91: 973, 90: 966, 38: 960, 20: 927, 8: 983, 75: 999, 92: 1020, 99: 1030, 64: 976, 57: 1030, 86: 1041, 16: 941, 39: 1017, 94: 996, 18: 940, 13: 1024, 27: 990, 53: 1042, 68: 952, 2: 1031, 85: 984, 21: 1009, 36: 1009, 71: 990, 84: 1022, 49: 1010, 60: 990, 70: 967, 9: 949, 67: 989, 87: 980, 74: 970, 32: 983, 89: 999, 96: 998, 50: 991, 56: 1010, 76: 1001, 95: 964, 24: 1004, 14: 950, 83: 1053, 5: 988, 22: 1043, 65: 980, 6: 967, 15: 966, 41: 922, 1: 960, 48: 958, 58: 955, 4: 999}\n" - ] - } - ], - "source": [ - "N = 100000\n", - "d1 = {}\n", - "d2 = {}\n", - "duration1 = np.zeros((N,), dtype=np.float32)\n", - "duration2 = np.zeros((N,), dtype=np.float32)\n", - "str = \"Mean time = {0:.4e} +/- {1:.4e} sigma\"\n", - "for i in range(N):\n", - " k = random.randint(0,100)\n", - " start = timer()\n", - " d1[k] = d1.setdefault(k, 0) + 1\n", - " duration1[i] = timer() - start\n", - " start = timer()\n", - " d2[k] = d2[k] + 1 if k in d2 else 1\n", - " duration2[i] = timer() - start\n", - "\n", - "print(\"*** With setdefault ***\")\n", - "print(str.format(np.mean(duration1), np.std(duration1)))\n", - "print(d1)\n", - "print(\"*** With if syntax ***\")\n", - "print(str.format(np.mean(duration2), np.std(duration2)))\n", - "print(d2)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "__global__ void multiply_them(float *dest, float *a, float *b)\n", - "{\n", - " const int i = threadIdx.x;\n", - " dest[i] = a[i] * b[i];\n", - "}\n", - "\n", - "[-2.90137202e-01 2.81293893e+00 -1.65957522e+00 -8.62088725e-02\n", - " 1.45804667e+00 7.99023032e-01 8.37303638e-01 2.03320041e-01\n", - " -1.78530657e+00 -9.88828689e-02 2.83610914e-02 -3.73530895e-01\n", - " 1.13282132e+00 3.41161788e-01 7.03967333e-01 2.51203799e+00\n", - " -1.10995814e-01 -2.47637033e-01 4.86121893e-01 -5.22908807e-01\n", - " 2.42040649e-01 3.50897670e-01 -2.33534321e-01 -5.71392417e-01\n", - " 2.94612437e-01 8.51076543e-01 -1.22819483e-01 -1.12457033e-02\n", - " 7.62222052e-01 -5.62664986e-01 -2.81204749e-02 2.15141201e+00\n", - " -2.52846658e-01 -4.59794961e-02 -2.25618288e-01 -2.16486081e-02\n", - " 1.80242336e+00 1.98668197e-01 1.38681874e-01 -8.27464104e-01\n", - " 2.84924650e+00 4.41990757e+00 7.45217443e-01 2.79382646e-01\n", - " -3.47226970e-02 -3.42106796e-03 -2.03399825e+00 1.97560683e-01\n", - " 1.39831769e+00 -8.06550503e-01 -1.33297205e+00 1.37708103e-02\n", - " -4.00247842e-01 1.86116919e-02 2.44872691e-03 3.97552028e-02\n", - " -3.61032963e+00 -5.08877039e-01 3.09200644e-01 -2.52947181e-01\n", - " -1.45006254e-01 -2.06694026e-02 -6.71102941e-01 -2.49164805e-01\n", - " -2.45076999e-01 -8.83047581e-02 -2.77056009e-01 -3.63603652e-01\n", - " 9.13712531e-02 1.50326788e-01 -1.89215928e-01 6.49247885e-01\n", - " -1.04680789e+00 4.51940441e+00 -4.10190582e-01 -1.03717482e+00\n", - " -2.83955693e-01 2.13240623e-01 -4.06043559e-01 1.64782095e+00\n", - " 3.88930738e-02 1.79433972e-01 -1.63999215e-01 8.21388125e-01\n", - " 3.96741897e-01 -1.78203881e+00 -7.89099187e-02 -2.08030403e-01\n", - " -1.67499959e+00 -6.03813231e-02 9.04122651e-01 2.57910769e-02\n", - " -2.13610873e-01 1.05494165e+00 1.07709356e-02 -4.04108614e-02\n", - " -1.21986246e+00 3.52327973e-01 9.47596207e-02 -8.17048013e-01\n", - " 4.55845296e-01 1.14165060e-01 -8.36074054e-01 -2.73001790e+00\n", - " -2.25733072e-02 1.01752472e+00 1.58793926e-01 -3.07355216e-03\n", - " 3.39909703e-01 3.54566932e-01 4.76458110e-03 -2.74281472e-01\n", - " -4.90250558e-01 -5.93070447e-01 4.16583568e-01 1.40949559e+00\n", - " -6.85005546e-01 5.71568191e-01 2.63672054e-01 -2.65214413e-01\n", - " -1.82554388e+00 -2.56274521e-01 -2.20750004e-01 2.96699733e-01\n", - " -6.49191618e-01 -4.23787624e-01 1.40397280e-01 5.71154011e-03\n", - " -1.53047368e-01 -1.18402898e+00 8.88164192e-02 -7.80049741e-01\n", - " 1.22469738e-01 5.82156956e-01 -2.78263122e-01 5.70335388e+00\n", - " 2.33998346e+00 9.56273079e-01 1.51689303e+00 -4.10727739e-01\n", - " 4.94410247e-01 -3.66233498e-01 7.14528918e-01 2.38090664e-01\n", - " -6.46302760e-01 -3.08008194e-01 -3.49969387e-01 1.53435739e-02\n", - " 5.77413812e-02 3.72533381e-01 1.98260975e+00 -7.76899280e-03\n", - " -1.54382363e-01 -1.86449081e-01 -9.56342891e-02 1.03035802e-02\n", - " 1.14140980e-01 1.41981363e+00 -7.38705873e-01 -2.08745885e+00\n", - " -6.28826141e-01 1.02032393e-01 -7.70327747e-01 5.62456894e+00\n", - " -2.95871317e-01 1.26501453e+00 4.17780161e-01 8.68652642e-01\n", - " -4.87591237e-01 6.19750731e-02 -1.26040816e+00 -3.43194783e-01\n", - " 1.27273810e+00 -3.55367869e-01 2.32648347e-02 2.89628506e-01\n", - " -1.51091516e-01 2.83231330e-03 -1.51034407e-02 1.76298320e+00\n", - " -3.59570235e-01 2.01595259e+00 -7.87402838e-02 4.81955826e-01\n", - " -1.40068781e+00 2.83799553e-03 6.27174973e-01 3.14519048e-01\n", - " -1.10712957e+00 -3.53843659e-01 -6.35562837e-01 4.04969931e-01\n", - " -1.65314469e-02 4.08839643e-01 8.27084303e-01 3.12124312e-01\n", - " -4.19728532e-02 -4.32954282e-01 5.92173636e-01 -1.95017815e+00\n", - " 3.28963660e-02 6.78022718e-03 -1.16085088e+00 5.09182066e-02\n", - " -6.12896085e-01 -8.15577134e-02 1.12161350e+00 -3.40709865e-01\n", - " 2.52548099e-01 -4.65507209e-01 5.91823518e-01 -7.46792078e-01\n", - " 1.19965337e-01 6.05180681e-01 -5.09674013e-01 2.71683186e-01\n", - " 2.30722860e-01 -1.65039837e-01 -8.05439278e-02 1.71006903e-01\n", - " -2.81729937e-01 1.10326950e-02 3.20048153e-01 9.83216614e-03\n", - " 1.53846651e-01 1.16461468e+00 -4.88103539e-01 -2.46520080e-02\n", - " -7.18142092e-02 -1.67339086e-03 -2.42161244e-01 2.67475009e-01\n", - " -1.32814407e+00 -5.36984839e-02 1.15024351e-01 -1.35336888e+00\n", - " -4.01394248e-01 2.28310853e-01 2.85696723e-02 -9.75638449e-01\n", - " 1.79381263e+00 1.34870076e+00 -9.75736082e-01 -2.56683826e-01\n", - " -9.24404740e-01 1.18486941e+00 -1.60593867e-01 5.32781780e-01\n", - " -1.61111280e-01 -5.70979357e-01 2.48478189e-01 -5.70544958e-01\n", - " -3.36045325e-02 -1.70751661e-01 -7.83387959e-01 -3.28783333e-01\n", - " 6.68492764e-02 -4.55635548e-01 6.78718448e-01 1.61884940e+00\n", - " 1.40411711e+00 1.68428612e+00 -1.77249038e+00 -9.48907316e-01\n", - " 1.18341064e+00 -5.30112609e-02 -1.22148085e+00 5.62596917e-01\n", - " 1.31391573e+00 1.84780562e+00 5.45549512e-01 1.03463089e+00\n", - " -7.32520103e-01 3.38242576e-02 -6.29517257e-01 6.84408307e-01\n", - " -2.80194193e-01 4.18214053e-01 -2.41577148e+00 -2.93253827e+00\n", - " 9.50718462e-01 2.36972594e+00 4.81406689e-01 1.71889886e-02\n", - " 6.07256055e-01 -2.35717386e-01 -2.49700022e+00 6.08527958e-01\n", - " -7.02820182e-01 -1.22066826e-01 6.92340672e-01 9.00277853e-01\n", - " -1.30328491e-01 -4.41209674e-02 -9.21233058e-01 1.37919143e-01\n", - " 3.67532313e-01 3.77332382e-02 2.87247807e-01 2.75621843e+00\n", - " 7.48364270e-01 -3.02746415e-01 1.44414037e-01 5.80033548e-02\n", - " 1.95701897e-01 -1.33819908e-01 1.95749756e-02 9.36418235e-01\n", - " 1.13439392e-02 -3.80111992e-01 -9.90576968e-02 -5.11335442e-03\n", - " -7.68416934e-03 -2.29034567e+00 -2.59990782e-01 -1.78645715e-01\n", - " 1.65659058e+00 -2.18677855e+00 1.03389049e+00 1.44531997e-02\n", - " -3.51684600e-01 4.83583333e-03 1.80972859e-01 2.64298506e-02\n", - " -2.43892953e-01 -2.05088049e-01 -3.25786471e-01 6.42316818e-01\n", - " 1.44556820e-01 9.11835134e-02 1.94504070e+00 -5.24064781e-05\n", - " -2.08403915e-01 -1.54737011e-01 -1.55257428e+00 7.24277273e-02\n", - " -8.63651395e-01 1.59108377e+00 5.03697515e-01 -3.29254329e-01\n", - " -8.90930295e-02 1.14660770e-01 -9.05855417e-01 8.15455243e-03\n", - " 1.48153394e-01 -2.29722723e-01 -8.32916439e-01 -6.75686240e-01\n", - " 6.29307210e-01 -5.49214065e-01 -8.63798857e-02 -2.25813970e-01\n", - " 1.34750354e+00 -1.27279890e+00 1.71834212e-02 -9.28580642e-01\n", - " -4.82821971e-01 -3.34665596e-01 -5.94868183e-01 -1.29932821e-01\n", - " -1.92791373e-02 -1.49232015e-01 1.34774446e+00 1.19024850e-01\n", - " -1.20160818e-01 -1.26262501e-01 1.97318313e-03 1.36541653e+00\n", - " 1.02985278e-01 -2.10293263e-01 2.37391043e+00 2.78081983e-01\n", - " 1.06245232e+00 -2.89069340e-02 -2.64283836e-01 -3.76625746e-01\n", - " 2.17229322e-01 4.31653678e-01 3.62828434e-01 5.05672574e-01\n", - " 7.73309097e-02 2.52127171e+00 -5.13727009e-01 -5.77548921e-01\n", - " -1.68320909e-01 4.10304099e-01 2.59571910e-01 2.76594549e-01\n", - " 1.45417917e+00 4.71246615e-02 -9.45373952e-01 -2.64028404e-02\n", - " -1.45785689e+00 -2.15390992e+00 2.60196701e-02 -1.00632882e+00\n", - " -2.80741006e-01 -1.05663754e-01 -1.99056208e-01 1.07909453e+00]\n" - ] - } - ], - "source": [ - "import pycuda.autoinit\n", - "import pycuda.driver as drv\n", - "import numpy\n", - "from pycuda.compiler import SourceModule\n", - "\n", - "module = \"\"\"\n", - "__global__ void multiply_them(float *dest, float *a, float *b)\n", - "{\n", - " const int i = threadIdx.x;\n", - " dest[i] = a[i] * b[i];\n", - "}\n", - "\"\"\"\n", - "print(module)\n", - "\n", - "mod = SourceModule(module, nvcc=\"nvcc\", options=[\"-ccbin=/usr/bin/clang-3.8\"])\n", - "\n", - "multiply_them = mod.get_function(\"multiply_them\")\n", - "\n", - "a = numpy.random.randn(400).astype(numpy.float32)\n", - "b = numpy.random.randn(400).astype(numpy.float32)\n", - "\n", - "dest = numpy.zeros_like(a)\n", - "multiply_them(\n", - " drv.Out(dest), drv.In(a), drv.In(b),\n", - " block=(400,1,1), grid=(1,1))\n", - "\n", - "print (dest)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "ename": "CompileError", - "evalue": "nvcc preprocessing of /tmp/tmpn_14m8_h.cu failed\n[command: nvcc --preprocess -arch sm_50 -I/home/arrivault/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/cuda /tmp/tmpn_14m8_h.cu --compiler-options -P]\n[stderr:\nb\"ERROR: No supported gcc/g++ host compiler found, but clang-3.8 is available.\\n Use 'nvcc -ccbin clang-3.8' to use that instead.\\n\"]", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mCompileError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-4-1815e70115ee>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpycuda\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcurandom\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mrand\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mcurand\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0ma_gpu\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcurand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m50\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[0m\u001b[1;32m 8\u001b[0m \u001b[0mb_gpu\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcurand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m50\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[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/curandom.py\u001b[0m in \u001b[0;36mrand\u001b[0;34m(shape, dtype, stream)\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0mdest\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mPOW_2_M32\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 209\u001b[0m \"\"\",\n\u001b[0;32m--> 210\u001b[0;31m \"md5_rng_float\")\n\u001b[0m\u001b[1;32m 211\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mdtype\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 212\u001b[0m func = get_elwise_kernel(\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/elementwise.py\u001b[0m in \u001b[0;36mget_elwise_kernel\u001b[0;34m(arguments, operation, name, keep, options, **kwargs)\u001b[0m\n\u001b[1;32m 159\u001b[0m \"\"\"\n\u001b[1;32m 160\u001b[0m func, arguments = get_elwise_kernel_and_types(\n\u001b[0;32m--> 161\u001b[0;31m arguments, operation, name, keep, options, **kwargs)\n\u001b[0m\u001b[1;32m 162\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/elementwise.py\u001b[0m in \u001b[0;36mget_elwise_kernel_and_types\u001b[0;34m(arguments, operation, name, keep, options, use_range, **kwargs)\u001b[0m\n\u001b[1;32m 145\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 146\u001b[0m mod = module_builder(arguments, operation, name,\n\u001b[0;32m--> 147\u001b[0;31m keep, options, **kwargs)\n\u001b[0m\u001b[1;32m 148\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 149\u001b[0m \u001b[0mfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/elementwise.py\u001b[0m in \u001b[0;36mget_elwise_module\u001b[0;34m(arguments, operation, name, keep, options, preamble, loop_prep, after_loop)\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[0;34m\"after_loop\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mafter_loop\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 74\u001b[0m },\n\u001b[0;32m---> 75\u001b[0;31m options=options, keep=keep)\n\u001b[0m\u001b[1;32m 76\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/compiler.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs)\u001b[0m\n\u001b[1;32m 289\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 290\u001b[0m cubin = compile(source, nvcc, options, keep, no_extern_c,\n\u001b[0;32m--> 291\u001b[0;31m arch, code, cache_dir, include_dirs)\n\u001b[0m\u001b[1;32m 292\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 293\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpycuda\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdriver\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmodule_from_buffer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/compiler.py\u001b[0m in \u001b[0;36mcompile\u001b[0;34m(source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs, target)\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"-I\"\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 254\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 255\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mcompile_plain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeep\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnvcc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcache_dir\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 256\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 257\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mCudaModule\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobject\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/compiler.py\u001b[0m in \u001b[0;36mcompile_plain\u001b[0;34m(source, options, keep, nvcc, cache_dir, target)\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'#include'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msource\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 78\u001b[0;31m \u001b[0mchecksum\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpreprocess_source\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnvcc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\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 79\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0mchecksum\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/compiler.py\u001b[0m in \u001b[0;36mpreprocess_source\u001b[0;34m(source, options, nvcc)\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpycuda\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdriver\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mCompileError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 54\u001b[0m raise CompileError(\"nvcc preprocessing of %s failed\" % source_path,\n\u001b[0;32m---> 55\u001b[0;31m cmdline, stderr=stderr)\n\u001b[0m\u001b[1;32m 56\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0;31m# sanity check\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mCompileError\u001b[0m: nvcc preprocessing of /tmp/tmpn_14m8_h.cu failed\n[command: nvcc --preprocess -arch sm_50 -I/home/arrivault/.virtualenvs/splearn-pycuda/lib/python3.6/site-packages/pycuda/cuda /tmp/tmpn_14m8_h.cu --compiler-options -P]\n[stderr:\nb\"ERROR: No supported gcc/g++ host compiler found, but clang-3.8 is available.\\n Use 'nvcc -ccbin clang-3.8' to use that instead.\\n\"]" - ] - } - ], - "source": [ - "import pycuda.gpuarray as gpuarray\n", - "import pycuda.driver as cuda\n", - "import pycuda.autoinit\n", - "import numpy\n", - "from pycuda.curandom import rand as curand\n", - "\n", - "a_gpu = curand((50,))\n", - "b_gpu = curand((50,))\n", - "\n", - "from pycuda.elementwise import ElementwiseKernel\n", - "lin_comb = ElementwiseKernel(\n", - " \"float a, float *x, float b, float *y, float *z\",\n", - " \"z[i] = a*x[i] + b*y[i]\",\n", - " \"linear_combination\")\n", - "\n", - "c_gpu = gpuarray.empty_like(a_gpu)\n", - "lin_comb(5, a_gpu, 6, b_gpu, c_gpu)\n", - "\n", - "import numpy.linalg as la\n", - "assert la.norm((c_gpu - (5*a_gpu+6*b_gpu)).get()) < 1e-5" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "from scipy.linalg import svd\n", - "import pycuda.autoinit\n", - "import pycuda.gpuarray as gpuarray\n", - "d = 50\n", - "A = np.asarray(np.random.randint(1, 10,(d, d)), dtype=np.float32)\n", - "a_gpu = gpuarray.to_gpu(A)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.19 ms ± 1.49 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)\n" - ] - } - ], - "source": [ - "%timeit -n3 [u, s, v] = svd(A)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3.76 ms ± 1.95 ms per loop (mean ± std. dev. of 7 runs, 3 loops each)\n" - ] - } - ], - "source": [ - "%timeit -n3 [u, s, v] = np.linalg.svd(A)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "ename": "CUSOLVER_STATUS_INTERNAL_ERROR", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mCUSOLVER_STATUS_INTERNAL_ERROR\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-9-3d7440e3c764>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \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\"-n3 u_gpu, s_gpu, vh_gpu = linalg.svd(a_gpu, 'S', 'S', 'cusolver')\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2093\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'local_ns'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getframe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack_depth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf_locals\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2094\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2095\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2096\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m<decorator-gen-61>\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell, local_ns)\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 187\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell, local_ns)\u001b[0m\n\u001b[1;32m 1100\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1102\u001b[0;31m \u001b[0mall_runs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtimer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1103\u001b[0m \u001b[0mbest\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall_runs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1104\u001b[0m \u001b[0mworst\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall_runs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib/python3.6/timeit.py\u001b[0m in \u001b[0;36mrepeat\u001b[0;34m(self, repeat, number)\u001b[0m\n\u001b[1;32m 204\u001b[0m \u001b[0mr\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[1;32m 205\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 206\u001b[0;31m \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimeit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 207\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, number)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0mgc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 160\u001b[0;31m \u001b[0mtiming\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minner\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 161\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mgcold\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m<magic-timeit>\u001b[0m in \u001b[0;36minner\u001b[0;34m(_it, _timer)\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/build/scikit-cuda/skcuda/linalg.py\u001b[0m in \u001b[0;36msvd\u001b[0;34m(a_gpu, jobu, jobvt, lib)\u001b[0m\n\u001b[1;32m 467\u001b[0m \u001b[0mldu\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvh_gpu\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgpudata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mldvt\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 468\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mWork\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgpudata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mLwork\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrwork\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 469\u001b[0;31m int(devInfo.gpudata))\n\u001b[0m\u001b[1;32m 470\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 471\u001b[0m \u001b[0;31m# Free working space:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/build/scikit-cuda/skcuda/cusolver.py\u001b[0m in \u001b[0;36mcusolverDnSgesvd\u001b[0;34m(handle, jobu, jobvt, m, n, a, lda, s, U, ldu, vt, ldvt, work, lwork, rwork, devInfo)\u001b[0m\n\u001b[1;32m 998\u001b[0m \u001b[0mldu\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mldvt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwork\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 999\u001b[0m lwork, int(rwork), int(devInfo))\n\u001b[0;32m-> 1000\u001b[0;31m \u001b[0mcusolverCheckStatus\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstatus\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1001\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1002\u001b[0m \u001b[0m_libcusolver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcusolverDnDgesvd_bufferSize\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrestype\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/build/scikit-cuda/skcuda/cusolver.py\u001b[0m in \u001b[0;36mcusolverCheckStatus\u001b[0;34m(status)\u001b[0m\n\u001b[1;32m 160\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mstatus\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 162\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mCUSOLVER_EXCEPTIONS\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstatus\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 163\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 164\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mCUSOLVER_ERROR\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mCUSOLVER_STATUS_INTERNAL_ERROR\u001b[0m: " - ] - } - ], - "source": [ - "%timeit -n3 u_gpu, s_gpu, vh_gpu = linalg.svd(a_gpu, 'S', 'S', 'cusolver')" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "ename": "CUSOLVERError", - "evalue": "CUSOLVER_STATUS_INTERNAL_ERROR", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mCUSOLVERError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-8-c960eb315819>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \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'-n3 u_cp, s_cp, v_cp = cp.linalg.svd(a_cp)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2093\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'local_ns'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getframe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack_depth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf_locals\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2094\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2095\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2096\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2097\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m<decorator-gen-61>\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell, local_ns)\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 187\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell, local_ns)\u001b[0m\n\u001b[1;32m 1100\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1101\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1102\u001b[0;31m \u001b[0mall_runs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtimer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1103\u001b[0m \u001b[0mbest\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall_runs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1104\u001b[0m \u001b[0mworst\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall_runs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/lib/python3.6/timeit.py\u001b[0m in \u001b[0;36mrepeat\u001b[0;34m(self, repeat, number)\u001b[0m\n\u001b[1;32m 204\u001b[0m \u001b[0mr\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[1;32m 205\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 206\u001b[0;31m \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimeit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 207\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, number)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0mgc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 160\u001b[0;31m \u001b[0mtiming\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minner\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 161\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mgcold\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m<magic-timeit>\u001b[0m in \u001b[0;36minner\u001b[0;34m(_it, _timer)\u001b[0m\n", - "\u001b[0;32m~/.virtualenvs/sksplearn/lib/python3.6/site-packages/cupy/linalg/decomposition.py\u001b[0m in \u001b[0;36msvd\u001b[0;34m(a, full_matrices, compute_uv)\u001b[0m\n\u001b[1;32m 254\u001b[0m \u001b[0mhandle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjob\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjob\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mptr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 255\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mptr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mu_ptr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvt_ptr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 256\u001b[0;31m workspace.data.ptr, buffersize, 0, dev_info.data.ptr)\n\u001b[0m\u001b[1;32m 257\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# dtype == 'd'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 258\u001b[0m \u001b[0mbuffersize\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcusolver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdgesvd_bufferSize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhandle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32mcupy/cuda/cusolver.pyx\u001b[0m in \u001b[0;36mcupy.cuda.cusolver.sgesvd\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mcupy/cuda/cusolver.pyx\u001b[0m in \u001b[0;36mcupy.cuda.cusolver.sgesvd\u001b[0;34m()\u001b[0m\n", - "\u001b[0;32mcupy/cuda/cusolver.pyx\u001b[0m in \u001b[0;36mcupy.cuda.cusolver.check_status\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mCUSOLVERError\u001b[0m: CUSOLVER_STATUS_INTERNAL_ERROR" - ] - } - ], - "source": [ - "%timeit -n3 u_cp, s_cp, v_cp = cp.linalg.svd(a_cp)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/examples/performances_calculation.py b/examples/performances_calculation.py deleted file mode 100644 index 771fe0ba2c4f3c544921c60543d9b304c964b29c..0000000000000000000000000000000000000000 --- a/examples/performances_calculation.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- - -''' -Created on 20 févr. 2018 - -@author: arrivault -''' -from timeit import default_timer as timer - -from splearn import Spectral -from splearn.tests.datasets.get_dataset_path import get_dataset_path -from splearn.datasets.base import load_data_sample - -def launch_fit(X, version='classic', partial=True, sparse=True, smooth_method='none'): - param = "****** {:s} - partial = {:b} - sparse = {:b}, {:s} *****".format(version, partial, sparse, smooth_method) - print(param) - - sp1 = Spectral(version=version, partial=partial, sparse=sparse, smooth_method=smooth_method) - start = timer() - sp1 = sp1.fit(X) - duration = timer() - start - print("Unoptimized : " + str(duration)) - -# sp2 = Spectral(version=version, partial=partial, sparse=sparse, smooth_method=smooth_method) -# start = timer() -# sp2 = sp2.fit(X) -# duration = timer() - start -# print("Optimized : " + str(duration)) -# -# if sp1.hankel == sp2.hankel: -# print("Same result.") -# else: -# print("The result is different", file=sys.stderr) - -def test_fit(): - adr = get_dataset_path("3.pautomac_light.train") - data = load_data_sample(adr=adr) - X = data.data - param = {'version':['classic', 'prefix', 'suffix', 'factor'], 'partial':[True, False], - 'sparse':[True, False], 'smooth_method':['none','trigram']} - for version in param['version']: -# for partial in param['partial']: - for sparse in param['sparse']: - for smooth_method in param['smooth_method']: - launch_fit(X, version=version, partial=True, sparse=sparse, smooth_method=smooth_method) - -if __name__ == '__main__': - test_fit() diff --git a/examples/simple_automata.json b/examples/simple_automata.json deleted file mode 100644 index ab271a879ea057c6064636ba019001158b41a863..0000000000000000000000000000000000000000 --- a/examples/simple_automata.json +++ /dev/null @@ -1 +0,0 @@ -{"automaton": {"final": {"numpy.ndarray": {"values": [0.15, 0.9], "dtype": "float64"}}, "initial": {"numpy.ndarray": {"values": [0.5, 0.8], "dtype": "float64"}}, "transitions": [{"numpy.ndarray": {"values": [[0.5, 0.15], [0.9, 0]], "dtype": "float64"}}, {"numpy.ndarray": {"values": [[0, 0], [0, -0.15]], "dtype": "float64"}}], "type": "classic", "nbS": 2, "nbL": 2}} diff --git a/examples/simple_automata.json.gv b/examples/simple_automata.json.gv deleted file mode 100644 index 0fd62e2d59b54c471ed4736cd2b9456c714a1897..0000000000000000000000000000000000000000 --- a/examples/simple_automata.json.gv +++ /dev/null @@ -1,15 +0,0 @@ -//Simple Automata -digraph { - 0 [label="0 -______ -> 0.50 -0.15 >"] - 1 [label="1 -______ -> 0.80 -0.90 >"] - 0 -> 0 [label="0:0.50"] - 0 -> 1 [label="0:0.15"] - 1 -> 0 [label="0:0.90"] - 1 -> 1 [label="1:-0.15"] -} diff --git a/examples/simple_automata.json.gv.pdf b/examples/simple_automata.json.gv.pdf deleted file mode 100644 index 9253c0b86d51eaa9a3f4014c4c4202bbf69c7aa4..0000000000000000000000000000000000000000 Binary files a/examples/simple_automata.json.gv.pdf and /dev/null differ diff --git a/examples/simple_automata.yaml b/examples/simple_automata.yaml deleted file mode 100644 index b85b6aec2fdc2ffe36ac8799948651b8c8c456ef..0000000000000000000000000000000000000000 --- a/examples/simple_automata.yaml +++ /dev/null @@ -1,23 +0,0 @@ -automaton: - final: - numpy.ndarray: - dtype: float64 - values: [0.15, 0.9] - initial: - numpy.ndarray: - dtype: float64 - values: [0.5, 0.8] - nbL: 2 - nbS: 2 - transitions: - - numpy.ndarray: - dtype: float64 - values: - - [0.5, 0.15] - - [0.9, 0] - - numpy.ndarray: - dtype: float64 - values: - - [0, 0] - - [0, -0.15] - type: classic diff --git a/examples/simple_automata.yaml.gv b/examples/simple_automata.yaml.gv deleted file mode 100644 index 0fd62e2d59b54c471ed4736cd2b9456c714a1897..0000000000000000000000000000000000000000 --- a/examples/simple_automata.yaml.gv +++ /dev/null @@ -1,15 +0,0 @@ -//Simple Automata -digraph { - 0 [label="0 -______ -> 0.50 -0.15 >"] - 1 [label="1 -______ -> 0.80 -0.90 >"] - 0 -> 0 [label="0:0.50"] - 0 -> 1 [label="0:0.15"] - 1 -> 0 [label="0:0.90"] - 1 -> 1 [label="1:-0.15"] -} diff --git a/examples/simple_automata.yaml.gv.pdf b/examples/simple_automata.yaml.gv.pdf deleted file mode 100644 index 9253c0b86d51eaa9a3f4014c4c4202bbf69c7aa4..0000000000000000000000000000000000000000 Binary files a/examples/simple_automata.yaml.gv.pdf and /dev/null differ diff --git a/examples/svd_tests.py b/examples/svd_tests.py deleted file mode 100644 index bcc28f24b03e6dcaa40a520ef3bd8155f664bdba..0000000000000000000000000000000000000000 --- a/examples/svd_tests.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- - -''' -Created on 20 févr. 2018 - -@author: arrivault -''' -import sys -from timeit import default_timer as timer -import numpy as np - -def test_svd(): - d = 1000 - A = np.asarray(np.random.randint(1, 10,(d, d)), dtype=np.float32) - - # scipy - print("\n****************** Scipy") - from scipy.linalg import svd as sc_svd - start = timer() - u_sc, s_sc, v_sc = sc_svd(A) - duration = timer() - start - print("SVD scipy : " + str(duration)) - print(s_sc) - print(type(s_sc)) - - # cupy - print("\n****************** Cupy") - import cupy as cp - from cupy.linalg import svd as cp_svd - start = timer() - A_cp = cp.asarray(A) - u_cp, s_cp, v_cp = cp_svd(A_cp) - u_cp, s_cp, v_cp = u_cp.get(), s_cp.get(), v_cp.get() - duration = timer() - start - print("SVD cupy : " + str(duration)) - print(s_cp) - print(A_cp.device) - print(type(s_cp)) - - # scikit-cuda - print("\n****************** scikit-cuda") - import pycuda.autoinit - import pycuda.gpuarray as gpuarray - #import ctypes - #ctypes.CDLL('libgomp.so.1', mode=ctypes.RTLD_GLOBAL) - from skcuda import linalg as sk_linalg - start = timer() - sk_linalg.init() - A_sk = gpuarray.to_gpu(A) - u_sk, s_sk, vh_sk = sk_linalg.svd(A_sk, jobu='S', jobvt='S', lib='cusolver') - u_sk, s_sk, v_sk = u_sk.get_async(), s_sk.get_async(), vh_sk.get_async() - duration = timer() - start - print("SVD skcuda : " + str(duration)) - print(s_sk) - print(type(s_sk)) - -# # tensorflow -# print("\n****************** tensorflow") -# import tensorflow as tf -# start = timer() -# with tf.device("/cpu:0"): -# s_tf, u_tf, v_tf = tf.svd(A, compute_uv=True) -# s_tf, u_tf, v_tf = tf.Session().run(s_tf), tf.Session().run(u_tf), tf.Session().run(v_tf) -# duration = timer() - start -# print("SVD tensorflow CPU : " + str(duration)) -# print(s_tf) -# print(type(s_tf)) -# print() -# start = timer() -# with tf.device("/gpu:0"): -# s_tf, u_tf, v_tf = tf.svd(A, compute_uv=True) -# s_tf, u_tf, v_tf = tf.Session().run(s_tf), tf.Session().run(u_tf), tf.Session().run(v_tf) -# duration = timer() - start -# print("SVD tensorflow GPU : " + str(duration)) -# print(s_tf) -# print(type(s_tf)) - - # Theano - print("\n****************** theano") - from theano import function, shared, tensor, config - import theano.tensor.nlinalg as th_linalg - x = tensor.dmatrix('x') - u, s, v = th_linalg.svd(x) - f = function([x], (u, s, v)) - start = timer() - u_th, s_th, v_th = f(A) - duration = timer() - start - -# x = shared(np.asarray(A, config.floatX)) -# f = function([], th_linalg.svd(x)) -# start = timer() -# u_th, s_th, v_th = f() -# duration = timer() - start - - print("SVD theano : " + str(duration)) - print(s_th) - print(type(s_th)) - - -if __name__ == '__main__': - test_svd() diff --git a/splearn/hankel.py b/splearn/hankel.py index 24dc0cf6460e651415b87b0c69a1bbaed34e885f..133f85a98b341e5f0ea424ab798970e66bd90d3b 100644 --- a/splearn/hankel.py +++ b/splearn/hankel.py @@ -40,6 +40,8 @@ from __future__ import division, print_function import scipy.sparse as sps import scipy.sparse.linalg as lin import numpy as np +from numpy.linalg import svd, pinv +from sklearn.utils.extmath import randomized_svd as sk_svd class Hankel(object): """ A Hankel instance , compute the list of Hankel matrices @@ -61,6 +63,9 @@ class Hankel(object): :param boolean partial: (default value = False) build of partial :param boolean sparse: (default value = False) True if Hankel matrix is sparse + :param boolean full_svd_calculation: (default value = False) if True the entire SVD is calculated + for building hankel matrix. Else it is done by the sklearn random algorithm only for the greatest + k=rank eigenvalues. :param boolean mode_quiet: (default value = False) True for no output message. :param list lhankel: list of all Hankel matrices. At least one of the two parameters @@ -86,11 +91,12 @@ class Hankel(object): self, sample_instance=None, lrows=[], lcolumns=[], version="classic", partial=False, - sparse=False, mode_quiet=False, lhankel=None): + sparse=False, full_svd_calculation=False, mode_quiet=False, lhankel=None): self.version = version self.partial = partial self.sparse = sparse + self.full_svd__calculation = full_svd_calculation self.build_from_sample = True if sample_instance is not None: # Size of the alphabet @@ -363,24 +369,19 @@ class Hankel(object): "the smaller dimension of the Hankel Matrix (" + str(matrix_shape) + ")") if not self.sparse: - try: - import theano.tensor as T - from theano import function - import theano.tensor.nlinalg as th_linalg - x = T.dmatrix('x') - u, s, v = th_linalg.svd(x) - svd = function([x], (u, s, v)) - except : - from scipy.linalg import svd hankel = self.lhankel[0] - [u, s, v] = svd(hankel) - u = u[:, :rank] - v = v[:rank, :] - # ds = np.zeros((rank, rank), dtype=complex) - ds = np.diag(s[:rank]) - pis = np.linalg.pinv(v) + if self.full_svd__calculation: + [u, s, v] = svd(hankel) + u = u[:, :rank] + v = v[:rank, :] + # ds = np.zeros((rank, rank), dtype=complex) + ds = np.diag(s[:rank]) + else: + [u, s, v] = sk_svd(hankel, n_components=rank) + ds = np.diag(s) + pis = pinv(v) del v - pip = np.linalg.pinv(np.dot(u, ds)) + pip = pinv(np.dot(u, ds)) del u, ds init = np.dot(hankel[0, :], pis) term = np.dot(pip, hankel[:, 0]) @@ -390,18 +391,25 @@ class Hankel(object): trans.append(np.dot(pip, np.dot(hankel, pis))) else: - hankel = self.lhankel[0] - [u, s, v] = lin.svds(hankel, k=rank) + hankel = self.lhankel[0].tocsr() + if self.full_svd__calculation: + [u, s, v] = svd(hankel.A) + u = u[:, :rank] + v = v[:rank, :] + # ds = np.zeros((rank, rank), dtype=complex) + ds = np.diag(s[:rank]) + else: + [u, s, v] = lin.svds(hankel, k=rank) ds = np.diag(s) - pis = np.linalg.pinv(v) + pis = pinv(v) del v - pip = np.linalg.pinv(np.dot(u, ds)) + pip = pinv(np.dot(u, ds)) del u, ds init = hankel[0, :].dot(pis)[0, :] term = np.dot(pip, hankel[:, 0].toarray())[:, 0] trans = [] for x in range(self.nbL): - hankel = self.lhankel[x+1] + hankel = self.lhankel[x+1].tocsr() trans.append(np.dot(pip, hankel.dot(pis))) A = Automaton(nbL=self.nbL, nbS=rank, initial=init, final=term, diff --git a/splearn/spectral.py b/splearn/spectral.py index e2b734139c34e3db52275da4bab340e0473b5c8d..ce705d2d3df8d0d0ffbb25640715f223e01e9b65 100644 --- a/splearn/spectral.py +++ b/splearn/spectral.py @@ -77,6 +77,9 @@ class Spectral(BaseEstimator): of partial Hankel matrix :param boolean sparse: (default value = False) True if Hankel matrix is sparse + :param boolean full_svd_calculation: (default value = False) if True the entire SVD is calculated + for building hankel matrix. Else it is done by the sklearn random algorithm only for the greatest + k=rank eigenvalues. :param string smooth_method: (default value = "none") method of smoothing - 'trigram' the 3-Gram trigram dict @@ -115,11 +118,12 @@ class Spectral(BaseEstimator): """ def __init__(self, rank=5, lrows=7, lcolumns=7, version='classic', partial=True, - sparse=True, smooth_method='none', + sparse=True, full_svd_calculation=False, smooth_method='none', mode_quiet=False): self.version = version self.partial = partial self.sparse = sparse + self.full_svd_calculation = full_svd_calculation self.lrows = lrows self.lcolumns = lcolumns self.rank = rank @@ -219,6 +223,7 @@ class Spectral(BaseEstimator): lrows=self.lrows, lcolumns=self.lcolumns, version=self.version, partial=self.partial, sparse=self.sparse, + full_svd_calculation = self.full_svd_calculation, mode_quiet=self.mode_quiet) self._automaton = self._hankel.to_automaton(self.rank, self.mode_quiet) # for smooth option compute trigram dictionnary @@ -226,45 +231,8 @@ class Spectral(BaseEstimator): self.trigram = self._threegramdict(X.sample) return self - - def fit_opt(self, X, y=None): - """Fit the model in a optimal way - - - Input: - - :param SplearnArray X: object of shape [n_samples,n_features] - Training data - :param ndarray y: (default value = None) not used by Spectral estimator - numpy array of shape [n_samples] Target values - - - - Output: - - :returns: Spectral itself with an automaton attribute instanced - returns an instance of self. - :rtype: Spectral - - """ - check_array(X) - if not isinstance(X, SplearnArray): - self._hankel = None - self._automaton = None - return self - self.polulate_dictionnaries_opt(X) - self._hankel = Hankel(sample_instance=X, - lrows=self.lrows, lcolumns=self.lcolumns, - version=self.version, - partial=self.partial, sparse=self.sparse, - mode_quiet=self.mode_quiet) - self._automaton = self._hankel.to_automaton(self.rank, self.mode_quiet) - # for smooth option compute trigram dictionnary - if self.smooth == 1: - self.trigram = self._threegramdict(X.sample) - - return self - - def polulate_dictionnaries_opt(self, X): + def polulate_dictionnaries(self, X): """Populates the *sample*, *pref*, *suff*, *fact* dictionnaries of X - Input: @@ -275,10 +243,10 @@ class Spectral(BaseEstimator): """ if not isinstance(X, SplearnArray): return X - X.sample = {} # dictionary (word,count) - X.pref = {} # dictionary (prefix,count) - X.suff = {} # dictionary (suffix,count) - X.fact = {} # dictionary (factor,count) + dsample = {} # dictionary (word,count) + dpref = {} # dictionary (prefix,count) + dsuff = {} # dictionary (suffix,count) + dfact = {} # dictionary (factor,count) if self.partial: if isinstance(self.lrows, int): lrowsmax = self.lrows @@ -293,96 +261,7 @@ class Spectral(BaseEstimator): lcolumnsmax = self.lcolumns.__len__() version_columns_int = False lmax = lrowsmax + lcolumnsmax - #threads = [] - for line in range(X.shape[0]): - self._populate_a_word(X, line, lrowsmax, version_rows_int, - lcolumnsmax, version_columns_int, lmax) - else: - self._populate_a_word(X, line) - - - if self.version == "classic": - X.fact = {} - elif self.version == "suffix": - X.pref = {} - elif self.version == "prefix": - X.suff = {} - elif self.version == "factor": - X.suff = {} - X.pref = {} - def _populate_a_word(self, X, line, lrowsmax=None, version_rows_int=None, - lcolumnsmax=None, version_columns_int=None, lmax=None): - w = X[line, :] - w = w[w >= 0] - w = tuple([int(x) for x in w[0:]]) - X.sample[w] = X.sample.setdefault(w, 0) + 1 - if self.version == "prefix" or self.version == "classic": - # empty word treatment for prefixe, suffix, and factor dictionnaries - X.pref[()] = X.pref.setdefault((),0) + 1 - if self.version == "suffix" or self.version == "classic": - X.suff[()] = X.suff.setdefault((),0) + 1 - if (self.version == "factor" or self.version == "suffix" or - self.version == "prefix"): - X.fact[()] = X.fact.setdefault((),0) + len(w) + 1 - if self.partial: - for i in range(len(w)): - if self.version == "classic": - if ((version_rows_int and i + 1 <= lrowsmax) or - (not version_rows_int and w[:i + 1] in self.lrows)): - X.pref[w[:i + 1]] = X.pref.setdefault(w[:i + 1], 0) + 1 - if ((version_columns_int and i + 1 <= lcolumnsmax) or - (not version_columns_int and w[-( i + 1):] in self.lcolumns)): - X.suff[w[-(i + 1):]] = X.suff.setdefault(w[-(i + 1):], 0) + 1 - elif self.version == "prefix": - # dictionaries dpref is populated until - # lmax = lrows + lcolumns - # dictionaries dfact is populated until lcolumns - if (((version_rows_int or version_columns_int) and i + 1 <= lmax) or - (not version_rows_int and w[:i + 1] in self.lrows) or - (not version_columns_int and w[:i + 1] in self.lcolumns)): - X.pref[w[:i + 1]] = X.pref.setdefault(w[:i + 1], 0) + 1 - for j in range(i + 1, len(w) + 1): - if ((version_columns_int and (j - i) <= lmax) or - (not version_columns_int and w[i:j] in self.lcolumns)): - X.fact[w[i:j]] = X.fact.setdefault(w[i:j], 0) + 1 - elif self.version == "suffix": - if (((version_rows_int or version_columns_int) and i <= lmax) or - (not version_rows_int and w[-(i + 1):] in self.lrows) or - (not version_columns_int and w[-(i + 1):] in self.lcolumns)): - X.suff[w[-(i + 1):]] = X.suff.setdefault(w[-(i + 1):], 0) + 1 - for j in range(i + 1, len(w) + 1): - if ((version_rows_int and (j - i) <= lmax) or - (not version_rows_int and w[i:j] in self.lrows)): - X.fact[w[i:j]] = X.fact.setdefault(w[i:j], 0) + 1 - elif self.version == "factor": - for j in range(i + 1, len(w) + 1): - if (((version_rows_int or version_columns_int) and (j - i) <= lmax) or - (not version_rows_int and w[i:j] in self.lrows) or - (not version_columns_int and w[i:j] in self.lcolumns)): - X.fact[w[i:j]] = X.fact.setdefault(w[i:j], 0) + 1 - else: # not partial - for i in range(len(w)): - X.pref[w[:i + 1]] = X.pref.setdefault(w[:i + 1], 0) + 1 - X.suff[w[i:]] = X.suff.setdefault(w[i:], 0) + 1 - for j in range(i + 1, len(w) + 1): - X.fact[w[i:j]] = X.fact.setdefault(w[i:j], 0) + 1 - - def polulate_dictionnaries(self, X): - """Populates the *sample*, *pref*, *suff*, *fact* dictionnaries of X - - - Input: - - :param SplearnArray X: object of shape [n_samples,n_features] - Training data - - """ - if not isinstance(X, SplearnArray): - return X - dsample = {} # dictionary (word,count) - dpref = {} # dictionary (prefix,count) - dsuff = {} # dictionary (suffix,count) - dfact = {} # dictionary (factor,count) for line in range(X.shape[0]): w = X[line, :] w = w[w >= 0] @@ -398,20 +277,6 @@ class Spectral(BaseEstimator): dfact[()] = dfact[()] + len(w) + 1 if () in dfact else len( w) + 1 if self.partial: - if isinstance(self.lrows, int): - lrowsmax = self.lrows - version_rows_int = True - else: - version_rows_int = False - lrowsmax = self.lrows.__len__() - if isinstance(self.lcolumns, int): - lcolumnsmax = self.lcolumns - version_columns_int = True - else: - lcolumnsmax = self.lcolumns.__len__() - version_columns_int = False - lmax = lrowsmax + lcolumnsmax - for i in range(len(w)): if self.version == "classic": if (version_rows_int is True and