4747 "metadata" : {
4848 "id" : " ZHpg3aVXSeix"
4949 },
50- "execution_count" : null ,
50+ "execution_count" : 1 ,
5151 "outputs" : []
5252 },
5353 {
7878 "metadata" : {
7979 "id" : " BCToOdVdSONp"
8080 },
81- "execution_count" : null ,
81+ "execution_count" : 2 ,
8282 "outputs" : []
8383 },
8484 {
8585 "cell_type" : " code" ,
86- "execution_count" : null ,
86+ "execution_count" : 3 ,
8787 "metadata" : {
88- "id" : " 5ak3mn2hIsKo"
88+ "id" : " 5ak3mn2hIsKo" ,
89+ "outputId" : " 0d415d45-535a-4a2d-e757-f0c4a7a1efb0" ,
90+ "colab" : {
91+ "base_uri" : " https://localhost:8080/"
92+ }
8993 },
90- "outputs" : [],
94+ "outputs" : [
95+ {
96+ "output_type" : " stream" ,
97+ "name" : " stdout" ,
98+ "text" : [
99+ " [[-0.4937 -0.519 -0.2935 ... -0.1628 0.8361 0.531 ]\n " ,
100+ " [-1.0859 0.0087 -0.0661 ... -0.1706 1.0955 0.7075]\n " ,
101+ " [-0.4291 -0.3628 0.3393 ... 0.1813 0.2238 -0.2124]\n " ,
102+ " ...\n " ,
103+ " [-1.1089 -0.4564 -0.3024 ... 0.2075 1.2864 0.9066]\n " ,
104+ " [-0.8714 -0.5109 -0.1201 ... -0.072 1.3048 0.4372]\n " ,
105+ " [-1.6421 -0.6629 -0.2001 ... -0.2997 1.8579 1.5576]]\n "
106+ ]
107+ }
108+ ],
91109 "source" : [
92110 " def generate_host(cfg=PowerIterationConfig()):\n " ,
93111 " np.random.seed(42)\n " ,
150168 " print(lam_est_host)"
151169 ],
152170 "metadata" : {
153- "id" : " q0x0_p4pvAdD"
171+ "id" : " q0x0_p4pvAdD" ,
172+ "outputId" : " 78e0d606-1d79-4a89-8bcc-79dd9282f4cf" ,
173+ "colab" : {
174+ "base_uri" : " https://localhost:8080/"
175+ }
154176 },
155- "execution_count" : null ,
156- "outputs" : []
177+ "execution_count" : 4 ,
178+ "outputs" : [
179+ {
180+ "output_type" : " stream" ,
181+ "name" : " stdout" ,
182+ "text" : [
183+ " step 0: residual = 7.594e+00\n " ,
184+ " step 10: residual = 1.699e-02\n " ,
185+ " step 20: residual = 2.148e-02\n " ,
186+ " step 30: residual = 1.295e-02\n " ,
187+ " step 40: residual = 4.494e-03\n " ,
188+ " step 50: residual = 1.366e-03\n " ,
189+ " step 60: residual = 4.129e-04\n " ,
190+ " step 70: residual = 1.274e-04\n " ,
191+ " step 80: residual = 4.013e-05\n " ,
192+ " step 90: residual = 1.286e-05\n " ,
193+ " step 100: residual = 4.181e-06\n " ,
194+ " step 110: residual = 1.374e-06\n " ,
195+ " step 120: residual = 4.550e-07\n " ,
196+ " step 130: residual = 1.517e-07\n " ,
197+ " step 140: residual = 5.085e-08\n " ,
198+ " step 150: residual = 1.712e-08\n " ,
199+ " step 160: residual = 5.784e-09\n " ,
200+ " step 170: residual = 1.961e-09\n " ,
201+ " step 180: residual = 6.655e-10\n " ,
202+ " step 190: residual = 2.269e-10\n " ,
203+ " step 200: residual = 7.746e-11\n " ,
204+ " \n " ,
205+ " 0.9999999999604734\n "
206+ ]
207+ }
208+ ]
157209 },
158210 {
159211 "cell_type" : " markdown" ,
204256 " print(lam_est_device)"
205257 ],
206258 "metadata" : {
207- "id" : " sulx6gabBd1w"
259+ "id" : " sulx6gabBd1w" ,
260+ "outputId" : " 2b929e25-6bd7-4533-bf93-1a7d1f912f00" ,
261+ "colab" : {
262+ "base_uri" : " https://localhost:8080/"
263+ }
208264 },
209- "execution_count" : null ,
210- "outputs" : []
265+ "execution_count" : 5 ,
266+ "outputs" : [
267+ {
268+ "output_type" : " stream" ,
269+ "name" : " stdout" ,
270+ "text" : [
271+ " step 0: residual = 7.594e+00\n " ,
272+ " step 10: residual = 1.699e-02\n " ,
273+ " step 20: residual = 2.148e-02\n " ,
274+ " step 30: residual = 1.295e-02\n " ,
275+ " step 40: residual = 4.494e-03\n " ,
276+ " step 50: residual = 1.366e-03\n " ,
277+ " step 60: residual = 4.129e-04\n " ,
278+ " step 70: residual = 1.274e-04\n " ,
279+ " step 80: residual = 4.013e-05\n " ,
280+ " step 90: residual = 1.286e-05\n " ,
281+ " step 100: residual = 4.181e-06\n " ,
282+ " step 110: residual = 1.374e-06\n " ,
283+ " step 120: residual = 4.550e-07\n " ,
284+ " step 130: residual = 1.517e-07\n " ,
285+ " step 140: residual = 5.085e-08\n " ,
286+ " step 150: residual = 1.712e-08\n " ,
287+ " step 160: residual = 5.784e-09\n " ,
288+ " step 170: residual = 1.960e-09\n " ,
289+ " step 180: residual = 6.659e-10\n " ,
290+ " step 190: residual = 2.269e-10\n " ,
291+ " step 200: residual = 7.736e-11\n " ,
292+ " \n " ,
293+ " 0.9999999999593268\n "
294+ ]
295+ }
296+ ]
211297 },
212298 {
213299 "cell_type" : " markdown" ,
257343 " print(lam_est_device_generation)"
258344 ],
259345 "metadata" : {
260- "id" : " HXFZXGhU1Xj2"
346+ "id" : " HXFZXGhU1Xj2" ,
347+ "outputId" : " fd52bba4-839b-42c6-c7d3-80d1a39f80e3" ,
348+ "colab" : {
349+ "base_uri" : " https://localhost:8080/"
350+ }
261351 },
262- "execution_count" : null ,
263- "outputs" : []
352+ "execution_count" : 6 ,
353+ "outputs" : [
354+ {
355+ "output_type" : " stream" ,
356+ "name" : " stdout" ,
357+ "text" : [
358+ " A_host:\n " ,
359+ " [[-0.4937 -0.519 -0.2935 ... -0.1628 0.8361 0.531 ]\n " ,
360+ " [-1.0859 0.0087 -0.0661 ... -0.1706 1.0955 0.7075]\n " ,
361+ " [-0.4291 -0.3628 0.3393 ... 0.1813 0.2238 -0.2124]\n " ,
362+ " ...\n " ,
363+ " [-1.1089 -0.4564 -0.3024 ... 0.2075 1.2864 0.9066]\n " ,
364+ " [-0.8714 -0.5109 -0.1201 ... -0.072 1.3048 0.4372]\n " ,
365+ " [-1.6421 -0.6629 -0.2001 ... -0.2997 1.8579 1.5576]]\n " ,
366+ " \n " ,
367+ " A_device:\n " ,
368+ " [[-0.3175 -0.227 0.0765 ... -0.2411 0.9861 -0.6663]\n " ,
369+ " [-1.8135 -0.6378 -0.4466 ... -0.4503 3.2291 -1.3058]\n " ,
370+ " [-0.6443 0.3033 0.9719 ... 0.1302 0.4531 -0.3723]\n " ,
371+ " ...\n " ,
372+ " [-1.8697 -0.7714 -0.2048 ... 0.0244 2.859 -1.1147]\n " ,
373+ " [-1.1404 -0.9935 -0.4077 ... -0.2789 2.8553 -0.7879]\n " ,
374+ " [-0.5979 -0.6596 0.1047 ... -0.1826 1.4195 -0.0636]]\n " ,
375+ " \n " ,
376+ " step 0: residual = 2.346e+01\n " ,
377+ " step 10: residual = 2.859e-02\n " ,
378+ " step 20: residual = 2.984e-02\n " ,
379+ " step 30: residual = 1.433e-02\n " ,
380+ " step 40: residual = 5.035e-03\n " ,
381+ " step 50: residual = 1.643e-03\n " ,
382+ " step 60: residual = 5.309e-04\n " ,
383+ " step 70: residual = 1.726e-04\n " ,
384+ " step 80: residual = 5.663e-05\n " ,
385+ " step 90: residual = 1.875e-05\n " ,
386+ " step 100: residual = 6.253e-06\n " ,
387+ " step 110: residual = 2.098e-06\n " ,
388+ " step 120: residual = 7.077e-07\n " ,
389+ " step 130: residual = 2.396e-07\n " ,
390+ " step 140: residual = 8.140e-08\n " ,
391+ " step 150: residual = 2.772e-08\n " ,
392+ " step 160: residual = 9.461e-09\n " ,
393+ " step 170: residual = 3.234e-09\n " ,
394+ " step 180: residual = 1.107e-09\n " ,
395+ " step 190: residual = 3.792e-10\n " ,
396+ " step 200: residual = 1.299e-10\n " ,
397+ " step 210: residual = 4.454e-11\n " ,
398+ " \n " ,
399+ " 0.9999999999558278\n "
400+ ]
401+ }
402+ ]
264403 },
265404 {
266405 "cell_type" : " markdown" ,
282421 "metadata" : {
283422 "id" : " fL7QYIVesehd"
284423 },
285- "execution_count" : null ,
424+ "execution_count" : 7 ,
286425 "outputs" : []
287426 },
288427 {
313452 " np.testing.assert_allclose(lam_est_device, lam_ref, rtol=1e-4)"
314453 ],
315454 "metadata" : {
316- "id" : " 7E7MUYsYsjwO"
455+ "id" : " 7E7MUYsYsjwO" ,
456+ "outputId" : " b9e3bb4e-f9d9-4311-ba18-5896be23eb8e" ,
457+ "colab" : {
458+ "base_uri" : " https://localhost:8080/"
459+ }
317460 },
318- "execution_count" : null ,
319- "outputs" : []
461+ "execution_count" : 8 ,
462+ "outputs" : [
463+ {
464+ "output_type" : " stream" ,
465+ "name" : " stdout" ,
466+ "text" : [
467+ " Solution\n " ,
468+ " \n " ,
469+ " Power iteration (host) = 1.000000e+00\n " ,
470+ " Power iteration (device) = 1.000000e+00\n " ,
471+ " `eigvals` reference = 1.000000e+00\n " ,
472+ " \n " ,
473+ " Relative error (host) = 3.938e-11\n " ,
474+ " Relative error (device) = 4.053e-11\n "
475+ ]
476+ }
477+ ]
320478 },
321479 {
322480 "cell_type" : " markdown" ,
333491 " print(f\" Execution Time\" )\n " ,
334492 " print()\n " ,
335493 " \n " ,
336- " time_host = %timeit -q -o estimate_host(A_host, PowerIterationConfig(progress=False))\n " ,
494+ " time_host = %timeit -q -o estimate_host(A_host, PowerIterationConfig(progress=False)).item() \n " ,
337495 " print(f\" Power iteration (host) = {time_host}\" )\n " ,
338496 " \n " ,
339497 " # We intentionally use `A_host`, not `A_device`, because they're not\n " ,
340498 " # the same matrices due to differences in NumPy and CuPy's random facilities.\n " ,
341- " time_device = %timeit -q -o estimate_device(A_host, PowerIterationConfig(progress=False))\n " ,
499+ " time_device = %timeit -q -o estimate_device(A_host, PowerIterationConfig(progress=False)).item() \n " ,
342500 " print(f\" Power iteration (device) = {time_device}\" )\n " ,
343501 " \n " ,
344502 " time_ref = %timeit -q -o -r 1 -n 1 np.linalg.eigvals(A_host).real.max()\n " ,
345503 " print(f\" `eigvals` reference = {time_ref}\" )"
346504 ],
347505 "metadata" : {
348- "id" : " v_2HmcBFERhE"
506+ "id" : " v_2HmcBFERhE" ,
507+ "outputId" : " 43c4da5f-6164-4088-ac5e-685f26b58c95" ,
508+ "colab" : {
509+ "base_uri" : " https://localhost:8080/"
510+ }
349511 },
350- "execution_count" : null ,
351- "outputs" : []
512+ "execution_count" : 9 ,
513+ "outputs" : [
514+ {
515+ "output_type" : " stream" ,
516+ "name" : " stdout" ,
517+ "text" : [
518+ " Execution Time\n " ,
519+ " \n " ,
520+ " Power iteration (host) = 2.38 s ± 382 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n " ,
521+ " Power iteration (device) = 324 ms ± 7.39 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n " ,
522+ " `eigvals` reference = 49.1 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)\n "
523+ ]
524+ }
525+ ]
352526 }
353527 ]
354- }
528+ }
0 commit comments