1

Now I'm using ArrayFire and met up with something strange. For example:

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

where A is generated from:

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
....

So I'll have to use af::moddims all the time. But that's really weird. Anyone with a similar problem?

the whole for and gfor part is as follows:

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);
  }
} 

The codes intend to blur absinput into absinput_after_blur based on m (blurring degree) of every point, and store some useful matrices in Z_add and Z_grad.

Dana Mark
  • 45
  • 7
  • Now I use: `auto A= af::moddims(matrix(ploop,jloop,0,0),K);` and it works well. Still don't know why. – Dana Mark Jul 10 '19 at 11:37
  • 1
    I don't understand what you are trying to do. You don't need the for loop or the gfor loop to do this. All those operations will be performed on every element. – Umar Arshad Jul 10 '19 at 12:33
  • Exactly for and gfor loop is used for other operations. – Dana Mark Jul 10 '19 at 13:10
  • 1
    I will need more context to help you. There are very few operations that require gfor. StackOverflow is not the best platform for these back an forth. Its better to discuss these things on our forums or slack channels. – Umar Arshad Jul 10 '19 at 13:41
  • Thank you @UmarArshad. Whole part of codes posted. And wondering where's the forum or slack channels. – Dana Mark Jul 10 '19 at 15:51
  • You can find the slack and forum information at the bottom of the repo's readme. https://github.com/arrayfire/arrayfire – Umar Arshad Jul 10 '19 at 20:37

0 Answers0