help-octave
[Top][All Lists]
Advanced

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

My first guess with NDArray


From: Luca Tagliacozzo
Subject: My first guess with NDArray
Date: Fri, 4 May 2007 12:16:21 +0200

After reading through some example and sources I constructed a guess for the translation from .m to oct
suppose I pass into arg the dimensions of the various array (I know it is superflous but anyway..)
The problem was how to transalte this:
Imagine I have some n-dime array
G1(Chi,Chi,d)
G2(Chi,Chi,d)
and I want to create a n-d array given by:
 theta=zeros(Chi,Chi,d,d);
 
  for  i=1:d
    for j=1:d
      theta(:,:,i,j)=G1(:,:,i)*G2(:,:,j);
   
    
    endfor
  endfor



 const int d = args(0).int_value();
  const int Chi = args(1).int_value();
 
  NDArray G1(args(4).array_value());
 
  NDArray G2(args(3).array_value());
  dim_vector ind_th;
  ind_th.resize(4);
  ind_th(0)=Chi;
  ind_th(1)=Chi;
  ind_th(2)=d;
  ind_th(3)=d;
  NDArray TH(ind_th,0.); //controllare fill value
  Array<idx_vector> idxt (4);
  Array<idx_vector> idxg1 (3);
  Array<idx_vector> idxg2 (3);
  idxt(0) =idx_vector (Range (0., Chi-1.));   
  idxt(1) = idx_vector (Range (0., Chi-1.));
  idxg1(0) =idx_vector (Range (0., Chi-1));   
  idxg1(1) = idx_vector (Range (0., Chi-1.));
  idxg2(0) =idx_vector (Range (0., Chi-1.));   
  idxg2(1) = idx_vector (Range (0., Chi-1.));
  for(int i=0;i<d;i++){
    for(int j=0;j<d;j++){
    
     
     
      idxt(2) = idx_vector (i);
      idxt(3) = idx_vector (j);
      idxg1(2)= idx_vector(i);
      idxg2(2)= idx_vector (j);
      TH(idxt)=TH(idxt)+ G1(idxg1).matrix_value()*G2(idxg2).matrix_value() ;
     
    }}
 



But the compiler complains with :
 
error: request for member 'matrix_value' in 'G2.NDArray::<anonymous>.MArrayN<double>::<anonymous>.ArrayN<double>::<anonymous>.Array<T>::operator() [with T = double](((const Array<int>&)(& Array<int>(((const Array<idx_vector>&)((const Array<idx_vector>*)(& idxg2)))))))', which is of non-class type 'double'

any suggestion on how to correct this:




---------- Forwarded message ----------
From: Luca Tagliacozzo < address@hidden>
Date: May 3, 2007 4:48 PM
Subject: writing oct files
To: address@hidden

I am not sure this is the place to post such a question.
I have a working .m file.
I would like to pass it to an oct file.
I have some major questions.
Imagine I have some n-dime array
G1(Chi,Chi,d)
G2(Chi,Chi,d)
and I want to create a n-d array given by:
 theta=zeros(Chi,Chi,d,d);
 
  for  i=1:d
    for j=1:d
      theta(:,:,i,j)=G1(:,:,i)*G2(:,:,j);
   
    
    endfor
  endfor


.
I should be able to address the 2dim subarray of theta to copy inside the values of the product G1,G2...


Have you any clue to what the C++ sintax would be?

reply via email to

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