Weird behavior while using numba on a raspberry pi zero

huangapple go评论65阅读模式
英文:

Weird behavior while using numba on a raspberry pi zero

问题

我在树莓派 Zero 上使用 numba 时遇到了一些奇怪的行为。当我使用浮点数时,我的函数返回了数学上错误的奇怪计算结果。这是我的代码:

import numba

@numba.jit(nopython=True)
def numtesting(n):
    print(n)
    print(n)

numtesting(1.0)

我期望的输出是:

  • 1.0
  • 1.0

但实际得到的是:

  • 1.0
  • 0.031326431754716

有什么想法发生了什么?

英文:

I got some weird behavior while using numba on a raspberry pi zero. When I use floating numbers, my function returns weird calculations which are mathematically wrong. This is my code:

import numba

@numba.jit(nopython=True)
def numtesting(n):
    print(n)
    print(n)


numtesting(1.0)

I would expect

  • 1.0
  • 1.0

Instead i get:

  • 1.0
  • 0.031326431754716

Any ideas what's happening?

答案1

得分: 0

我放弃在我的树莓派 Zero 上安装 numba。在 GitHub 上找到的信息显示,numba 只在 64 位架构上正常工作。不过,我购买了一台带有 64 位架构的树莓派 Zero 2,并且成功在上面安装了 numba 0.56.4。然而,我不得不使用一些变通方法,以下是我是如何做到的:

操作系统:树莓派 OS Lite(32 位)
为了成功安装 llvmlite,我执行了 sudo apt install -y llvm-dev libffi-dev
为了使 numpy 正常运行,我执行了 sudo apt-get install -y libatlas libopenjp2-7
之后,我在虚拟环境中使用了 pip install llvmlite==0.39.1
在这一步,我遇到了一个问题,安装程序在为 llvmlite 构建 wheel 时卡住了。ChatGPT 建议我将 /etc/dphys-swapfile 中的 SWAP 大小增加到 1024(默认值为 100)。参数名为 CONF_SWAPSIZE

之后,我能够使用 pip install numpy==0.56.4 将 numpy 安装到我的虚拟环境中
希望这对某人有所帮助。我花了很多时间才解决了这个问题。

英文:

I gave up installing numba on my Raspberry Pi Zero. Found infos on github that numba only correctly works on 64-bit architectures. However, I bought myself a Raspberry Pi Zero 2 with 64-bit architecture and I managed to install numba 0.56.4 on it. However, I had to use some workarounds, here is how i did it:

OS: Raspberry Pi OS Lite (32bit)
For llvmlite to be installed successfully, I installed sudo apt install -y llvm-dev libffi-dev
For numpy to run successfully, I installed sudo apt-get install -y libatlas libopenjp2-7
After that i used pip install llvmlite==0.39.1 into a virtual environment
At this point I faced the issue, that the installer froze builing a wheel for llvmlite. ChatGPT helped by recommending to increase the SWAP size in /etc/dphys-swapfile to 1024 (Default was 100). The parameter is called CONF_SWAPSIZE

After that i was able to install numpy into my virtual environment using pip install numpy==0.56.4
I really hope it helps someone. I took me quite some time to figure this out...

huangapple
  • 本文由 发表于 2023年5月11日 02:08:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定