articles:numpy_vs_geo

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
articles:numpy_vs_geo [2021/05/21 10:29] Takashi Suehiroarticles:numpy_vs_geo [2024/03/28 14:43] (現在) – [結論] Takashi Suehiro
行 5: 行 5:
 ===== 目的 ===== ===== 目的 =====
  
-ベクトル,回転行列,座標変換行列といった三次元幾何演算をpythonのリストをベースに[[./geo.py|geo.py]]というモジュールを自作している.リストベースの処理よりnumpyを使ったほうが高速なのではないかとの疑念もあるので比較を行う. \\+ベクトル,回転行列,座標変換行列といった三次元幾何演算をpythonのリストをベースに[[upload_files:geo.py|geo.py]]というモジュールを自作している.リストベースの処理よりnumpyを使ったほうが高速なのではないかとの疑念もあるので比較を行う. \\
 geo.pyはもともとpython2で開発されたが,単純な構造なのでpython3でも問題なく動く. geo.pyはもともとpython2で開発されたが,単純な構造なのでpython3でも問題なく動く.
  
行 94: 行 94:
 <code python> <code python>
 data = [] data = []
 +</code>
 +<code python>
 +def judge(test_name, g_time, np_time) :
 +    if g_time < np_time :
 +        judgment = "geo.pyの勝ち"
 +    elif g_time > np_time :
 +        judgment = "npの勝ち"
 +    else :
 +        judgment = "引き分け"
 +    return test_name, g_time, np_time, judgment
 </code> </code>
 ===== ループ回数の決定 ===== ===== ループ回数の決定 =====
行 101: 行 111:
 </code> </code>
 <code> <code>
-0.00014853477478027344+0.00030612945556640625
 </code> </code>
 <code python> <code python>
行 107: 行 117:
 </code> </code>
 <code> <code>
-0.002180337905883789+0.0015869140625
 </code> </code>
 <code python> <code python>
行 113: 行 123:
 </code> </code>
 <code> <code>
-0.017717838287353516+0.024413347244262695
 </code> </code>
 <code python> <code python>
行 119: 行 129:
 </code> </code>
 <code> <code>
-0.13070940971374512+0.1378471851348877
 </code> </code>
 <code python> <code python>
行 125: 行 135:
 </code> </code>
 <code> <code>
-1.1683580875396729+1.200444221496582
 </code> </code>
 <code python> <code python>
行 131: 行 141:
 </code> </code>
 <code> <code>
-12.219730377197266+11.367036819458008
 </code> </code>
 <code python> <code python>
行 137: 行 147:
 </code> </code>
 <code> <code>
-112.70604348182678+112.89321899414062
 </code> </code>
 百万回ぐらいでループ前後のオーバーヘッドの影響が少なくなってきている. まだ多少影響はあるが,一千万,一億は時間がかかるし, どうせループ内の処理の影響は消せないので百万回に決定する. 百万回ぐらいでループ前後のオーバーヘッドの影響が少なくなってきている. まだ多少影響はあるが,一千万,一億は時間がかかるし, どうせループ内の処理の影響は消せないので百万回に決定する.
行 163: 行 173:
 </code> </code>
 <code> <code>
-1.1506123542785645+1.143357515335083
 </code> </code>
 <code python> <code python>
行 170: 行 180:
 </code> </code>
 <code> <code>
-0.6568763256072998+0.6900453567504883
 </code> </code>
 <code python> <code python>
-if g_time < np_time : +data.append(judge('ベクトルの和', g_time, np_time))
-    win = "geo.pyの勝ち" +
-elif g_time > np_time : +
-    win = "npの勝ち" +
-else : +
-    win = "引き分け" +
-data.append(['ベクトルの和', g_time, np_time, win])+
 </code> </code>
 ===== ベクトルの内積 geo.pyの勝ち ===== ===== ベクトルの内積 geo.pyの勝ち =====
行 200: 行 204:
 </code> </code>
 <code> <code>
-0.597369909286499+0.6457569599151611
 </code> </code>
 <code python> <code python>
行 207: 行 211:
 </code> </code>
 <code> <code>
-1.6821990013122559+1.7959060668945312
 </code> </code>
 <code python> <code python>
-if g_time < np_time : +data.append(judge('ベクトルの内積', g_time, np_time))
-    win = "geo.pyの勝ち" +
-elif g_time > np_time : +
-    win = "npの勝ち" +
-else : +
-    win = "引き分け" +
-data.append(['ベクトルの内積', g_time, np_time, win])+
 </code> </code>
 ===== ベクトルの外積 geo.pyの圧勝 ===== ===== ベクトルの外積 geo.pyの圧勝 =====
行 239: 行 237:
 </code> </code>
 <code> <code>
-1.786348819732666+1.6717863082885742
 </code> </code>
 <code python> <code python>
行 246: 行 244:
 </code> </code>
 <code> <code>
-52.208454847335815+54.95365524291992
 </code> </code>
 <code python> <code python>
-if g_time < np_time : +data.append(judge('ベクトルの外積', g_time, np_time))
-    win = "geo.pyの勝ち" +
-elif g_time > np_time : +
-    win = "npの勝ち" +
-else : +
-    win = "引き分け" +
-data.append(['ベクトルの外積', g_time, np_time, win])+
 </code> </code>
 ===== 行列とベクトルの積 npの勝ち ===== ===== 行列とベクトルの積 npの勝ち =====
