我正在玩LowRankQP()
R中的软件包,甚至设置verbose=FALSE
仍会产生大量输出(参见下面的示例).
输出来自代码的编译部分.R中是否有一种方法(包装函数?)在不修改底层编译代码的情况下调用LowRankQP()
绝对静音(即不在屏幕上打印任何内容)(与此软件包关联的电子邮件地址仍未激活)?
library(LowRankQP)
Vmat <- matrix(0,6,6)
diag(Vmat) <- c(1, 1,1,0,0,0)
dvec <- c(0,-5,0,0,0,0)
Amat <- matrix(c(-4,-3,0,-1,0,0,2,1,0,0,-1,0,0,-2,1,0,0,-1),6,3)
bvec <- c(-8,2,0)
uvec <- c(100,100,100,100,100,100)
aa<-LowRankQP(Vmat,dvec,t(Amat),bvec,uvec,method="CHOL")
# LowRankQP CONVERGED IN 15 ITERATIONS
#
# Primal Feasibility = 2.5719308e-16
# Dual Feasibility = 7.1949984e-16
# Complementarity Value = 3.3066705e-11
# Duality Gap = 3.3065273e-11
# Termination Condition = 9.7802929e-12
Run Code Online (Sandbox Code Playgroud)
这是我想要的"LowRankQP收敛于15次迭代"的部分.
Ubuntu 11.04,R版本2.12.1和LowRankQP()1.0.1.
在带有标志的上一代i7处理器上使用GCC 4.8.1:
-O3 -ftree-vectorizer-verbose=5 -fomit-frame-pointer -DNDEBUG -fno-operator-names -msse2 -mfpmath=sse -march=native -funsafe-math-optimizations -ffast-math
Run Code Online (Sandbox Code Playgroud)
(例如所有'下摆!)
我明白了:
.cpp:31:note: not vectorized: relevant stmt not supported: D.56044_367 = __builtin_logf (D.55726_232);
Run Code Online (Sandbox Code Playgroud)
对于该行:
for(i=0;i<N5;i++) d3[i]=std::log(d2[i]);
Run Code Online (Sandbox Code Playgroud)
这个'错误'消息是什么意思?(d3和d2是浮点数的向量).向量化日志功能是否无望?
所以,我有这个循环的C++代码:
for(i=0;i<(m-1);i++) N4[i]=(i+m-1-Rigta[i]-1-N3[i])/N0;
Run Code Online (Sandbox Code Playgroud)
涉及的所有数量都是int
.从GCC的矢量化报告中我得到:
babar.cpp:233: note: ===== analyze_loop_nest =====
babar.cpp:233: note: === vect_analyze_loop_form ===
babar.cpp:233: note: === get_loop_niters ===
babar.cpp:233: note: not vectorized: number of iterations cannot be computed.
babar.cpp:233: note: bad loop form.
Run Code Online (Sandbox Code Playgroud)
我想知道为什么'无法计算迭代次数'!?FWIW,m
被宣布为
const int& m
.更令人费解的是,我所拥有的代码与上面相同:
for(i=1;i<(m-1);i++) a2[i]=(x[i]+x[i+m-1])*0.5f;
Run Code Online (Sandbox Code Playgroud)
以上的循环被矢量化就好了(这里a2
和x
是floats
).我正在编译
-Ofast -ftree-vectorizer-verbose=10 -mtune=native -march=native
Run Code Online (Sandbox Code Playgroud)
在i7上的GCC 4.8.1上的标志.
提前致谢,
在@nodakai的想法之后,我尝试了这个:
const int mm = m;
for(i=0;i<(m-1);i++) N4[i]=(i+m-1-Rigta[i]-1-N3[i])/N0;
Run Code Online (Sandbox Code Playgroud)
这不会让我安静下来:
babar.cpp:234: note: not vectorized: relevant stmt not supported: D.55255_812 = D.55254_811 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的c++
<random>
标头与全局固定种子一起使用。这是我的第一个玩具示例:
#include <iostream>\n#include <random>\nint morerandom(const int seednum,const int nmax){\n std::mt19937 mt;\n mt.seed(seednum);\n std::uniform_int_distribution<uint32_t> uint(0,nmax);\n return(uint(mt));\n}\nint main(){\n const int seed=3;\n for (unsigned k=0; k<5; k++){\n std::cout << morerandom(seed,10) << std::endl;\n }\n return 0;\n} \n
Run Code Online (Sandbox Code Playgroud)\n\n所以问题是:如何修复 中的种子main()
并从 \n 中获得可重现的输出morerandom()
?
换句话说,我需要调用morerandom()
很多(k
会很大),但这些随机数应该始终使用相同的值来绘制seed
. 我想知道定义整个块是否可能/更有效:
std::mt19937 mt;\nmt.seed(seednum);\n
Run Code Online (Sandbox Code Playgroud)\n\n在 main 内部并传递mt
给morerandom()
. 我尝试过:
#include <iostream>\n#include <random>\nint morerandom(const int nmax)\n{\n\n std::uniform_int_distribution<uint32_t> uint(0,nmax);\n return(uint(mt));\n}\n\n\nint main()\n{\n const int …
Run Code Online (Sandbox Code Playgroud) 我在c++
代码中经常使用函数指针,总是符合这个简单的规范示例(例如,函数具有相同的I/O,但所需的操作仅在运行时已知):
#include <iostream>
using namespace std;
int add(int first, int second){
return first + second;
}
int subtract(int first, int second){
return first - second;
}
int operation(int first, int second, int (*functocall)(int, int)){
return (*functocall)(first, second);
}
int main(){
int a, b;
int (*plus)(int, int) = add;
int (*minus)(int, int) = subtract;
a = operation(7, 5, plus);
b = operation(20, a, minus);
cout << "a = " << a << " and b = " << b …
Run Code Online (Sandbox Code Playgroud) 假设我有以下矩阵:
cm<-structure(c(100, 200, 400, 800, 100, 200, 400, 800, 100, 200,
400, 800, 100, 200, 400, 800, 100, 200, 400, 800, 0, 0, 0, 0,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5,
-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4,
-0.4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, …
Run Code Online (Sandbox Code Playgroud) 正在做(R3.4,ubuntu 16.04,rgl 0.95.1441):
library(rgl)
open3d()
Run Code Online (Sandbox Code Playgroud)
返回:
Error in rgl.clear(type, subscene = subscene) :
object 'rgl_clear' not found
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x, y)
plot3d(x, y, z, col = rainbow(1000))
Error in currentSubscene3d() : object 'rgl_getsubsceneid' not found
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我有一个 Pandas Dataframe,每行至少有 4 个非 NaN 值,但位于不同的列:
Index Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8
1991-12-31 100.000 100.000 100.000 89.123 NaN NaN NaN NaN
1992-01-31 98.300 101.530 100.000 NaN 92.342 NaN NaN NaN
1992-02-29 NaN 100.230 98.713 97.602 NaN NaN NaN NaN
1992-03-31 NaN NaN 102.060 93.473 98.123 NaN NaN NaN
1992-04-30 NaN 102.205 107.755 94.529 94.529 NaN NaN NaN
Run Code Online (Sandbox Code Playgroud)
(我只显示前 8 列)我想将其转换为每行 4 列的数据框。这些行应仅包含该日期的前四个(从左到右读取)非 NaN 值。
每行的顺序很重要。
测试用例:
df = pd.DataFrame([[np.nan, 2, np.nan, 0],
[3, 4, np.nan, 1],
[np.nan, np.nan, np.nan, 5],
[np.nan, 3, np.nan, 4]],
columns=list('ABCD'))
Run Code Online (Sandbox Code Playgroud)
其中A [i + 1,j],A [i-1,j],A [i,j + 1],A [i,j-1]是与A [i,j]相邻的条目集合.
用这么多的话说,这个:
A B C D
0 NaN 2.0 NaN 0
1 3.0 4.0 NaN 1
2 NaN NaN NaN 5
3 NaN 3.0 NaN 4
Run Code Online (Sandbox Code Playgroud)
应该成为这样的:
A B C D
0 3.0 2.0 2.0 0.0
1 3.0 4.0 4.0 1.0
2 3.0 4.0 5.0 5.0
3 3.0 3.0 4.0 4.0
Run Code Online (Sandbox Code Playgroud) 我有一个巨大的文本文件。我需要替换所有出现的这种三行模式:
|pattern|some data|
|giberish|,,
|pattern|some other data|
Run Code Online (Sandbox Code Playgroud)
在模式的最后一行:
|pattern|some other data|
Run Code Online (Sandbox Code Playgroud)
删除模式的前两行,仅保留最后一行。
|pattern|
|pattern|
以两个逗号开头,但不以两个逗号结尾。|pattern|
以两个逗号开头且不以两个逗号结尾。我尝试了这个:
sed 'N;N;/^|pattern|.*\n.*,,\n|pattern|.*/I,+1 d' trial.txt
Run Code Online (Sandbox Code Playgroud)
运气不好
编辑:这是一个更重要的例子
#!/usr/bin/env bash
cat > trial.txt <<EOL
|pattern|sdkssd|
|.x,mz|e,dsa|,,
|pattern|sdk;sd|
|xl'x|cxm;s|,,
|pattern|aslkaa|
|l'kk|3lke|,,
|x;;lkaa|c,c,s|
|-0-ses|3dsd|
|xk;xzz|'l3ld|
|0=9c09s|klkl32|
|d0-zox|m,3,a|
|x'.za|wkl;3|
|=-0poxz|3kls|
|x-]0';a|sd;ks|
|wsd|756|
|sdw|;lksd|
|pattern|askjkas|
|xp]o]xa|lk3j2|,,
|]-p[z|lks|
EOL
Run Code Online (Sandbox Code Playgroud)
它应该变成:
|pattern|aslkaa|
|l'kk|3lke|,,
|x;;lkaa|c,c,s|
|-0-ses|3dsd|
|xk;xzz|'l3ld|
|0=9c09s|klkl32|
|d0-zox|m,3,a|
|x'.za|wkl;3|
|=-0poxz|3kls|
|x-]0';a|sd;ks|
|wsd|756|
|sdw|;lksd|
|pattern|askjkas|
|xp]o]xa|lk3j2|,,
|]-p[z|lks|
Run Code Online (Sandbox Code Playgroud)
@zdim:
文件的前三行:
|pattern|sdkssd|
|.x,mz|e,dsa|,,
|pattern|sdk;sd|
Run Code Online (Sandbox Code Playgroud)
满足模式。因此它们被替换为
|pattern|sdk;sd|
Run Code Online (Sandbox Code Playgroud)
因此文件的顶部现在变为:
|pattern|sdk;sd|
|xl'x|cxm;s|,, …
Run Code Online (Sandbox Code Playgroud)