The core types and functions of the SciNim ecosystem
scinim / nimjl Goto Github PK
View Code? Open in Web Editor NEWA bridge between Nim-lang and Julia !
A bridge between Nim-lang and Julia !
Hi @Clonkk, as I said, I think this is a great project ✨. But I believe nimpy
has a better user experience currently, though:
import nimpy
let np = pyImport("numpy")
# An attempt to translate the README example to nimpy
var myval = 4.0
var res = np.sqrt(myval)
echo res
❯ nim c -r -d:danger --opt:speed --verbosity=0 asdf.nim
..............................2.0
No
a. init
or exit
b. no default imports (faster/more straightforward/more explicit interface?)
c. no typecasting
So I have two questions and a suggestion:
import nimjl
Julia.init()
var myval = 4.0 # no `'f64`
var res = Julia.sqrt(myval) # no `to(float)`
echo res
Julia.exit()
So, do we need type conversions? Can't Julia types (primitives at least) be mapped automatically to Nim types/primitives? Isn't it done already? (I haven't looked at the code yet.)
sqrt
comes from the Julia Base
module (from the docs about embedding and here). What's behind the design decision of not making it explicit in Nim? For instance, nimpy
requires importing a builtin module:import nimpy
let py = pyBuiltinsModule()
(As a second thought, I'm not sure how to import a Julia module yet, so that this comment might be just too naive/simply dumb.)
init
and exit
, okay. But should this be mapped to Nim? init
can be called as soon as nimjl
is imported, so problem solved. The tricky part is to call exit
, so I tried a couple of ways of deferring this to the end of the program. Here's what I've found:defer
does not work (I didn't know that):
...
defer:
Julia.exit()
# =>
# Error: defer statement not supported at top level
Using std/exitprocs
work 🎉:
import nimjl
import std/exitprocs
Julia.init()
addExitProc proc =
echo "Cleaning up nimjl!"
Julia.exit()
# Actual working code:
var myval = 4.0
var res = Julia.sqrt(myval)
echo res
echo "That's all folks!"
$ nim c -r -d:danger --opt:speed --verbosity=0 exitprocstest.nim
................................................................................................................................................................................................................................................
Nimjl> Using Julia install: /opt/julias/julia-1.6.0
..2.0
That's all folks!
Cleaning up nimjl!
(Even though I like the solution above, another possibility would be to have a top-level, global object that runs Julia.exit
in its destructor, but I haven't tested that, and I'm not sure if it has any extra advantage over the above.)
It's very useful to debug
Greetings,
first of all, thanks for this library. It sparked my interest, as I'm following Julia since many years.
I was wondering, whether it's feasible to have general support for loading Julia scripts during Nim runtime.
For example, when I init
the Julia VM, then exit
it, I cannot init
it again, in another proc
.
It's also not possible right now to just "run" a script, that has top level statements, which are not enclosed by functions. Or, it is possible, kind of, however it just seems to be a side-effect of how the VM loading works.
It'd be great, if it were possible to initialise the VM once during the app's lifetime, as intended, then being able to load scripts on demand and run them. Being able to run Pkg
after init
in native Nim would also be good to have.
The use case is distributing a complex program, which gives users the option to write scripts. The scripts are written in Julia and the complex program, written in Nim, calls the procedures from the Julia scripts, to modify functionality of the complex program.
Use Arraymancer's desugar [1..5|2] syntax converted to Julia indexing slice / views
Only importing the package already throws an error:
import nimjl
$ nim c -r -d:danger --opt:speed --verbosity=0 example.nim
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: nimjl [Processing]
Hint: arrays [Processing]
Hint: types [Processing]
Hint: config [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: macros [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
Hint: pathnorm [Processing]
Hint: osseps [Processing]
Hint: posix [Processing]
Hint: times [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: jlcores [Processing]
Hint: strformat [Processing]
/home/schneider/.nimble/pkgs/nimjl-0.5.4/nimjl/types.nim(17, 3) Error: 'let' symbol requires an initialization
The offending line is
$ nim -v
Nim Compiler Version 1.2.6 [Linux: amd64]
Compiled at 2020-09-07
Copyright (c) 2006-2020 by Andreas Rumpf
active boot switches: -d:release
$ julia -v
julia version 1.6.0
Would be pretty cool to support Windows even if WSL is a superior solution IMHO.
The goal would be to able to execute Nim code from Julia.
Probably need :
The use of https://github.com/treeform/genny to export C-API callable from Julia would probably be the best solution
Currently it will usually fails silently on config.nim
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.