行 276: 行 268:
 </code> </code>
 <code> <code>
-2.4420416355133057+2.362830638885498
 </code> </code>
 <code python> <code python>
行 283: 行 275:
 </code> </code>
 <code> <code>
-1.813652753829956+1.848921537399292
 </code> </code>
 <code python> <code python>
-if g_time < np_time : +data.append(judge('行列とベクトルの積', g_time, np_time))
-    win = "geo.pyの勝ち" +
-elif g_time > np_time : +
-    win = "npの勝ち" +
-else : +
-    win = "引き分け" +
-data.append(['行列とベクトルの積', g_time, np_time, win])+
 </code> </code>
 ===== 行列同士の積 npの勝ち ===== ===== 行列同士の積 npの勝ち =====
行 315: 行 301:
 </code> </code>
 <code> <code>
-6.281814098358154+5.8199920654296875
 </code> </code>
 <code python> <code python>
行 322: 行 308:
 </code> </code>
 <code> <code>
-2.4157330989837646+2.266876697540283
 </code> </code>
 <code python> <code python>
-if g_time < np_time : +data.append(judge('行列同士の積', g_time, np_time))
-    win = "geo.pyの勝ち" +
-elif g_time > np_time : +
-    win = "npの勝ち" +
-else : +
-    win = "引き分け" +
-data.append(['行列同士の積', g_time, np_time, win])+
 </code> </code>
 ===== 結論 ===== ===== 結論 =====
行 341: 行 321:
 df df
 </code> </code>
-<HTML>+ 
 <div> <div>
 <style scoped> <style scoped>
行 362: 行 343:
 </th> </th>
 <th> <th>
-</HTML>+
 項目 項目
-<HTML>+
 </th> </th>
 <th> <th>
-</HTML>+
 geo.py geo.py
-<HTML>+
 </th> </th>
 <th> <th>
-</HTML>+
 np np
-<HTML>+
 </th> </th>
 <th> <th>
-</HTML>+
 結果 結果
-<HTML>+
 </th> </th>
 </tr> </tr>
行 386: 行 367:
 <tr> <tr>
 <th> <th>
-</HTML>+
 0 0
-<HTML>+
 </th> </th>
 <td> <td>
-</HTML>+
 ベクトルの和 ベクトルの和
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-1.150612 +1.143358 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-0.656876 +0.690045 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML>+
 npの勝ち npの勝ち
-<HTML>+
 </td> </td>
 </tr> </tr>
 <tr> <tr>
 <th> <th>
-</HTML> + 
-+
-<HTML>+
 </th> </th>
 <td> <td>
-</HTML>+
 ベクトルの内積 ベクトルの内積
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-0.597370 +0.645757 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-1.682199 +1.795906 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML>+
 geo.pyの勝ち geo.pyの勝ち
-<HTML>+
 </td> </td>
 </tr> </tr>
 <tr> <tr>
 <th> <th>
-</HTML>+
 2 2
-<HTML>+
 </th> </th>
 <td> <td>
-</HTML>+
 ベクトルの外積 ベクトルの外積
 <HTML> <HTML>
 </td> </td>
 <td> <td>
-</HTML> + 
-1.786349 +1.671786 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-52.208455 +54.953655 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML>+
 geo.pyの勝ち geo.pyの勝ち
-<HTML>+
 </td> </td>
 </tr> </tr>
 <tr> <tr>
 <th> <th>
-</HTML>+
 3 3
-<HTML>+
 </th> </th>
 <td> <td>
-</HTML>+
 行列とベクトルの積 行列とベクトルの積
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-2.442042 +2.362831 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-1.813653 +1.848922 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML>+
 npの勝ち npの勝ち
-<HTML>+
 </td> </td>
 </tr> </tr>
 <tr> <tr>
 <th> <th>
-</HTML>+
 4 4
-<HTML>+
 </th> </th>
 <td> <td>
-</HTML>+
 行列同士の積 行列同士の積
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-6.281814 +5.819992 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML> + 
-2.415733 +2.266877 
-<HTML>+
 </td> </td>
 <td> <td>
-</HTML>+
 npの勝ち npの勝ち
-<HTML>+
 </td> </td>
 </tr> </tr>
行 523: 行 503:
 </div> </div>
 </HTML> </HTML>
 +
 結論から言うと,意外にに差がないということが分かる. 大きなサイズのデータを扱うときはnumpyが良いのだろうが,三次元のベクトルや行列では大きな差は出ない. 結論から言うと,意外にに差がないということが分かる. 大きなサイズのデータを扱うときはnumpyが良いのだろうが,三次元のベクトルや行列では大きな差は出ない.
  
行 529: 行 510:
 ロボットのプログラムで使うときは個々の要素へのアクセスも多くあるので,なおさら差が出にくく現状のgeo.pyで十分であると考えられる. ロボットのプログラムで使うときは個々の要素へのアクセスも多くあるので,なおさら差が出にくく現状のgeo.pyで十分であると考えられる.
  
 +<table tab_label> 
 +<caption>まとめの表</caption> 
 +^ 項目 ^ geo.py ^ np ^ 結果 ^ 
 +| foo    | bar    | 
 +</table>
  
  • articles/numpy_vs_geo.1621560569.txt.gz
  • 最終更新: 2021/05/21 10:29
  • by Takashi Suehiro