Successfully reported this slideshow.
Your SlideShare is downloading. ×

NArray and scientific computing with Ruby - RubyKaigi2010

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Rubyによるデータ解析
Rubyによるデータ解析
Loading in …3
×

Check these out next

1 of 46 Ad

NArray and scientific computing with Ruby - RubyKaigi2010

Download to read offline

NArray is an n-dimensional numerical array library developed for use in science fields, but it is usable for handling binary data efficiently. I talk about NArray for the first time after 10 years from the first release. I will also present topics including the next version of NArray, and distributed scientific computing using Ruby for multi-core era.

NArray is an n-dimensional numerical array library developed for use in science fields, but it is usable for handling binary data efficiently. I talk about NArray for the first time after 10 years from the first release. I will also present topics including the next version of NArray, and distributed scientific computing using Ruby for multi-core era.

Advertisement
Advertisement

More Related Content

Slideshows for you (16)

Viewers also liked (20)

Advertisement

Similar to NArray and scientific computing with Ruby - RubyKaigi2010 (20)

Recently uploaded (20)

Advertisement

NArray and scientific computing with Ruby - RubyKaigi2010

  1. 1. 田中昌宏 Masahiro Tanaka RubyKaigi2010 2010-8-29 1
  2. 2.  NArrayの開発者 ◦ NArray developer  昨年度からつくば市在住 ◦ I live in Tsukuba since Apr 2009 RubyKaigi2010 2010-8-29 2
  3. 3.  NArrayを使ったサイエンス ◦ Science using NArray  NArrayの概要 ◦ NArray overview ◦ 詳しい話はしません。No details.  並列分散ワークフロー実行システム ◦ Parallel Distributed Workflow System RubyKaigi2010 2010-8-29 3
  4. 4. RubyKaigi2010 2010-8-29 4
  5. 5. RubyKaigi2010 2010-8-29 5
  6. 6.  http://www.gfd-dennou.org/  GPhys ◦ 多次元物理量表現ライブラリ ◦ multi-dimensional physical quantity library  RubyDCL ◦ グラフ描画ライブラリ ◦ Plotting Graph  RubyNetCDF ◦ 物理データフォーマットNetCDFのIOラ イブラリ ◦ Physical data format library RubyKaigi2010 2010-8-29 6
  7. 7. ◦ Gtk ベース格子点可 視化・解析ツール ◦ Gtk-base visualize & analysis tool for lattice data RubyKaigi2010 2010-8-29 7
  8. 8. ◦ Railsベースの地球流体デー タベース・解析・可視化ツー ル ◦ Rails-base visualize & analysis tool for Geophysical database RubyKaigi2010 2010-8-29 8
  9. 9. RubyKaigi2010 2010-8-29 9
  10. 10.  物質科学における、多次元試料データの管理を効率 的に行う  For managing multi-dimensional sample data in material science. RubyKaigi2010 2010-8-29 10
  11. 11. 波長 位置 光の強さ Shin-ichi Todoroki, Meas. Sci. Technol. 16 (2005) 285–291 RubyKaigi2010 2010-8-29 11
  12. 12. RubyKaigi2010 2010-8-29 12
  13. 13. RubyKaigi2010 2010-8-29 13
  14. 14.  電子顕微鏡写真から、生体微小管などの三次元構造 を構築するためのプログラム  Program set for Helical image analysis in combination with electron microscopy used to study three- dimensional structures of microtubules etc. RubyKaigi2010 2010-8-29 14
  15. 15. 画像から構築した3次元構造 3-D structure constructed from the EM image 電子顕微鏡写真 Electron Microscope image RubyKaigi2010 2010-8-29 15
  16. 16. RubyKaigi2010 2010-8-29 16
  17. 17.  http://www.artcompsci.org/~makino/rikigaku/  A book in dynamics for general readers RubyKaigi2010 2010-8-29 17
  18. 18. Program and explanation 飛跡の計算結果 Result flight trajectory RubyKaigi2010 2010-8-29 18
  19. 19. RubyKaigi2010 2010-8-29 19
  20. 20. RubyKaigi2010 2010-8-29 20
  21. 21.  処理を簡単に書きたい ◦ write processing codes shortly  結果をすぐ確認したい ◦ confirm processing result immediately  インタラクティブな操作もしたい ◦ manipulate interactively RubyKaigi2010 2010-8-29 21
  22. 22.  プログラムが書ける – Ruby ◦ Programmable  インタラクティブな実行 – irb ◦ Interactive execution  データ配列操作 – NArray ◦ Data Array Manipulation  数値計算ライブラリ ◦ Library for Numerical Algorithms  グラフ表示機能 ◦ Plotting Graphs RubyKaigi2010 2010-8-29 22
  23. 23.  多次元数値配列 ◦ Numerical N-dimensional Array  http://narray.rubyforge.org  http://github.com/masa16/narray RubyKaigi2010 2010-8-29 23
  24. 24.  0.3.0 – 1999  0.5.0 – 2000  0.5.9p7 – 2009 (current version)  0.7.0 – 20?? (next version, under development) RubyKaigi2010 2010-8-29 24
  25. 25.  IDL (Interactive Data Language)  Yorick  Python Numeric RubyKaigi2010 2010-8-29 25
  26. 26.  rank ◦ 次元数 the number of dimension  shape ◦ 配列の「形」 array shape  type ◦ 要素の型 element type  memory block ◦ データを格納するメモリーブロック RubyKaigi2010 2010-8-29 26
  27. 27.  Ruby Array : ◦ VALUE *ptr; → value[0] value[1] value[2] value[3] … struct RVALUE { … }  NArray ◦ void *ptr; → double[0] double[1] double[2] double[3] … ◦ or int[0] int[1] int[2] int[3] … RubyKaigi2010 2010-8-29 27
  28. 28.  整数  複素数 ◦ BYTE (8bit) ◦ SCOMPLEX (64bit) ◦ SINT (16bit) ◦ COMPLEX ◦ INT (32bit) ◦ = DCOMPLEX (128bit)  浮動小数点数  Rubyオブジェクト ◦ SFLOAT (32bit) ◦ ROBJECT ◦ FLOAT ◦ = DFLOAT (64bit) RubyKaigi2010 2010-8-29 28
  29. 29.  現版では、ビルトインのみ ◦ Current version has Built-in types only  次版 Next version ◦ 後から付け足すことが可能  Append-able types RubyKaigi2010 2010-8-29 29
  30. 30.  shape = [4]  shape = [4,4,4] ◦ 1次元配列 ◦ 3次元配列 ◦ one-dimensional array ◦ three-dimensional array a[0] a[1] a[2] a[3]  shape = [4,4] ◦ 2次元配列 a[0,0,0] a[1,0,0] a[2,0,0] a[3,0,0] ◦ two-dimensional array a[0,1,0] a[1,1,0] a[2,1,0] a[3,1,0] a[0,0] a[1,0] a[2,0] a[3,0] a[0,2,0] a[1,2,0] a[2,2,0] a[3,2,0] a[0,1] a[1,1] a[2,1] a[3,1] a[0,3,0] a[1,3,0] a[2,3,0] a[3,3,0] a[0,2] a[1,2] a[2,2] a[3,2] a[0,3] a[1,3] a[2,3] a[3,3] 行列でいう次元とは異なる Different from Matrix dimension RubyKaigi2010 2010-8-29 30
  31. 31.  a[i,j] データが連続する順番 contiguous order  左の次元(i)がはやく回る ◦ Left dimension(i) is contiguous ◦ Fortran-order a[0,0] a[1,0] a[2,0] a[3,0] ◦ Row-major order a[0,1] a[1,1] a[2,1] a[3,1] If a.shape == [m,n] then a[0,2] a[1,2] a[2,2] a[3,2] a[i,j] == a[i+j*m] a[0,3] a[1,3] a[2,3] a[3,3]  a[j][i] と逆 reverse order  次版では変更予定 ◦ This will be changed for the next version. RubyKaigi2010 2010-8-29 31
  32. 32. NArray.float(3,2) NArray[[1,2,3],[4,5,6]] => NArray.float(3,2): => NArray.int(3,2): [ [ 0.0, 0.0, 0.0 ], [ [ 1, 2, 3 ], [ 0.0, 0.0, 0.0 ] ] [ 4, 5, 6 ] ] NArray.float(3,2).indgen! NArray[1..10] => NArray.float(3,2): => NArray.int(10): [ [ 0.0, 1.0, 2.0 ], [ 1, 2, 3, 4, 5, 6, 7, 8, [ 3.0, 4.0, 5.0 ] ] 9, 10 ] RubyKaigi2010 2010-8-29 32
  33. 33.  a[1] a[0] a[1] a[2] a[3] ◦ 要素参照 ◦ reference by element  a[1..2] a[0] a[1] a[2] a[3] ◦ 範囲参照 ◦ reference by range  a[[1,3]] a[0] a[1] a[2] a[3] ◦ インデックス配列参照 ◦ reference by index array RubyKaigi2010 2010-8-29 33
  34. 34.  演算は要素ごと ◦ Operation is element-wise a*b= a[0]*b[0] a[1]*b[1] a[2]*b[2] a[3]*b[3]  演算 Operations ◦ 四則演算  arithmetic operations  +, -, *, /, %, ** ◦ 数学関数演算  math operations  NMath module RubyKaigi2010 2010-8-29 34
  35. 35.  Float Array with 106 elements  Ruby 1.9.2 : (0...n).map{|i| a[i]*b[i]} ◦ elapsed time : 180 ms  NArray with Ruby 1.9.2 : a*b ◦ elapsed time : 6.4 ms  NArray is ~ 28 times faster 28倍速い  8 times less characters 8倍短く書ける RubyKaigi2010 2010-8-29 35
  36. 36. NArrayによる性能向上 速度向上の倍率 Speedup factor Speedup by NArray コードはNArrayのサイト 60 にあります 50 40 30 20 Speedup by NArray 10 0 0.E+00 2.E+05 4.E+05 6.E+05 8.E+05 1.E+06 データサイズ data size RubyKaigi2010 2010-8-29 36
  37. 37.  NArrayのメモリアクセス  実際のPCアーキテクチャ  Memory access for NArray  Actual PC architechture CPU CPU core core fast NArray’s L1 cache Bottleneck ボトルネック L2 cache Main Main slow Memory Memory RubyKaigi2010 2010-8-29 37
  38. 38. CPU Socket CPU Socket CPU CPU CPU CPU GPU core core core core cache cache cache cache cache cache Storage Main Memory Main Memory Node Node Node … Network RubyKaigi2010 2010-8-29 38
  39. 39.  Ruby and NArray ◦ コードを書きやすい Easy to write code ◦ 複雑さの隠蔽 Hide complexity  アーキテクチャの違い different architecture  データの分散 data distribution RubyKaigi2010 2010-8-29 39
  40. 40.  プログラムが書ける – Ruby ◦ Programmable  インタラクティブな実行 – irb ◦ Interactive execution  データ配列操作 – NArray ◦ Data Array Manipulation  数値計算ライブラリ – Ruby/GSL , etc. ◦ Library for Numerical Algorithms  グラフ表示機能 –? ◦ Plotting Graphs RubyKaigi2010 2010-8-29 40
  41. 41.  NArrayの各機能 ◦ NArray functions  NArrayの使い方 ◦ NArray usage  次版NArray ◦ Next version of NArray  他の類似数値配列との比較 ◦ Comparison with other numerical arrays, e.g. Numpy  Python が科学分野で主流になりつつある件 ◦ Python is becoming major in Science field. RubyKaigi2010 2010-8-29 41
  42. 42. 田中昌宏 Masahiro Tanaka 筑波大学 University of Tsukuba RubyKaigi2010 2010-8-29 42
  43. 43. ワークフローのグラフ  科学データ処理 Workflow graph ◦ Scientific data processing  複雑なワークフローである ◦ is a complicated workflow.  ワークフロー記述言語が必要 ◦ It needs definition language  Makefileによる記述が提案 ◦ Use of Makefile has been proposed ◦ e.g. GXP make RubyKaigi2010 2010-8-29 43
  44. 44. Pwrake  Rakeによるワークフロー記述を提案 Process Process  We propose defining workflows Rake Process ◦ Makeより記述力が高い ◦ More descriptive power than Make  Rakeの並列分散拡張として、Pwrake (プレイク)を開 発  We are developing Pwrake, a Parallel workflow extension for Rake ◦ http://github.com/masa16/pwrake RubyKaigi2010 2010-8-29 44
  45. 45.  NArrayを使った科学計算の例について紹介 ◦ Examples of Scientific computing using NArray  NArrayとその特徴を紹介 ◦ NArray and its features  並列分散ワークフロー実行システムPwrake ◦ Parallel Distributed Workflow System Pwrake RubyKaigi2010 2010-8-29 45
  46. 46.  ご質問  Questions? RubyKaigi2010 2010-8-29 46

×