We have some interop code that involves matrices. I was trying to call the native DLL and for the most part it works very reliably.
I am relying on the default marshalling by .net, avoiding unmanaged pointers and rather using .net arrays for the most part, and maybe a byref
here and there. The .net article says, that multidimensional arrays are implicitly marshalled as column-major one-dimensional arrays, which would be fine.
The only thing that does not seem to work, is trying to marshal a multi-dimensional array, as the F# compiler complains that float[,]
is not allowed in an extern
declaration. Is there any way around this limitation?
I am aware of the PinnedArray
and PinnedArray2
types from the F# PowerPack, but I was looking for a solution which relies on managed pointers and - more importantly - I'd like to avoid having to include F# PowerPack as a dependency just for the PinnedArray
classes.
To do this, assign another 3-by-3 matrix to the index value 2 in the third dimension. The syntax A(:,:,2) uses a colon in the first and second dimensions to include all rows and all columns from the right-hand side of the assignment. The cat function can be a useful tool for building multidimensional arrays.
numpy is the core library for scientific computing in Python. It provides a high-performance multidimensional array object and tools for working with these arrays.
By this discription about Blittable and Non-Blittable Types in the link below you could try the System.Double in place of float, because they do not require conversion when they are passed between managed and unmanaged code wich means no more special handling by the interop marshaler with a plus in performance: https://msdn.microsoft.com/en-us/library/75dwhxf7%28v=vs.110%29.aspx
I did a search and found this related topic wich may help you:
Threat like a single array: http://stackoverflow.com/a/18607817/4597705
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With