E***e 发帖数: 3430 | 1 【 以下文字转载自 GPGPU_HC 俱乐部 】
发信人: Echte (Liebe), 信区: GPGPU_HC
标 题: GTX 580在MATLAB上第一跑
发信站: BBS 未名空间站 (Mon Mar 3 20:48:27 2014, 美东)
3 asset (correlated) basket option (barrier)
3,000,000模拟路
2*252时间步
全双精度
用时31.850787秒
相对i-7-3770有5.3倍性能提升
感觉已经是相当不错
另外由于是basket
每个路径都涉及矩阵运算
所以没法写成elementwise的程序
估计至少丢了1/3的性能,比较遗憾
tic
R = gpuArray(3000000);
dt = gpuArray(1/252);
sqrtdt = sqrt(dt);
TTM = gpuArray(3);
T = gpuArray(TTM/dt);
N = gpuArray(3);
SLAG = gpuArray([100 100 100]');
SLAG = repmat(SLAG,[1 R]);
W = gpu... 阅读全帖 |
|
l*******d 发帖数: 101 | 2 网上下的一段程序。需要分析复杂度。中间的循环完全把我绕糊涂了。该怎样想呢?
谢谢回帖!
void repmat(char *dest, const char *src, int ndim, int *destdimsize,
int *dimsize, const int *dims, int *rep)
{
int d = ndim-1;
int i, chunk;
/* copy the first repetition into dest */
if(d == 0) {
chunk = dimsize[0];
memcpy(dest,src,chunk);
}
else {
/* recursively repeat each slice of src */
for(i=0;i
repmat(dest + i*destdimsize[d-1], src + i*dimsize[d-1],
ndim-1, destdimsize, dimsize, |
|
S*********g 发帖数: 5298 | 3
return
leverage
这个j循环可以改成
rr(y,:,:)=repmat(su(y,:),1,s)-fai.*repmat(leverage./(1-leverage,q,1);
i循环也可以同样变成矩阵操作,
最后,这两层循环,一行就可以解决了
return,
.
i)
num2str
); |
|
l********a 发帖数: 1154 | 4 xx = repmat(x,10,1);
tt = repmat(t',1,10);
sum(xx<=tt,2)
x和t就是你原来的1*10的行向量
最后打印出的结果是10*1的列向量,每行等于sum(x |
|
r****y 发帖数: 1437 | 5
most straightforward way
for i = 1:3
e(:, :, i) = reshape(repmat(d(:, i), 1, 3), 3, 3, 1);
end
I suspect "resahpe" is not necessary. You can try it.
repmat(d(:, 1), 1, 3) |
|
g******s 发帖数: 733 | 6 I wonder why the following codes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:3
e(:, :, i) = repmat(d(:, i), 1, 3);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cannot be simplied as
e(:,:,1:3)=repmat(d(:,1:3),1,3);
Anyone has any ideas?
Thanks a lot! |
|
c****r 发帖数: 576 | 7 Matlab矩阵计算也就零点几秒,不用循环。
tic;
s = m * repmat((0:1999)',1,2000);
allsum = sum(s(:)) + sum(0:1999);
toc
Elapsed time is 0.478149 seconds |
|
r*g 发帖数: 3159 | 8 < 就是设计上不如。
例如 X- mean(X)这种东西,matlab 还要bsxfun 或者 repmat。不如numpy的处理。
这俩都不如J对任意维数组加rank/frame的处理。 |
|
k**********g 发帖数: 989 | 9 Depends on how big the area is.
More precisely, what is the maximum distance from the set of missing pixels
to the nearest valid pixel.
The general technique is called Infilling.
Here's just an example from Google search result. http://research.microsoft.com/pubs/67276/criminisi_tip2004.pdf
When the text is very thin, a masked local averaging will do the job.
img = imread( filename ) ;
[ nrows, ncols, nchan ] = size ( img ) ;
imgColor = double ( img ) .* (1 / 255) ;
imgGray = rgb2gray ( imgColor... 阅读全帖 |
|
r****y 发帖数: 1437 | 10
Let a is your vector, and B is the matrix,
repmat(a', 1, 100) .* B |
|
r****y 发帖数: 1437 | 11
B - repmat(a', 1, 100)
You really need to learn some basic about matlab ah. |
|
g******s 发帖数: 733 | 12 Thank you so much. You are right, reshape is not necessary. repmat is really
good :)) I am not sure if we can remove the for loop in the codes. |
|
g******s 发帖数: 733 | 13 比如复制a=[3 2 6]成
b(:,:,1)=[3 3 3;3 3 3;3 3 3]
b(:,:,2)=[2 2 2;2 2 2;2 2 2]
b(:,:,3)=[6 6 6;6 6 6;6 6 6];
使用下面这段代码,能去掉循环吗? 先谢了!
for i=1:3
e(:,:,i)=repmat(b(i),3,3);
end |
|
s****g 发帖数: 52 | 14 c=repmat(a,9,1);
e=reshape(a,3,3); |
|
g******s 发帖数: 733 | 15 在MATLAB中.如果是一维向量减另一个一维向量的话好象很容易,repmat成二维矩阵就行.
二维矩阵的每个元素减另一个二维矩阵的每个元素也能这样吗? |
|
r****y 发帖数: 1437 | 16 sure
you define you own color table, let it be
[1 1 1]
monotonically changes to [0 0 0]
e.g cmap = repmat([0:1/63:1]', 1, 3);
colormap(cmap);
If you use colorbar before this set of commands,
replot your colorbar to reflect the changes as well.
|
|
j**u 发帖数: 6059 | 17 cmap = repmat([1:-1/63:0]', 1, 3);
就把颜色该成从白到黑了。 |
|
j**u 发帖数: 6059 | 18 ☆─────────────────────────────────────☆
jzxu (自然) 于 (Mon Apr 16 17:27:31 2007) 提到:
matlab要输出一个数据文本文件给C程序使用,里面的数据都是整数。
如果简单的使用save -ascii,文件里面都是浮点数,如何用matlab
将一个整数矩阵写入一个文本文件?
☆─────────────────────────────────────☆
jzxu (自然) 于 (Mon Apr 16 17:30:22 2007) 提到:
一个可能的解答。
fid = fopen('datafile','w') ;
fprintf(fid, [repmat('%d ', 1, size(dataarray,2)), '\n'], dataarray) ;
fclose(fid) ;
☆─────────────────────────────────────☆
jzxu (自然) 于 (Mon Apr 16 17:31:35 2007) 提到:
用其他任何方法解答此问题者,皆有包子,长 |
|
c****r 发帖数: 576 | 19 多谢。顺便问一个Matlab语句
>> seed = [seed,repmat(head2(1+length(seed)),(~isempty(strfind(head2(2+
length(seed):
length(head2)),[seed,head2(1+length(seed))]))),1)]
是否过于复杂?这是个递归语句,用于实现我帖子里的算法。写成函数+if - else结
构更好? |
|
|
m*f 发帖数: 8162 | 21 算了,repmat+reshape,就决定这样了 |
|
i******t 发帖数: 370 | 22 This code is more efficient though harder to read:
e = A-repmat(a, [size(A, 1), 1]);
i = find(sum(e==0, 2)==size(A, 2));
"find" only operates on a vector so it's fast. |
|
l*****e 发帖数: 594 | 23 把matlab code帖出来了
f0 = 1e6; % Base frequency
osr = 4; % Over sampling Rate
fs = 2*osr*f0; % sampling frequency
ts = 1/fs;
ncyc = 1; % number of cycles
ts_input = [ones(osr,1);-1*ones(osr,1)];
ts_input = repmat(ts_input,[ncyc 1]);
xt = (0:length(ts_input)-1)*ts;
xt_us = xt*1e6;
figure,
plot(ts_input,'*-')
nfft = 4096;
spc = fftshift(fft(ts_input,nfft));
fs_mhz = fs*1e-6;
fx = (-nfft/2:nfft/2-1)/nfft*fs_mhz;
spc_db = 20*log10(abs(spc));
spc_norm = spc_db-max(spc_db);
figure,
plot(fx,sp... 阅读全帖 |
|
|
m*****e 发帖数: 207 | 25 repmat(1:4, 4, 1)
or
ones(4,1)*(1:4) |
|
z*******9 发帖数: 167 | 26 Showing the size of the matrices is very useful for other
to help you.
Another way to do it is
Y = X.*repmat(y',[size(X,1),1]);
Result = Y*X';
assuming y is a column vector. |
|