1

I am trying to use ILNumerics from F#. It seems quite difficult.

I would like to replicate this example

What I have so far is the following code:

open ILNumerics 
open type ILMath
let inline (!) (x :RetArray<'T>) = Array<'T>.op_Implicit(x)
let inline (!!) (x:Array<'T> ) = InArray<'T>.op_Implicit(x) 
let inline  (!!!) (x:float[]) :InArray<float>  = Array.map float32 x 
                                                  |> InArray.op_Implicit

let inline (!~) (x:float[]) : Array<float> = Array.map float32 x 
                                             |> Array.op_Implicit

let vec1 = (!~) [|1.0 .. 0.1 .. 2.0 |]

let X1 =   (linspace<float>((!!!)[|-3.0|],(!!!) [|3.0|],(!!!)[|20.0|]))
            |> Seq.toArray  
            |> (!~)
            |> (!!)
            
let X2 = X1 

let X3 :OutArray<float>= null
let T = meshgrid(X1,X2, X3)

Do I really need all these conversions to make it work? Also, how do I use an interpolant? I have scattered data and have to map from R3 -> R2 and from R4 -> R3.

I was considering Kriging interpolation, but it seems quite tough to use the library from F#. Any suggestion? Otherwise will be better off to solve the problem in C# and call it from F#, when needed?

  • 1
    I looked into the previously and came to the conclusion that the authors of ILNumerics never anticipated that anyone would use it from F#. The conversions are very frustrating, but I don't think there's any way around them. – Brian Berns May 07 '21 at 04:45
  • 1
    I don’t know ILNumerics but you could at least get rid of the `float32`s by using float32 literals: `[| 3.14f; 1.41f; …|]` – CaringDev May 07 '21 at 05:47
  • @brianberns I agree. I love F#, but am still learning and wondered whether there was a substantial easier way. At the moment I think it is not practically usable, unless one goes and redesigns the whole external API or at least using some computation expression. I think I will have to call C# produced DLLs from F#. – pacta_sunt_servanda May 07 '21 at 13:14
  • @CaringDev Thanks, for catching that. Sure, yet it does still seem too cumbersome to implement. ILNumerics has been created also for giving the user a syntax a la Matlab: easy to use, with logical indexing and the like. I need so many lines just to create a grid: it is pointless. – pacta_sunt_servanda May 07 '21 at 13:15

0 Answers0