help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NDArray oct file gives error with 4 dimension


From: niconeuman
Subject: NDArray oct file gives error with 4 dimension
Date: Thu, 6 Feb 2020 15:52:20 -0600 (CST)

Greetings,
I'm writing an oct-file for performing an operation between a 2D NDArray and
a 4D NDArray. Apparently trying to do

retMat(mu,nu) += D(ka,la)*gmnkl(mu,nu,ka,la);

does not compile. On the other hand, doing

retMat(mu,nu) += D(ka,ka)*gmnkl(mu,nu,ka);

compiles with no problem. Can anyone help me? 
Best regards,
Nicolas 

Below is the code for contractgD.cc,


#include <octave/oct.h>

DEFUN_DLD (contractgD, args, nargout,
           "This function takes as arguments D and gmnkl, and calculates the
matrix"
           "Jtemp which results from contracting gmnkl with D along
dimensions 3 and 4")
{

  NDArray D = args(0).array_value ();
  NDArray gmnkl = args(1).array_value ();

  const int lengthmu = gmnkl.dims()(0); //have to use it like this, not
NDArray.dims(i);
  const int lengthnu = gmnkl.dims()(1);
  const int lengthka = gmnkl.dims()(2);
  const int lengthla = gmnkl.dims()(3);

  octave_stdout << lengthmu << "\n";
  octave_stdout << lengthnu << "\n";
  octave_stdout << lengthka << "\n";
  octave_stdout << lengthla << "\n";
  octave_stdout << "gmnkl.ndims() = "  << "\n";
  octave_stdout << gmnkl.ndims() << "\n";
  octave_stdout << "gmnkl(1,1,1) = "  << "\n";
  octave_stdout << gmnkl(1,1,1) << "\n";
  octave_stdout << "gmnkl(1,1,1,1) = "  << "\n";
  octave_stdout << gmnkl(1,1,1,1) << "\n";
  dim_vector dvmn (lengthmu,lengthnu);

  NDArray retMat (dvmn);

  if (gmnkl.ndims() == 4){
  for(octave_idx_type mu = 0; mu < lengthmu; mu++){
    for(octave_idx_type nu = 0; nu < lengthnu; nu++){
      for(octave_idx_type ka = 0; ka < lengthka; ka++){
        for(octave_idx_type la = 0; la < lengthla; la++){
          retMat(mu,nu) += D(ka,la)*gmnkl(mu,nu,ka,la);
        }
      }
    }
  }
}

  octave_value_list retval (nargout);
  retval(0) = octave_value(retMat);
  return retval;
}



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]