我正在尝试在Cygwin上编译这个简单的GMP程序:
#include <gmp.h>
int main(){
mpz_t i;
mpz_init(i);
}
Run Code Online (Sandbox Code Playgroud)
这是命令:
gcc -lgmp test.c
我收到此错误:
/tmp/ccJpGa7K.o:test.c:(.text+0x17): undefined reference to `__imp___gmpz_init'
/tmp/ccJpGa7K.o:test.c:(.text+0x17): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp___gmpz_init'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
知道什么是错的吗?我知道它可以找到库(libgmp.dll.a),但似乎没有找到该函数.
产量nm /usr/lib/libgmp.dll.a | grep mpz_init:
0000000000000000 T __gmpz_inits
0000000000000000 I __imp___gmpz_inits
0000000000000000 T __gmpz_init_set_ui
0000000000000000 I __imp___gmpz_init_set_ui
0000000000000000 T __gmpz_init_set_str
0000000000000000 I __imp___gmpz_init_set_str
0000000000000000 T __gmpz_init_set_si
0000000000000000 I __imp___gmpz_init_set_si
0000000000000000 T __gmpz_init_set_d
0000000000000000 I __imp___gmpz_init_set_d
0000000000000000 T __gmpz_init_set
0000000000000000 I __imp___gmpz_init_set …Run Code Online (Sandbox Code Playgroud) 有没有办法使用surf()样式数据格式来创建热图?
我有一堆形式的分散数据z=f(x,y)(所以我曾经TriScatteredInterp使它工作meshgrid),我想z用热图可视化.surf已经做了类似于我想要的事情,除了你必须手动旋转图形以使视图自上而下看XY平面.
基本上,我想要类似的东西:

但冲浪默认情况下会给你这个:

我正在尝试为cgal绑定创建一个setup.py .要安装它,用户需要至少具有某个版本的CGAL.此外,如果用户有一些库(如Eigen3),CGAL有一些可选的目标.Python中是否有跨平台方式来检查?
我可以用.< - 这实际上并不是一直有效,有些库只是像eigen3这样的头文件,它是一个C++模板库.find_library在ctypes.util检查库中存在,但我看不出有什么简单的方法来获取版本
使用install_requires的说法setup()只适用于Python库和CGAL是一个C/C++库.
我正在使用setup.py,它在build_ext步骤中创建了一大堆SWIG接口文件.这需要先运行,因为后续的构建步骤需要一个完整的python文件列表才能正常工作(比如将python文件复制到包目录,创建egg,创建源列表等).
当你这样做时,这是当前发生的事情setup.py install:
running install
running bdist_egg
running egg_info
running install_lib
running build_py
running build_ext
Run Code Online (Sandbox Code Playgroud)
该build_py步骤尝试将它找到的所有python文件复制到构建目录.这些文件在build_ext运行之前不存在(swig创建了一堆.py文件).
这个答案建议改变,sub_commands但似乎没有做任何事情.
我试着install像这样继承子命令类以build_ext在其他任何事情之前运行:
class Build_ext_first(setuptools.command.install.install):
def run(self):
self.run_command("build_ext")
super(Build_ext_first, self).run()
Run Code Online (Sandbox Code Playgroud)
..然后用它来设置cmdclass:
setup(
...
cmdclass = {'install' : Build_ext_first}
)
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为super它不适用于旧式类,install显然不会继承object.
我该怎么做build_ext?
我正在尝试在Mac OS 10.7.5上使用Python中的CPLEX.CPLEX似乎只支持32位python.我在python shell中使用它来检查它是否是32位:
import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32
Run Code Online (Sandbox Code Playgroud)
我按照man 1 python的建议尝试了这两个命令,但似乎都没有强制32位:
export VERSIONER_PYTHON_PREFER_32_BIT=yes
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Run Code Online (Sandbox Code Playgroud)
似乎唯一有用的是:
arch -i386 python
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用调用其他脚本的arch运行脚本,它们似乎都以64位模式启动.是否有另一个系统范围的变量强制它进入32位模式?
我有一些代码可以加载 2000 个 2D 坐标的 csv 文件,然后一个名为的函数collision_count计算比d彼此距离更近的坐标对的数量:
using BenchmarkTools
using CSV
using LinearAlgebra
function load_csv()::Array{Float64,2}
df = CSV.read("pos.csv", header=0)
return Matrix(df)'
end
function collision_count(pos::Array{Float64,2}, d::Float64)::Int64
count::Int64 = 0
N::Int64 = size(pos, 2)
for i in 1:N
for j in (i+1):N
@views dist = norm(pos[:,i] - pos[:,j])
count += dist < d
end
end
return count
end
Run Code Online (Sandbox Code Playgroud)
结果如下:
pos = load_csv()
@benchmark collision_count($pos, 2.0)
BenchmarkTools.Trial:
memory estimate: 366.03 MiB
allocs estimate: 5997000
--------------
minimum time: 152.070 ms …Run Code Online (Sandbox Code Playgroud)