toCtypes¶
Utility routine used to convert a NumPy ndarray to a ctypes array.
Synopsis¶
toCtypes
(ndarr
, ctypes_array
)
Required Arguments¶
- tuple
ndarr[[]]
(Input) - NumPy ndarray of any dimension.
- ctypes
ctypes_array[]
(Input) - ctypes array already created of the correct size to hold the elements in the ndarray.
Description¶
This routine is used to copy a NumPy ndarray. This is only needed inside user defined functions. Arrays passed to user defined functions are always passed in a ctypes array. However if you wish to pass this array to another routine which expects an ndarray as input, including other PyIMSL functions, then you can use the toNdarray utility to convert from ctypes to ndarray, and then if needed, toCtypes to copy the results back from the ndarray to the ctypes array before exiting the user function.
Note that this utility is imported from pyimsl.util.imslConvert
.
Example¶
For an example of using this routine see the example for the PyIMSL math
routine linSolDefCg
, the relevant part of which is shown here in the
user supplied function:
from pyimsl.util.imslConvert import toCtypes
from pyimsl.util.imslConvert import toNdarray
...
def amultp (p,z):
ptmp = toNdarray(p, (n))
ztmp=matMulRect ("A*x",
aMatrix = a,
xVector = ptmp)
toCtypes(ztmp, z)