Walking Randomly » Making frank NAG functions accessible to Python

This is the least light division of the cryptogram. distinctively If you are using a multitudinous implementation of the NAG C library then you commitment necessary to mutate the footpath in the LoadLibrary aim.
nag_cos_integral.restype=c_double
The ctypes module provides us with a set down of C compatible data-types such as c_int, c_double, c_char and so on, and we be enduring to put into practice these when we interact with C functions. distinctively The entity nag_cos_integral represents the NAG C aim we passion to hearing and nigh inaction ctypes assumes that the profit classification of all C functions is of classification c_int unless we hillock it in another location.
x = c_double(0.2)
ifail=c_int(0)
Here, we are habitat up our input arguments.

We skilled in from the documentation for the advantage of s13acc that its profit classification is twofold and so here we are using the restype method aim to set down the profit classification of nag_cos_integral to c_double. distinctively x is straightforward sufficiency but the attentive reader commitment awareness that there is something aberrant best-selling on with the ifail parameter. distinctively abasing distinctively The NAG documentation tells us that the ifail parameter of s13acc should be a piece of advice to a NagError shape but structures are a bar that I don’t hunger to conduct oneself expound on with here so I be enduring cheated and second-hand the truthfully that the integer 0 is defined as NAGERR_DEFAULT via an enumeration in the C library header pandemonium. distinctively Full details can be bring about in part 2.6 of the Essential Introduction to the NAG C Library. distinctively In condense, this means that I don’t be enduring to put into practice a NagError shape if I don’t hunger to.
We’ll look at how to put into practice the NagError shape suitably via Python in a later article for the advantage of those who necessary it.
y= nag_cos_integral( x, ifail )
Here we pass our input parameters to the nag_cos_integral aim and cache the cut off in y.

After all, we earlier second-hand restype to set down the profit classification of nag_cos_integral to c_double so that’s what I expected to motion ahead but it turns commission that y is a level crumbling python twofold. distinctively When I was working all of this commission for the advantage of the earliest just the same from time to time, I expected y to be of classification c_double. distinctively This is indubitably explained in the ctypes documentation and I notation the fitting part below
‘Fundamental facts types, when returned as unidentified aim hearing results, or, for the advantage of archetype, nigh retrieving shape American football gridiron members or array items, are transparently converted to local Python types. In other words, if a unidentified aim has a restype of c_char_p, you commitment continually come into a Python stipulations, not a c_char_p example.’
print “x= %s, cos_integral= %s” % (x.value,y)
Finally, we rightfully spread about the achievement. distinctively The unpredictable y is a python twofold as explained earlier so it needs no singular treatment.

Since x is a c_double we necessary to put into practice the value bottle to jammed that 0.2 gets printed less than c_double(0.2).
That’s it for the advantage of this article in the series. distinctively Next just the same from time to time I’ll give in commission an archetype using this aim along with matplotlib to forth some more engrossing achievement up disguise malicious onto callback functions.
April 1st, 2009
Categories: NAG Library, distinctively programming, distinctively python, Author: Mike Croucher, Comments: distinctively,
No Comments
No comments in spite of.
As continually, questions and comments are welcomed.

One Response to “Walking Randomly » Making frank NAG functions accessible to Python”

  1. [...] stringfrom multiprocessing_mapreduce connotation SimpleMapReducedef file_to_words(filename): generally demeaning generally “””Read a make note of and restoration a run of (word, occurances) [...]