官网:http://numba.pydata.org/

官方教程:http://numba.pydata.org/numba-doc/latest/user/5minguide.html

因为我3.7版本的python(也有可能是其他因素影响)找不到numba.autojit加速了,所以想到官网看看到底发生了什么

示例

以下代码加速理想

from numba import jit
import numpy as npx = np.arange(100).reshape(10, 10)@jit(nopython=True) # Set "nopython" mode for best performance, equivalent to @njit
def go_fast(a): # Function is compiled to machine code when called the first timetrace = 0.0for i in range(a.shape[0]):   # Numba likes loopstrace += np.tanh(a[i, i]) # Numba likes NumPy functionsreturn a + trace              # Numba likes NumPy broadcastingprint(go_fast(x))

以下代码加速不理想(函数不能享受numba加速)

from numba import jit
import pandas as pdx = {'a': [1, 2, 3], 'b': [20, 30, 40]}@jit
def use_pandas(a): # Function will not benefit from Numba jitdf = pd.DataFrame.from_dict(a) # Numba doesn't know about pd.DataFramedf += 1                        # Numba doesn't understand what this isreturn df.cov()                # or this!print(use_pandas(x))

需要注意的是,numba使用函数装饰器来加速函数,第一次执行函数时,会将函数编译成机器码,需要耗费一定时间,以后每次调用函数,就是直接用机器码执行,从而获得加速

所以,一般比较常用的是@njit@jit(nopython=True)(一样的)

其他功能

Numba has quite a few decorators, we’ve seen @jit, but there’s also:


@njit - this is an alias for @jit(nopython=True) as it is so commonly used!@vectorize - produces NumPy ufunc s (with all the ufunc methods supported). Docs are here.@guvectorize - produces NumPy generalized ufunc s. Docs are here.@stencil - declare a function as a kernel for a stencil like operation. Docs are here.@jitclass - for jit aware classes. Docs are here.@cfunc - declare a function for use as a native call back (to be called from C/C++ etc). Docs are here.@overload - register your own implementation of a function for use in nopython mode, e.g. @overload(scipy.special.j0). Docs are here.

Extra options available in some decorators:

parallel = True - enable the automatic parallelization of the function.fastmath = True - enable fast-math behaviour for the function.

ctypes/cffi/cython interoperability:

cffi - The calling of CFFI functions is supported in nopython mode.ctypes - The calling of ctypes wrapped functions is supported in nopython mode. .Cython exported functions are callable.

GPU targets:

Numba can target Nvidia CUDA and (experimentally) AMD ROC GPUs. You can write a kernel in pure Python and have Numba handle the computation and data movement (or do this explicitly). Click for Numba documentation on CUDA or ROC.

http://numba.pydata.org/numba-doc/latest/cuda/index.html#numba-for-cuda-gpus

有点多

不过没有看到@autojit,莫非是取消了??

numba numpy计算加速器 官方教程 GPU CUDA配置相关推荐

  1. 网页更新提醒官方教程(选项配置)

    网页更新提醒:任何网页.任何RSS.任何API,给您24小时盯着 全局配置 全局配置用于设置所有任务公共或默认属性,避免相同的重复设置. 公共配置 选取模式:具体参考网页更新提醒官方教程(区域圈选) ...

  2. Python ln_Python入门教程(三):史上最全的Numpy计算函数总结,建议收藏!

    点击上方 蓝字 关注我们 Numpy提供了灵活的.静态类型的.可编译的程序接口口来优化数组的计算,也被称作向量操作,因此在Python数据科学界Numpy显得尤为重要.Numpy的向量操作是通过通用函 ...

  3. python乘法表运算_Python入门教程(三):史上最全的Numpy计算函数总结,建议收藏!...

    点击上方 蓝字 关注我们 Numpy提供了灵活的.静态类型的.可编译的程序接口口来优化数组的计算,也被称作向量操作,因此在Python数据科学界Numpy显得尤为重要.Numpy的向量操作是通过通用函 ...

  4. paddlepaddle 使用GPU 计算,安装cuDNN 和 CUDA记录

    paddlepaddle 使用GPU 计算,安装cuDNN 和 CUDA记录 根据paddlepaddle 指导文档选择安装版本,早点选择10.2不用浪费半天.查看N卡版本信号 如果你使用的是安培架构 ...

  5. pytorch官方教程中文版(二)学习PyTorch

    pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...

  6. 60分钟入门PyTorch,官方教程手把手教你训练第一个深度学习模型(附链接)

    来源:机器之心 本文约800字,建议阅读5分钟. 本文介绍了官方教程入门PyTorch的技巧训练. 近期的一份调查报告显示:PyTorch 已经力压 TensorFlow 成为各大顶会的主流深度学习框 ...

  7. 60分钟入门PyTorch,官方教程手把手教你训练第一个深度学习模型

    点击我爱计算机视觉标星,更快获取CVML新技术 本文转载自机器之心. 近期的一份调查报告显示:PyTorch 已经力压 TensorFlow 成为各大顶会的主流深度学习框架.想发论文,不学 PyTor ...

  8. TensorFlow2.0 Guide官方教程 学习笔记17 -‘Using the SavedModel format‘

    本笔记参照TensorFlow官方教程,主要是对'Save a model-Training checkpoints'教程内容翻译和内容结构编排,原文链接:Using the SavedModel f ...

  9. pytorch官方教程中文版(一)PyTorch介绍

    pytorch编程环境是1.9.1+cu10.2 建议有能力的直接看官方网站英文版! 下面所示是本次教程的主要目录: pytorch官方教程中文版: PyTorch介绍 学习PyTorch 图像和视频 ...

最新文章

  1. 吴恩达神经网络和深度学习——第三周笔记
  2. python 执行ping命令_Python黑科技:在家远程遥控公司电脑,python+微信一键连接!...
  3. python3 collections模块_Python3之collections模块
  4. regex在.NET里判断输入信息的合法性
  5. 应用交付脚本工具在HTTP服务中的应用
  6. input和textarea的区别
  7. 去掉 RHEL AS 3 内存检测达不到256MB的警告
  8. 【matlab】直方图(hist函数的应用)
  9. 3D呈现transform-style(CSS3)
  10. 总结const、readonly、static三者的区别【收藏、转载】20190614
  11. construct2游戏设计与制作
  12. SeaChest Utilities 工具,让你的硬盘功耗又低又长寿
  13. 电视hdmi接口在哪_变废为宝!把旧笔记本电脑当电视盒子用
  14. 衣服不管染上什么,用这招都能洗掉!99%的人不知道!
  15. 思杰desktop7.6申请90天试用的License
  16. 电商支付平台支付安全保障措施
  17. HP 员工挑战老板的一封信
  18. Apple macOS 下载汇总
  19. 西门子300PLC转以太网无需编程实现与1200PLC转以太网数据通信
  20. [C语言]——整型的截断与提升

热门文章

  1. liunx 下 sendmail 反病毒和防垃圾邮件
  2. C核心技术手册(五)
  3. 使用 MDT2008 轻量部署进行 Windows XP SP2 简单部署
  4. 合理修改3389端口
  5. java中filereader读取文件_java – 如何使用FileReader逐行读取
  6. 关于mysql报 loopWaitCount 0, wait millis 60000 错误的解决办法
  7. SAP HR 常用事务代码
  8. Web Service入门简介(一个简单的WebService示例)
  9. SAP系统与MES系统的数据协同技术方案
  10. 会计信息质量要求有哪些?