- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下代码来调用 Cython 的 clapack 例程 dgelsy_,但它没有给出最小二乘问题的正确解决方案。
cimport numpy as np
import numpy as np
ctypedef np.float64_t NP_FLOAT_t
ctypedef np.int_t NP_INT_t
ctypedef np.uint8_t NP_BOOL_t
ctypedef int integer
cdef extern from "clapack.h":
integer dgelsy_(integer *m, integer *n, integer *nrhs,
double *a, integer *lda, double *b, integer *ldb, integer *
jpvt, double *rcond, integer *rank, double *work, integer *
lwork, integer *info)
cpdef dgelsy(np.ndarray[NP_FLOAT_t,ndim=2] A, np.ndarray[NP_FLOAT_t,ndim=1] b, np.ndarray[NP_INT_t,ndim=1] jpvt):
cdef integer m = A.shape[0]
cdef integer n = A.shape[1]
cdef integer nrhs = 1
cdef integer lda = m
cdef integer ldb = m
cdef integer rank
cdef NP_FLOAT_t rcond = 1e-16
cdef integer lwork = -1
cdef integer info
#First call as a workspace query
cdef np.ndarray[NP_FLOAT_t, ndim=1] work1 = np.empty(shape=1,dtype=np.float)
dgelsy_(&m, &n, &nrhs, <double*>A.data, &lda, <double*>b.data, &ldb,
<integer*>jpvt.data, &rcond, &rank, <double*>work1.data, &lwork, &info)
#Now the actual call to solve the problem
lwork = <integer>work1[0]
cdef np.ndarray[NP_FLOAT_t, ndim=1] work2 = np.empty(shape=lwork,dtype=np.float)
dgelsy_(&m, &n, &nrhs, <double*>A.data, &lda, <double*>b.data, &ldb,
<integer*>jpvt.data, &rcond, &rank, <double*>work2.data, &lwork, &info)
return rank, info
import numpy
import cylapack #cylapack is my cython module with the code above
numpy.random.seed(1)
A = numpy.random.normal(size=(100,10))
A_ = A.copy()
x = numpy.random.normal(size=10)
b = numpy.dot(A,x) + numpy.random.normal(size=100)
b_ = b.copy()
pivots = numpy.zeros(shape=10,dtype=numpy.int)
print cylapack.dgelsy(A,b,pivots)
print pivots
x_ = numpy.linalg.lstsq(A_,b_,1e-16)[0]
print numpy.sum((numpy.dot(A_,x_) - b_)**2)
print numpy.sum((numpy.dot(A_,b[0:10]) - b_)**2)
(10, 0)
[25769803780 12884901896 30064771077 38654705666 4294967306 0
0 0 0 0]
99.8269537854
1087.62032064
cylapack.c:1424: warning: passing argument 1 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 2 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 3 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 5 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 7 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 8 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 10 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 12 of 'dgelsy_' from incompatible pointer type
cylapack.c:1424: warning: passing argument 13 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 1 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 2 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 3 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 5 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 7 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 8 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 10 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 12 of 'dgelsy_' from incompatible pointer type
cylapack.c:1495: warning: passing argument 13 of 'dgelsy_' from incompatible pointer type
最佳答案
回答我自己的问题并不是我的意图,但我现在已经想通了。问题是 lapack 需要 Fortran 样式列优先顺序的矩阵,但默认情况下 numpy 使用 C 样式行优先顺序。如果在我的测试代码中我更改了这一行:
A = numpy.random.normal(size=(100,10))
A = numpy.random.normal(size=(10,100)).transpose()
关于numpy - 从 Cython 调用 clapack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14881762/
我最近设法构建并运行了一个简单的 CLAPACK Microsoft Visual Studio 2008 项目(从 http://icl.cs.utk.edu/lapack-for-windows/
我正在尝试让 clapack 在 ubuntu 14 上工作......但它一直告诉我 undefined reference “ssyev_”(实际上它发生在“clapack.h”中的任何那些 c
我编写了以下代码来调用 Cython 的 clapack 例程 dgelsy_,但它没有给出最小二乘问题的正确解决方案。 cimport numpy as np import numpy as np
有谁知道在 Accelerate (CLAPACK) 中使用什么函数/方法来求解如下所示的增广矩阵?寻找任何示例代码、示例链接、有关如何求解矩阵的提示。我一直在浏览文档,但大多数事情都与更复杂的图形系
我正在尝试从 C 调用 CLAPACK 函数。我下载了 CLAPACK-3.2.1(来自 http://www.netlib.org/clapack/clapack.tgz)并按照此处的说明进行操作(
我正在将一组空间计算移植到基本上编译和运行 C 代码的嵌入式环境中。 我已经用 CBLAS 和 CLAPACK 替换了以前使用 VNL(不能在新平台上运行的模板化 C++ 库)的一些线性代数函数。他们
我正在将一个使用 clapack 的项目从 osx 转移到 linux 并遇到一些问题。我通过下载 cmake 项目、编译必要的 .h 和 .a 文件并将其移动到项目中的相关位置来使用 clapack
我正在尝试安装 Armadillo link . 但是,make 命令提示“clapack.h” 确实存在于位置/usr/include/atlas/clapack.h。一些帮助将不胜感激。 请注意,
我很难将 clapack 链接到我在 Linux 上的 cmake 项目,非常感谢任何帮助。 我已经成功地构建了 clapack 并将其链接到 osx 上的同一个项目,这使得这种情况特别令人沮丧。 我
有谁知道在 Accelerate (CLAPACK) 中使用什么函数/方法来求解压缩列存储矩阵 (ccs)。我正在寻找任何示例代码、示例链接、有关如何求解矩阵的提示。我一直在浏览文档,但大多数事情都与
我想使用lapack库clapck ,但我如何在 Visual Studio 2008 中的 C++ 项目中使用它... 我也在审查 Template Numerical Toolkit 您是否做过类
我使用 LAPACK 的目的是计算矩阵的 cholesky。我在 Fedora 中使用 C/C++ 编程,但我对要安装哪个 lapack 感到困惑 - LAPACK 与 lapacke 还是 clap
我是一名优秀的程序员,十分优秀!