现在我正在使用ArrayFire,遇到了一些奇怪的事情。例如:
A dim is 257 x 1 x 1 x 1
af::floor(A) dim is 1 x 1 x 1 x 257
2*A dim is 1 x 1 x 1 x 257
A-1 dim is 1 x 1 x 1 x 257
A-af::constant(1,A.dims()) is 257 x 1 x 1 x 257
其中A
的产生来源:
for (size_t jloop = 0; jloop < T; ++jloop){ //T=1600
gfor (af::seq ploop, K){ //K=257
auto A = matrix(ploop,jloop,0,0);//matrix dim is K*T*1*1
....
所以我必须一直使用af::moddims
。但这真的很奇怪。有类似问题的人吗?
整个for
和gfor
部分如下:
auto Z_add = af::constant (0,af::dim4(K, T, K, noiseDims[3])); // Z_add is Z
auto Z_grad = af::constant (0,af::dim4(K, T, K, noiseDims[3])); // Z_grad is partial(Z_pji)/partial(m_p_j)
for (size_t iloop = 0; iloop < K; ++iloop){
for (size_t jloop = 0; jloop < T; ++jloop){
absinput_after_blur(iloop,jloop,af::span,af::span) = absinput(iloop,jloop,af::span,af::span);
gfor (af::seq ploop, K){
auto m_p_j = af::moddims(m(ploop,jloop,0,0),K); // dim of K*1*1*1
auto m_floor = af::floor(m_p_j); // dim of K*1*1*1
auto sum_m_p_j=m_floor*(2*m_p_j-m_floor-1) + m_p_j; // dim of K*1*1*1
auto sum_mpj_partial_to_mpj=2*m_p_j; // dim of K*1*1*1
auto condition1 = (af::abs(ploop-iloop)<m_p_j);
auto condition2 = ((ploop - iloop)==0);
auto Z_add_pji = condition1.as(f32) * ((!condition2).as(f32) * (af::moddims(absinput(ploop,jloop,0,0),K)*(m_p_j-af::abs(iloop-ploop))/sum_m_p_j) + condition2.as(f32) * (af::moddims(absinput(ploop,jloop,0,0),K)*(m_p_j-sum_m_p_j)/sum_m_p_j));
auto Z_grad_pji = condition1.as(f32) * ((!condition2).as(f32) * (af::moddims(absinput(ploop,jloop,0,0),K)*(sum_m_p_j - sum_mpj_partial_to_mpj*(m_p_j-abs(iloop-ploop)))/(sum_m_p_j*sum_m_p_j)) + condition2.as(f32) * (af::moddims(absinput(ploop,jloop,0,0),K)*((1-sum_mpj_partial_to_mpj)*sum_m_p_j-sum_mpj_partial_to_mpj*(m_p_j-sum_m_p_j))/(sum_m_p_j*sum_m_p_j)));
Z_add(ploop,jloop,iloop,af::span) = Z_add_pji;
Z_grad(ploop,jloop,iloop,af::span) = Z_grad_pji;
}
absinput_after_blur(iloop,jloop,af::span)+=af::sum(Z_add(af::span,jloop,iloop),0);
}
}
这些代码打算根据每个点的absinput
(模糊度)将absinput_after_blur
模糊为m
,并在Z_add
和{{1}中存储一些有用的矩阵}。