我对h这个实验的价值感到有些困惑.在cpp,
int h,J=3,n=200,p=3,h_m=(n+p+1)/2;
float rt=(float)h_m/n;
for(int j=0,j<J,j++){
h=floor((j+1)/J*rt*(n-p-1)+p+1);
std::cout<<h<<" "<<j<<" "<<rt<<" "<<n-p-1<<" "<<h_i<<" "<<J<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
得到:
4 0 0.51 196 7 3
4 1 0.51 196 7 3
103 2 0.51 196 7 3
Run Code Online (Sandbox Code Playgroud)
我想要(这是在R):
n<-200
p<-3
h_m<-as.integer((n+p+1)/2)
J<-3
j<-0:(J-1)
rt<-h_m/n
floor((j+1)/J*rt*(n-p-1)+p+1)
[1] 37 70 103
Run Code Online (Sandbox Code Playgroud)
cpp构造有什么问题?
在本征中,构造:
(R.array() < s).select(P,Q);
Run Code Online (Sandbox Code Playgroud)
当 P、Q 中的一个或两个是向量(与 R 的长度相同)时有效。但是一旦它们都是标量,我就会收到编译错误。
我的问题是;select存在两个标量时的行为是特征警告我有更有效构造的一种方式吗?如果有,它们是什么?
我正试图用cxx-11's std::unique()来找到一个独特的元素array:
#include <iostream>
#include <algorithm>
#include <vector>
#include <typeinfo>
int main(){
const int n=11;
double x[n],a3[n],a1[n];
x[0]=-0.717778;
x[1]=-0.496843;
x[2]=-0.429063;
x[3]=-0.3596;
x[4]=-0.205607;
x[5]=0.0730536;
x[6]=0.138018;
x[7]=0.585526;
x[8]=2.40104;
x[9]=3.75268;
x[10]=4.55704;
a3[0]=0.790832;
a3[1]=0.569896;
a3[2]=0.502116;
a3[3]=0.432653;
a3[4]=0.343625;
a3[5]=0.512472;
a3[6]=0.56708;
a3[7]=1.01459;
a3[8]=2.32799;
a3[9]=3.67962;
a3[10]=4.48398;
std::cout.precision(10);
std::copy(a3,a3+n,a1);
for(int i=0;i<n;i++) a1[i]+=x[i];
std::sort(a1,a1+n);
for(int i=0;i<n;i++) std::cout << a1[i] << std::endl;
std::cout << "---" << std::endl;
int n_1=std::unique(a1,a1+n)-a1;
std::cout << "length of unique subvector " << n_1 << std::endl;
std::cout << "---" << std::endl; …Run Code Online (Sandbox Code Playgroud) 这一切都在标题中.
请考虑以下代码:
#include <iostream>
#include <algorithm>
#include <vector>
#include <typeinfo>
using namespace std;
int main(){
const int n=12;
double x[n];
x[0]=-0.717778;
x[1]=-0.496843;
x[2]=-0.429063;
x[3]=-0.3596;
x[4]=-0.205607;
x[5]=0.0730536;
x[6]=0.138018;
x[7]=0.585526;
x[8]=2.40104;
x[9]=3.752680001; //here
x[10]=3.75268;
x[11]=4.55704;
std::cout << std::is_sorted(x,x+n) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想它返回1(真正的):虽然我可以看到,x[9] 是大于x[10],它们之间的差值小于1e-8
所以我带他们来是平等的.
所以这是一个非常酷的Docker 文件.
为了运行它,我做:
wget https://cran.r-project.org/src/contrib/FastRCS_0.0.7.tar.gz
tar -xvzf FastRCS_0.0.7.tar.gz
docker run --rm -ti -v $(pwd):/mnt rocker/r-devel-ubsan-clang check.r --setwd /mnt -a --install-deps FastRCS_0.0.7.tar.gz
Run Code Online (Sandbox Code Playgroud)
但现在假设我想保存这个DockerFile并从当前目录运行保存的版本(即不只是github上的那个).我怎样才能做到这一点?
我的想法是我需要自定义这个DockerFile并运行自定义版本.
我想知道通过调用构造函数(如下面的代码中)或者如果这两个构造之间的差异Box,使用智能指针(如Box3下面的代码中)声明(对于我更经典)声明是否有任何优势Box2主观偏好问题.
#include <iostream>
#include <memory>
class Box{
private:
double length;
double width;
double height;
public:
Box(double lengthValue, double widthValue, double heightValue);
double volume() const;
};
Box::Box(double lValue, double wValue, double hValue):
length {lValue}, width {wValue}, height {hValue} {
}
double Box::volume() const {
return length * width * height;
}
int main() {
Box Box2 {1.5,2.5,3.5};
std::cout << Box2.volume() << std::endl;
auto Box3 = std::make_unique<Box>(1.5,2.5,3.5);
std::cout << Box3->volume() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)