我遇到了一个奇怪的quad功能问题.我quad用来计算简单积分,它工作了10到20次,然后Matlab发出以下错误:
Error using quad (line 75)
The integrand function must return an output vector of the same length as the input vector.
yteor(k) = quad(@(q)(exp(-(q).^2).*q.^2/(k.^2+1)), 0, 1);
Run Code Online (Sandbox Code Playgroud)
这里q和k是标量.我不知道什么是错的,为什么它在几个小时前工作.
编辑
这是我的代码
for k=1:100,
xteor(k)=step*k;
yteor(k)=quad(@(q)(exp(-(q).^2).*q.^2/((step.*k+1).^2)),0,1);
end plot(xteor,yteor,'r');
Run Code Online (Sandbox Code Playgroud) 我有一个示例代码:
#include <quadmath.h>
int main()
{
__float128 foo=123;
cosq(foo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下命令编译它:
g++ f128.cpp -lquadmath
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a /usr/lib64/libquadmath.so.0
g++ f128.cpp /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a /usr/lib64/libquadmath.so.0 /usr/lib64/gcc/x86_64-suse-linux/4.6/libquadmath.a
Run Code Online (Sandbox Code Playgroud)
所有这些命令都会产生同一个错误:
f128.cpp:(.text+0x1b): undefined reference to `cosq(__float128)'
Run Code Online (Sandbox Code Playgroud)
我也尝试声明cosq如下,但不包括在内quadmath.h.这种样式的声明在C++接口中用于其他程序中的fortran子例程,并且它们运行良好.
extern "C" __float128 cosq_(__float128 *op);
extern "C" __float128 cosq_(__float128 op);
extern "C" __float128 cosq(__float128 *op);
...and so on...
Run Code Online (Sandbox Code Playgroud)
结果是一样的.
然后我尝试cosq在Fortran中使用:
PROGRAM test
REAL*16 foo
REAL*16 res
foo=1;
res=cos(foo)
PRINT *,res
END
Run Code Online (Sandbox Code Playgroud)
这个程序编译和执行良好(用大量数字打印答案),所以cosq在其中工作.这个程序编译时没有选项:gfortran f128.f90.
操作系统是OpenSUSE 12.1,gcc版本是4.6.2.*.h,*.a和*.so文件由 …
我有一个很大的Git项目,我想用他们自己的存储库解剖到子项目中.Git的子树是完成这项任务的理想选择:首先
使用仅一个子文件夹的内容创建一个分支
git subtree split -P <name-of-folder> -b <name-of-new-branch>
Run Code Online (Sandbox Code Playgroud)
然后
将此分支拉入另一个存储库.
对于过渡阶段,我希望子项目是只读的,并从master中同步它们.对于每个要掌握的提交,我当然可以对所有子项目重复执行上述过程,但这似乎不太理想,因为它重新完成所有工作.
有没有办法将master合并到子树分支中?
在Python中,可以定义一个字典
a = {
'a': 'hhh',
'b': 123,
'jfa': {'j': 1.5, 'r': 'string'}
}
Run Code Online (Sandbox Code Playgroud)
在C++ 11中,我看到你可以
std::map<std::string, int> a = {
{"a", 1},
{"hh", 4}
};
Run Code Online (Sandbox Code Playgroud)
但实际上我希望值的类型不同(特别是允许字典作为值).是否有允许这样做的成语或库?有什么计划用于下一个标准吗?
今天早些时候,我们遇到了一个由以下 shell 管道引起的严重问题:
- name: get remote branches
shell: git ls-remote -h git@bitbucket.org:orga/repo.git | sed 's_.*refs/heads/__g'
register: branches_remote
Run Code Online (Sandbox Code Playgroud)
该git命令失败,而是整个管道的返回码为0。这是默认的bash / sh的行为。
要解决此问题,在 sh/bash 中,您可以set -o pipefail或set -e. 是否有可能在 ansible 中做到这一点,最好是对我的所有shell命令全局进行?
我想在Python中存储PNG图像,其中RGB值由列表给出
entries = [
[1, 2, [255, 255, 0]],
[1, 5, [255, 100, 0]],
[2, 5, [0, 255, 110]],
# ...
]
Run Code Online (Sandbox Code Playgroud)
(行,列,RGB三元组),以及[255, 255, 255]有关图像总尺寸的默认值和信息.
使用PIL,我当然可以转换entries为密集的m-by n-by- 3matrix,但这不适合内存; 矩阵维数可以在万里.
是否有其他方法可以使用上述信息创建PNG图像?
python png image-processing sparse-matrix python-imaging-library
我想在浏览器扩展中使用Fetch API来下载资源并计算其哈希值.以下作品(通过Browserify使用加密)
fetch(url).then(function(response) {
return response.blob();
}).then(function(data) {
var a = new FileReader();
a.readAsBinaryString(data);
a.onloadend = function() {
var hash = crypto.createHash(hashType);
hash.update(a.result, 'binary');
return hash.digest('hex');
};
})
Run Code Online (Sandbox Code Playgroud)
但有一个缺点,我必须等待,a.onloadend而我想要嵌入它的上下文需要Promise返回.此外,首先获取整个blob似乎很奇怪,然后将其读入一个FileReaderjust以便将其转储到createHash之后.
任何提示?
我想正则表达式匹配字符串
"abc", "d,e" , "", ",f"
Run Code Online (Sandbox Code Playgroud)
这样,组abc,d,e``和 ,f(没有引号)是分开匹配的.
随着小组
"([^"]*)"
Run Code Online (Sandbox Code Playgroud)
匹配这些"abc"位,我假设正则表达式
(?:\s*"([^"]*)"\s*,)\s*"([^"]*)"\s*
Run Code Online (Sandbox Code Playgroud)
会做的伎俩.但是,它只匹配abc和d,e.
任何提示?
我有一个(大)整数数组,如
materials = [0, 0, 47, 0, 2, 2, 47] # ...
Run Code Online (Sandbox Code Playgroud)
几乎没有独特的条目,我想将其转换为索引字典,即,
d = {
0: [0, 1, 3],
2: [4, 5],
47: [2, 6],
}
Run Code Online (Sandbox Code Playgroud)
这样做的最有效方法是什么?(欢迎使用 NumPy。)
我正在将 C++ 库与越来越流行的pybind11连接起来,以获得本机 Python 绑定;配置是通过CMake.
我的CMakeLists.txt样子
cmake_minimum_required(VERSION 3.0)
project(foo)
FILE(GLOB foo_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
FIND_PACKAGE(pybind11 REQUIRED)
pybind11_add_module(mylib ${foo_SRCS})
Run Code Online (Sandbox Code Playgroud)
然而,这似乎没有注册安装规则。因此,虽然构建树中的一切都按预期工作,但make install没有执行任何操作。
需要添加什么才能按顺序安装?