Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting Interpolating Function via mathlink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50799] Re: Extracting Interpolating Function via mathlink
  • From: Mario Drobics <mario.drobics at scch.at>
  • Date: Wed, 22 Sep 2004 00:10:57 -0400 (EDT)
  • References: <ciomuh$r8l$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The best way to do this is to use lists in Mathematica which you convert 
to STL-vectors in in C++. When getting the list in C++ you get its 
header and its length first. Then you can resize the vector and read in 
the elements accordingly. This works very fast, also for long lists.

Roughly it works like this (not tested!):
void getVector (std::vector<T> & con)
{
   std::string name;
   long count;

   int const valType = MLGetNext(ml);
   if (valType == MLTKFUNC)
     {
       char const * cstr;

       MLGetFunction(ml, &cstr, &count);
       name = std::string(cstr);
       MLDisownSymbol(ml, cstr);

       con.clear();
       con.resize(count);

       for (size_t i = 0; i < count; i++)
       {
         getElement(con[i]);
       }
     }
   else
   {
     throw error("expected a function");
   }
}


Regards,
-mario-

Peter Saffrey wrote:
> I'm writing an application that interfaces with Mathematicas
> differential equation solving routines via mathlink. The equations are
> loaded and solved and then I need to extract the resulting
> interpolating functions for use in the rest of my application. At the
> moment, I have a mathematica function which dumps the data points, one
> by one, which I grab and insert into C++ objects. This works, but it's
> very slow on large functions - when there are 10000 data points, this
> takes about 30 seconds per function.
> 
> I suspect the reason for the poor performance is that I'm calling too
> many mathlink functions - each data point is three "getpacket" calls,
> one for the a list header, and one for each part of the data point. Is
> there a way I can do this more quickly? How about exporting the whole
> list of points as some kind of C++ structure I can then parse with
> using mathlink? Does anybody know how I might do this?
> 
> Thanks,
> 
> Peter
> 


  • Prev by Date: Re: Special case of plotting a 3D function
  • Next by Date: Re: Re: Re: Forcing a Derivative
  • Previous by thread: Re: Extracting Interpolating Function via mathlink
  • Next by thread: Special case of plotting a 3D function