Coder Social home page Coder Social logo

cython_matmult's Introduction

cythonを用いた行列計算の高速化について

  1. Pure Python
  2. Python + Numpy
  3. Cython + Class + Malloc
  4. Cython + Function
  5. Cython Function + Typed Memoryviews and Raw Pointer
  6. Cython Class + Typed Memoryviews

[結果]

  1. 2 function calls in 100.808 seconds
  2. 2 function calls in 0.090 seconds
  3. 106 function calls in 17.667 seconds
  4. 3 function calls in 0.522 seconds
  5. 5 function calls in 0.209 seconds
  6. 203 function calls in 0.870 seconds

当然のようにNumpyが最速である。
従って、行列計算はNumpyを使え!(OpenBLASかGotoBLASでマルチコア化)となる。
他方、次位となるのは5である。まあ、データ配列にポインターでアクセスしたので、早くなって当然なのだが、コードが読みづらい?
どうしてもClassを使い場合は6のようにすればよいだろう。

[参考]
・NumPyが物足りない人へのCython入門
http://www.slideshare.net/lucidfrontier45/cython-intro
https://github.com/tokyo-scipy/archive/tree/master/003/cython_intro/final
・Memoryview Benchmarks
http://jakevdp.github.io/blog/2012/08/08/memoryview-benchmarks/

cython_matmult's People

Contributors

quasi-quant2010 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.