Boost logo

Boost Users :

Subject: Re: [Boost-users] multi_array : using double** from 3rd party lib
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-24 03:36:25


-----Original Message-----
From: "alfC" [alfredo.correa_at_[hidden]]
Date: 24/02/2010 08:24 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] multi_array : using double** from 3rd party lib

> and I wish to pass the "subarray" as a double** argument and call their function .It's not possible, is it?

you have to create the array of pointers:

double trace(double** arr){
  double ret=0;
  for(unsigned i=0; i!=4; ++i){
      ret+=arr[i][i];
  }
  return ret;
}

int main(){
  boost::multi_array<double, 7> a(boost::extents[2][2][2][2][2][4]
[4]);
  a[1][1][1][1][1][0][0]=8;
  a[1][1][1][1][1][3][3]=3;

  double** sarr=new double*[4];
  for(unsigned i=0; i!=4; ++i){
    sarr[i]=(&a[1][1][1][1][1][i][0]);
  }
  std::cout<< trace( sarr ) <<std::endl; //outputs 11
  return 0;
}
, but probably you wanted something simpler.

> I am actually able to override their function that takes in a double** data.
>
> Can it work then?

If you can "override" (sic) the function that takes the data, can't
you just replace by some multi_array<double, 2>, if there is no
pointer arithmetic in the function then that it is easy to do. right?

Alfredo
_______________________________________________

The function is a virtual member function of a class.
It has signature
  virtual f(double** data, ....)

So I can override in my derived class, but then I can only override it with the same signature.

creating the array of pointers is what the library does in their default implementation.
But for me, I have the data already in the array, so it is a waste of runtime and memory,

anyways, you confirmed there is no way around this,

thanks very much,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net