crystal-community / crystal-libraries-needed

A list of libraries that are needed or wanted for the Crystal-Language
141 stars 4 forks source link

A library like Scipy #15

Open johnjansen opened 7 years ago

johnjansen commented 7 years ago

https://www.scipy.org

marceloboeira commented 7 years ago

@johnjansen 👍

konovod commented 7 years ago

It would be great imho, as Crystal's fast speed and agile syntax could make it pretty successful in scientific programming. I see two main problems\questions though:

(all of that is a diletant point of view, I could be totally wrong and don't have much experience neither in scipy nor in scientific programming).

RX14 commented 7 years ago

@konovod Actually requiring a large shard shouldn't slow down the crystal compiler much if at all. The speed of the compiler is proportional to the amount of code in use: methods that aren't called and code that isn't used barely have a cost overhead because they are never typed.

I haven't actually benchmarked this at all so take it with a grain of salt but i'm 90% sure that this is how it works from looking at compiler internals.

konovod commented 7 years ago

Good to hear. I haven't benchmarked too, but type inference was my most concern. The compiler still have to parse all code - i've started creating wrapper for LAPACK and the direct conversion of c-header is 2300 lines, and that's just one library. But parsing is perhaps fast enough.

RX14 commented 7 years ago

@konovod if you use --stats you'll find even parsing all_spec.cr takes a fraction of a second.

konovod commented 7 years ago

Ok, now i have another question. License. Is GPL acceptable for most potential users of "Crystal SciPy"?

If GPL is acceptable, wrapper around GSL can provide most of the features Scipy has - optimization, ode, integrators, statistics, sparse linalg, splines etc etc. I've no idea about performance, but it can be improved later. There is also GLPK for linear programming and possibly more libraries.

If GPL is too strict and license should be close to SciPy - things will be more complex (but still solvable. after all, scipy itself has permissive license). Personally, i don't have anything against GPL (i'm closer to gpl fan actually), but if this will severely reduce popularity of the library, there is a little point to use it. Maybe this issue is not a best place to discuss it, but i don't know where to go with it.

konovod commented 7 years ago

So, status report

I'm open to suggestions what should be the next thing. Maybe Numpy analogue - multidimensional arrays with convenient DSL's. Or more complete GSL bindings (my favorite parts are root-finding\minimization and ode solvers, so i'll perhaps start with them). Or maybe sparce matrices - there is a SuiteSparse, i think i can try to create wrappers, but as i've no experience with sparce matrices i'm not sure what things are more important in it and what can be skipped.

konovod commented 7 years ago

Huh, just found there is also https://github.com/mverzilli/crystalla by @mverzilli. Looks like without centralized packages list people will keep reinventing bicycles again and again. If i've found it before I would prefer making PR's to it, as it doesn't looks like my one-man-hobby, but now my library has more features and i'm opinionated towards it.

On the GSL - my impression is that library has poor quality. Yes, it covers a lot of areas, but I've found a bug at the day I touched it, google shows that it is already reported but never fixed. Besides that, of three minimization algorithms one is slow, one is "default" and one fails to converge on simplest example. So i don't think wrapping it worth efforts. I've started instead wrapper of NLopt for nonlinear optimization.

mverzilli commented 7 years ago

Hey @konovod! As you might have noticed, it's been a while since I last worked on crystalla, and now that I'm a bit more involved in Crystal itself it is very unlikely that I'll dedicate time to it without a strong reason. Feel free to "steal" anything if you feel there's something useful. Otherwise, I'm super happy that someone is tackling this: I agree that Crystal is a super interesting fit for scientific applications. This post shows some of the potential: https://manas.tech/blog/2015/10/30/linear-algebra-in-crystal-from-lapack.html. Given most of the heavyweight was actually done by LAPACK/BLAS, those 10x improvements stem directly from the OH introduced by Crystal vs. Python, with comparable code "complexity".

christopherzimmerman commented 5 years ago

Just adding bottle here. I've only gotten to a few of scipy's features, but they are in the roadmap, and I do implement an N-Dimensional Tensor which is really useful.