我想在正则表达式中使用字符串变量进行搜索模式和替换.预期的输出是这样的,
$ perl -e '$a="abcdeabCde"; $a=~s/b(.)d/_$1$1_/g; print "$a\n"'
a_cc_ea_CC_e
Run Code Online (Sandbox Code Playgroud)
但是当我将模式和替换移动到变量时,$1没有进行评估.
$ perl -e '$a="abcdeabCde"; $p="b(.)d"; $r="_\$1\$1_"; $a=~s/$p/$r/g; print "$a\n"'
a_$1$1_ea_$1$1_e
Run Code Online (Sandbox Code Playgroud)
当我使用"ee"修饰符时,它会出错.
$ perl -e '$a="abcdeabCde"; $p="b(.)d"; $r="_\$1\$1_"; $a=~s/$p/$r/gee; print "$a\n"'
Scalar found where operator expected at (eval 1) line 1, near "$1$1"
(Missing operator before $1?)
Bareword found where operator expected at (eval 1) line 1, near "$1_"
(Missing operator before _?)
Scalar found where operator expected at (eval 2) line 1, near "$1$1"
(Missing operator before $1?) …Run Code Online (Sandbox Code Playgroud) 如何有效地规范化CUDA中的矩阵列?
我的矩阵存储在column-major中,典型大小为2000x200.
该操作可以用以下matlab代码表示.
A = rand(2000,200);
A = exp(A);
A = A./repmat(sum(A,1), [size(A,1) 1]);
Run Code Online (Sandbox Code Playgroud)
这可以通过Thrust,cuBLAS和/或cuNPP有效地完成吗?
包括4个内核的快速实现如下所示.
想知道这些是否可以在1或2个内核中完成以提高性能,尤其是对于由cublasDgemv()实现的列求和步骤.
#include <cuda.h>
#include <curand.h>
#include <cublas_v2.h>
#include <thrust/device_vector.h>
#include <thrust/device_ptr.h>
#include <thrust/transform.h>
#include <thrust/iterator/constant_iterator.h>
#include <math.h>
struct Exp
{
__host__ __device__ void operator()(double& x)
{
x = exp(x);
}
};
struct Inv
{
__host__ __device__ void operator()(double& x)
{
x = (double) 1.0 / x;
}
};
int main()
{
cudaDeviceSetCacheConfig(cudaFuncCachePreferShared);
cublasHandle_t hd;
curandGenerator_t rng;
cublasCreate(&hd);
curandCreateGenerator(&rng, CURAND_RNG_PSEUDO_DEFAULT);
const size_t m = 2000, …Run Code Online (Sandbox Code Playgroud) 我尝试将svn repo克隆到git,但是一些分支在svn根目录中,如下所示.
我试过了
$ git clone svn://url/svn-root -T trunk -b branches -b branch1 -b branch2
Run Code Online (Sandbox Code Playgroud)
和
$ git clone svn://url/svn-root -T trunk -b branches -b .
Run Code Online (Sandbox Code Playgroud)
两者都未能克隆branch1和branch2正确.请帮忙.
svn-root
??? branch1
??? branch2
??? branches
? ??? branch3
? ??? branch4
??? trunk
Run Code Online (Sandbox Code Playgroud) 问题很简单:我有两个矩阵,A和B,它们是M乘N,其中M >> N.我想首先取A的转置,然后乘以B(A ^ T*B)到把它放到C中,这是N乘N.我已经为A和B设置了所有东西,但是如果没有它返回错误的答案我怎么称呼cublasSgemm?
我知道cuBlas有一个cublasOperation_t enum用于预先转置事物,但不知怎的,我还没有正确使用它.我的矩阵A和B按行主顺序排列,即[row1] [row2] [row3] .....在设备存储器中.这意味着A被解释为A转置,BLAS需要知道我的A是按列主要顺序.我目前的代码如下所示:
float *A, *B, *C;
// initialize A, B, C as device arrays, fill them with values
// initialize m = num_row_A, n = num_row_B, and k = num_col_A;
// set lda = m, ldb = k, ldc = m;
// alpha = 1, beta = 0;
// set up cuBlas handle ...
cublasSgemm(handle, CUBLAS_OP_T, CUBLAS_OP_N, m, n, k, &alpha, A, lda, B, ldb, &beta, C, ldc);
Run Code Online (Sandbox Code Playgroud)
我的问题:
我正确设置了m,k,n吗?
那么lda,ldb,ldc呢?
谢谢!
我想测试Intel MKL矩阵乘法,所以我包括,我只是使用cblas_dgemm函数,但它总是说
undefined reference to `cblas_dgemm'
Run Code Online (Sandbox Code Playgroud)
我也链接了-lmkl_core -lmkl_blas95_lp64 -lmkl_lapack95_lp64,但我在$MKLROOT/lib/intel64/目录中的库中有许多组合,错误仍然存在.请问有人给我一些建议吗?谢谢.
以下代码按预期工作。源代码,文件“file.txt”和“out.txt”都是用utf8编码的。但是,当我改变它不工作wchar_t,以char16_t在第一线main()。我已经尝试过 gcc5.4 和 clang8.0 与-std=c++11. 我的目标是替换wchar_t为char16_t, aswchar_t在 RAM 中占用两倍的空间。我认为这两种类型在 c++11 和更高版本的标准中同样得到很好的支持。我在这里想念什么?
#include<iostream>
#include<fstream>
#include<locale>
#include<codecvt>
#include<string>
int main(){
typedef wchar_t my_char;
std::locale::global(std::locale("en_US.UTF-8"));
std::ofstream out("file.txt");
out << "123?????abc" << std::endl;
out.close();
std::basic_ifstream<my_char> win("file.txt");
std::basic_string<my_char> wstr;
win >> wstr;
win.close();
std::ifstream in("file.txt");
std::string str;
in >> str;
in.close();
std::wstring_convert<std::codecvt_utf8<my_char>, my_char> my_char_conv;
std::basic_string<my_char> conv = my_char_conv.from_bytes(str);
std::cout << (wstr == conv ? "true" : "false") << std::endl;
std::basic_ofstream<my_char> wout("out.txt"); …Run Code Online (Sandbox Code Playgroud) 我遇到了段错,但不知道为什么.这是一个问题std::unique_ptr<BaseClass>(&DerivedClassObj)吗?谢谢.
这是代码
# test.cc
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
struct a {
virtual void x(){cerr<<"a.x"<<endl;}
virtual void y(){cerr<<"a.y"<<endl;}
virtual void z(){cerr<<"a.z"<<endl;x();y();}
};
struct b: public a {
virtual void y() {cerr<<"b.y"<<endl;}
};
int main(){
cerr<<0<<endl;
{
b bb;
vector<unique_ptr<a> > pb;
cerr<<1<<endl;
bb.z();
pb.push_back(unique_ptr<a>(&bb));
pb[0]->z();
cerr<<2<<endl;
}
cerr<<3<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是输出
0
1
a.z
a.x
b.y
a.z
a.x
b.y
2
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
这是编译命令
$ g++ -std=c++0x test.cc -o test
Run Code Online (Sandbox Code Playgroud)
和g++ …