- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 mex 在 MATLAB 脚本中使用以下 C 文件。
#include <math.h>
#include "mex.h"
#include "blas.c"
static void lbidiagQR (int n, double* gamma, double* delta, double mu,
double* Q, double* u, double* v)
{
int i, ldQ ;
double tmp ;
ldQ = n*2 ;
u[0] = gamma[0] ;
for (i = 0 ; i < n ; ++i)
{
tmp = mu ;
rotg (&u[i], &tmp, &Q[i*2], &Q[i*2 +ldQ]) ;
tmp = delta[i] ;
rotg (&u[i], &tmp, &Q[i*2+1], &Q[i*2+1+ldQ]) ;
if (i < n-1)
{
v[i] = 0.0 ;
u[i+1] = gamma [i+1] ;
rot (&v[i], &u[i+1], Q[i*2+1], Q[i*2+1+ldQ]) ;
}
}
}
// input arguments
#define gamma prhs[0]
#define delta prhs[1]
#define mu prhs[2]
// output arguments
#define Q plhs[0]
#define u plhs[1]
#define v plhs[2]
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
int n ;
// check for proper number of arguments
if (nrhs != 3) mexErrMsgTxt ("lbidiagQR requires three input arguments.") ; else
if (nlhs != 3) mexErrMsgTxt ("lbidiagQR requires three output arguments.") ;
// check the dimensions of gamma
n = max (mxGetM (gamma), mxGetN (gamma)) ;
if (min (mxGetM (gamma), mxGetN (gamma)) != 1)
mexErrMsgTxt ("gamma must be an n-by-1 or a 1-by-n matrix.") ;
// check the dimensions of delta
if ((min (mxGetM (delta), mxGetN (delta)) != 1) ||
(max (mxGetM (delta), mxGetN (delta)) != n))
mexErrMsgTxt ("delta must be an n-by-1 or a 1-by-n matrix.") ;
// check the dimensions of mu
if ((mxGetM (mu) != 1) || (mxGetN (mu) != 1))
mexErrMsgTxt ("mu must be a scalar.") ;
// create matrices for the return arguments
Q = mxCreateDoubleMatrix (n*2, 2, mxREAL) ;
u = mxCreateDoubleMatrix (n, 1, mxREAL) ;
v = mxCreateDoubleMatrix (n-1, 1, mxREAL) ;
// do the actual computations in a subroutine
lbidiagQR (n, mxGetPr (gamma), mxGetPr (delta), *mxGetPr (mu),
mxGetPr (Q), mxGetPr (u), mxGetPr (v)) ;
}
但是这会引发错误:
c_routines/lbidiagqr.c:75:9: warning: implicit declaration of function 'max' is invalid in C99
[-Wimplicit-function-declaration]
n = max (mxGetM (gamma), mxGetN (gamma)) ;
^
c_routines/lbidiagqr.c:76:9: warning: implicit declaration of function 'min' is invalid in C99
[-Wimplicit-function-declaration]
if (min (mxGetM (gamma), mxGetN (gamma)) != 1)
^
2 warnings generated.
Undefined symbols for architecture x86_64:
"_max", referenced from:
_mexFunction in lbidiagqr.o
"_min", referenced from:
_mexFunction in lbidiagqr.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "lbidiagqr.mexmaci64"' failed.
在我看来,这表明使用 max() 和 min() 的行是问题所在。环顾四周后,我发现这些可以使用宏定义为:
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
尽管这并不能解决错误,但我现在收到有关在代码中重新定义宏的警告。链接错误仍然存在。
我正在使用 MATLAB R2012b 运行 OSX mavericks(遗憾的是,整个“clang”崩溃)。我非常感谢对此的任何帮助。
最佳答案
我可能已经解决了这个问题。
将它们定义为宏并没有起作用,但在我的例子中,我可以通过假设这些值是 float (因为它们将在 matlab 代码中)来逃脱。有了这些知识,我使用了 math.h fmin() fmax() 中的函数
这可以让代码编译良好。
再花一点时间,我将能够完全看到这是否有效,因为代码将完全可运行。
编辑:
是的!这解决了问题。明确知道这些值是 float 使我能够在 C 代码中使用 fmin 和 fmax 代替 min 和 max 来成功编译、链接和运行。
很抱歉使用此空间进行橡皮鸭调试,但也许这对将来的某人有用。祝你 future 的问题对象好运。
关于c - MATLAB mex - undefined symbol _max,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20524741/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!