Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a MathLink Function Lists With Different Structures
    text
    copied!<p>I've been developing a MathLink application with a function that accepts two lists, e.g.</p> <pre><code>:Pattern: g[zi_List, fi_List] </code></pre> <p>which I intended to pull in to the function manually. Both lists can be real or complex with the result being complex if either parameter is complex. Additionally, <code>fi</code> could be a list of square matrices, but <code>zi</code> is to remain a one dimensional list. </p> <p>Within the <a href="http://reference.wolfram.com/mathematica/guide/AlphabeticalListingOfMathLinkCFunctions.html" rel="nofollow">MathLink C API</a>, the most straightforward seeming function to use is <a href="http://reference.wolfram.com/mathematica/ref/c/MLGetReal64Array.html" rel="nofollow"><code>MLGetReal64Array</code></a> which can handle both real and complex data types as <code>Complex</code> shows up as the innermost <code>Head</code> of the array. And, once complexity is determined, the array can be cast to <code>std::complex&lt;double&gt;</code> or the C99 complex type, if appropriate. Now, <code>MLGetReal64Array</code> doesn't handle non-rectangular <code>Lists</code>, so each <code>List</code> element must have the dimensionality of the others and be of the same type: real of complex. Oddly, though, with a function that accepts a single <code>List</code> parameter, <code>MLGetReal64Array</code> returns a data structure that has a one element <code>List</code> as its outermost element, i.e. inputing <code>h[ {1, 3, 5} ]</code> returns <code>List[List[1,3,5]]</code> on the c-side of things. </p> <p>It turns out that for a two list function, like <code>g</code>, a single call to <code>MLGetReal64Array</code> will return both parameters at once, i.e. <code>g</code> receives <code>List[ zi, fi ]</code>. Since I plan on preprocessing each list for uniformity of structure and element type, ensuring that both had the same element type wouldn't be a problem. But, I'd like for <code>fi</code> to be a list of matrices, and <code>MLGetReal64Array</code> causes a <code>MLEGSQ: MLGet() called out of sequence</code> error.</p> <p>So, my questions are: can I use <code>MLGetReal64Array</code> to get both lists? how would I go about it? And, if I can't use <code>MLGetReal64Array</code>, what are my alternatives?</p> <p>I'm thinking that if <code>MLGetReal64Array</code> is correct about the structure, I can pop the outer <code>List</code> off the link by using <a href="http://reference.wolfram.com/mathematica/ref/c/MLGetFunction.html" rel="nofollow"><code>MLGetFunction</code></a> which would then allow me to use <code>MLGetReal64Array</code> for each parameter. As of yet, I haven't tried it. But, in the meantime, I would appreciate any suggestions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload