I'm using Nim for data processing, and missing some statistical and math functions.
Wondering if there are some well known and widely used C libraries doing these things? That would be possible to integrate and use from Nim?
I think integration with C would be much better option than re-creating it in Nim. As most effort for such libraries are documentation, tutorials, books and examples. It's too huge effort to re create all this in nim from the scratch.
If you are ok with GPL licensing you have a Nim wrapper for GSL
Nice, I didn't knew that.
A thought about Math libraries in Nim. I tried GSL library mentioned above, it works well.
The one thing is, as it turned out, the C-wrappers needs to be written manually, as usage and concepts in Nim and C are quite different. So you can't just auto-import or auto-generate these things.
As example, the GSL library provides Normal Distribution Function:
proc gsl_cdf_gaussian_P*(x: cdouble; sigma: cdouble): cdouble {.cdecl, importc, dynlib: libgsl.}
But in order to be usable in Nim it should be rewritten into Nim like code. The good side is that it's easy to do, you just wrap it in a little bit of high level interfacing code.
type Normal* = object
mu: float
sigma: float
proc cdf*(self: Normal): proc (x: float): float =
return proc (x: float): float =
gsl_cdf_gaussian_P(x - self.mu, self.sigma)
test "Normal.cdf":
assert Normal(mu: 0.0, sigma: 1.0).cdf()(0) =~ 0.5
I think a possible option to keep Nim Math ecosystem consistent is to mimic Julia math libraries, function names, usage patterns etc. As Nim and Julia are conceptually are very similar languages.