Thank you very much @mratsim! :-D This has cleared up a lot of my questions.
It's always fascination how smart compilers can be about reading code and
optimizing it. A huge amount of work has obviously been put into them.
One more question about sink inference: Is it infered once per proc or is
I've started to try to understand more what move semantics is and how and when
I can make my code benefit from it. I've watched Araq's talk on it and read a
few threads on the forum along with the Destructors page in the docs. But I
don't feel like I've really managed to nail down what's the
I think that it may complain about the first g[T] proc. It only works in the
case T = B but unless that's the case you never create the variable l. So
either you have to indent the echo statement to be within the when statement or
you add a else statement to the when statement to handle the
It's so quiet on the forum today, I might as well make some noice then ;)
Since last time [BarrOff](https://github.com/BarrOff) has made several
contributions to the ode solvers both by adding higher-order integrators like
Tsit54, Vern65. The adaptive ode solver does now also use both an
I can try to answer 5), that's really the only one I'm qualified to answer XD
I'm also learning Weave now and it's a really nice experience and your other
questions intrigues me as well.
The difference between addr and unsafeAddr is that addr only works on mutable
things like var output for
Ahh, yes that is more convenient then passing all the fields manually!
Thank you very much for the help :-D
Interesting! If I understand you correctly, I should make a SplineType type
with a handler field to hold the eval proc. And then newHermiteSpline() would
return a SplineType with handler set to the Hermite's eval proc. Have I
understood you correctly then?
> How would you go about accessing
Thank you! :-) So it is a bug then. I'll try to boil it down to a more minimal
example before I file an issue on Github.
Wasn't generic methods depreciated a while back? :/
s.eval(float) is T
Run
To test this out replace [this
line](https://github.com/HugoGranstrom/numericalnim/blob/613062201ebd560e42a4cab2337b656a8f9b694e/src/numericalnim/interpolate.nim#L5)
with the above concept and then run the test file for interpolate.
> I would very m
Took to long for me to realize XD
That sound like a good idea :-) Thank you!
What kind of floats should you use for scientific libraries? Right now I have a
mix of float and float64 but what is the preferred way to do it? One way I've
been thinking about is using generics with SomeFloat to accomodate all kinds of
floats. Or is float64 the way to go nowadays?
I haven't tried this one out but it might be worth a look
[https://github.com/Pebaz/nimporter](https://github.com/Pebaz/nimporter)
I'm glad it worked out in the end :-D Have a nice day JPLRouge
If you don't get the error on the a+10 about it having to be discarded, I'm
suspecting you have changed your template for + to include a += somewhere,
which it shouldn't. Try doing a fresh clone of mratsim's repo and try it there
as well
I'm sorry but that's not valid Nim code. The definition of a should have a var
or let in front of it. And you can't just write a+10 on a line by itself, it
throws an error that it has to be discarded.
Do you have an example using the + operator (not +=) that changes the variable?
* \- / and * shouldn't change the variable. Or is it a behavior you want?
They should return the value. But if you do a = a + b you do change the
variable, but not because of the + operator but because you reassign it to the
return-value.
It's += -= *= and /= that are the odd ones here. They are the only ones that
changes the variable, all other procs returns the value instead, leaving the
variable unchanged
Ah I see, it's the result notation for returning that's making it a bit hard to
see here. Instead of doing return 10 we can do result = 10.
In * you see that we have a result, but in *= we do not. So * returns a value
while *= does not. :-)
Does my explanation answer your question? :-)
If I understand you correctly, you are wondering why it doesn't print .2 in the
first case? It's because a*10 doesn't change a, it returns a new DecimalType.
If you instead run echo a*10 you should get what you expect. If you want to
save it you have to assign it to a variable like this: var b
I'm not really sure what point you are trying to make about * and *= :/ They
are two separate procs neither of them uses the other. So I don't get how
changing *= fixes the error you get with *.
Here is one example that works as expected:
let a = newDecimal("1.49")
let b = 1.25
let c1 = a * b
let c2 = b * a
echo c1
echo c2
# 1.8625
# 1.8625
Run
It feel like it shouldn't matter in which order you write a and newDecimal(b)
because both expressions have the type DecimalType so the same proc is called
regardless. The only possibility I see (and I may very well have overlooked
something) is if mpd_qmul isn't commutative (order matters) but
I'm assuming you're refering to
![[https://github.com/status-im/nim-decimal]](https://github.com/status-im/nim-decimal\]).
I was the one who wrote the high-level wrapper for it so it's probably one of
my mistakes. Could you give an example where it doesn't work as you expected?
Not really a solution to the problem but this could be an opportunity for you
to learn the underlying workings of the statistical algorithms you use by
creating a toy stats project in Nim. And you get an opportunity to learn Nim as
well ;-) All assuming you have the time, interest and energy of
It was interesting ;) I should use iterators more instead of hard to read loops
with indices
I'm trying to get a slice of a seq but I only want every second element. I
could write a loop that does this but I'm wondering if there is a more elegant
way of doing it? In Python you can do:
a = [0, 1, 2, 3, 4, 5]
print(a[::2])
# Outputs: [0, 2, 4]
Run
I
Monte Carlo involves generating a lot of random numbers, right? And doing the
same thing to all of them? Do you incorporate any parallelization to speed it
up?
Are there any maintained tries at a Jupiter kernel one could try to help out?
The path through Python seems like a good one. When Python programmers realize
there is a better Cython, things will get fun here ;)
Couldn't agree more! A plotting library that can both do a simple
plot(x, y)
Run
And more advanced customization.
Wow! You are a lot of cool people here :-)
I'm mainly focused on engineering applications (ode, integration,
interpolation) and my package NumericalNim is a collection of the algorithms I
have learnt thus far.
What do you think is the most lacking in Nim at the moment for Scientific
related
I get your point ;) The forum works fine, but it's the IRC part that I'm a bit
bothered by. I usual check the Gitter once every 2 hours and during that time
there has been too much going on (usually) and I don't have the time to go
through it all. If there has been anything about data science,
There seem to be quite a few data/computational science people lurking around
here in the Nim community (@mratsim among others). Is there any interest in us
creating a place where such stuff can be discussed? I think it would be helpful
to have a dedicated place to discuss such matters,
I think moigagoo meant choosenim
[https://github.com/dom96/choosenim](https://github.com/dom96/choosenim)
Aaa makes total sense :) this is what's called a closure?
Thank you very much @LeuGim :-D
I have a Spline (interpolation) type:
type
Spline*[T] = ref object
x: seq[float]
coeffs: seq[tuple[float, float, T, T]]
Run
And I can evaluate it at a point t using:
eval*[T](spline: Spline[T], t: float): T
Run
What
Released version 0.2 which included Gauss-Legendre Quadrature, with 20
different methods with increasing accuracy ranging from 1 to 20 function
evaluations per sub-interval.
I don't usually customize much, all I really want is an easy to use editor
where I can type code and get auto completion. So for me it's sufficient.
VS Code with Nim plugin
Are comp a ModelInstance or is it a pointer to a ModelInstance? In C the "->"
operator takes a pointer to a struct and the field we want and then
dereferences it. The equivalent Nim code in that case is:
template r(vr: untyped): untyped = comp[].r[vr]
Run
And if you
> But the ModelInstance definition doesn't seem to suggest it is an array.
fmi2Real *r;
Run
In C, arrays are a pointer to the first element in the array, thus r is both a
pointer to a fmi2Real and an array of fmi2Reals.
Yep, have noticed the same (and filed the issue @shashlick mentioned). The way
I solved it for the meantime was by copying the type definitions into a
separate header file and importing it.
Tank you :-) Awesome work from you too ;-) will test it out!
> So you haven't yet read our page with the most learning resources? ;)
> [https://nim-lang.org/learn.html](https://nim-lang.org/learn.html)
Apparently not 臘♀️ can't remember when I looked there last time tbh. Are some
really neat resources there!
> These are in our wiki and everybody can
I think it would be good to have a more fleshed out "Nim for {programming
language} programmers". There are some of them on the github page but I haven't
found any links to them except from Google. I would happily contribute to
something line that
Awesome to hear :-) I'm also new to this so we are in the same boat ;-) What we
don't know, we can learn. And in our case, will learn
Let me know if you gets it yo work, or more importantly if it doesn't. You
learn more from a failure than a success I have just been pounding at some
I have started to wrap the Sundials project and my first goal was to wrap the
N_Vector shared library, which I to some extent has succeeded with but in a
rather hacky, and not so seamless, way. The structure of the files can be found
in my github repo:
[https://github.com/HugoGranstrom
I have uploaded it to Github:
[https://github.com/HugoGranstrom/nimsundials](https://github.com/HugoGranstrom/nimsundials)
Let me know if you get it to run :-)
I have managed to get a simple CVode program running. Hurray! :-)
proc f(t: realtype, y: N_Vector, ydot: N_Vector, user_data: pointer): cint
{.cdecl.} =
NV_Ith_S(ydot, 0) = NV_Ith_S(y, 0)
NV_Ith_S(ydot, 1) = NV_Ith_S(y, 1)
NV_Ith_S(ydot, 2) = NV_Ith_S(y, 2)
This is so cool, we should definitely try to work together rather than making
two separate versions ;-)
I have managed to wrap N_Vector_Serial and made it functional (don't know if it
is memory safe and things like that though). And I have managed to compile some
of the CVode functions thus
When I run CMake on the project and "make" & "make install" it, I get a
include-folder with a few subfolders with .h files and a lib-folder with lots
of dynamic libraries. Can nimterop handle this?
Thank you, will take a closer look at it ;-)
I'm not very experienced in the C world but I think I want the entire library,
so perhaps all headers in the include/ folder?
What are my options for wrapping a C-library (in my case Sundials) that uses
CMake to build?
There seems to be alot floating around, c2nim, nimgen, nimterop etc.
What would be easiest to use for my use-case? :-)
Thanks for the interesting links :-)
Julia has an astonishing amount of solvers, I would like to implement all of
them in Nim but I got to be realistic XD and have a life as well. It has been
one of my major inspirations when doing this.
Thank you :-D
Not really, I'm quite new to low-level programming in general so I thought I'd
make it in pure Nim so I could learn its features. This was also a project
where I learned how all the algorithms worked which has been an enriching
experience. To be honest, this isn't even near being
[https://github.com/HugoGranstrom/numericalnim](https://github.com/HugoGranstrom/numericalnim)
NumericalNim is a library for doing basic ODE and integration related things.
At the moment the ODE has two solvers: RK4 and DOPRI54, which are two quite
standard methods. The integration can
That's embarrassing XD I must have mistyped something. Thank you :-D
Thanks both of you :-) Is there any advantages of using one over the other (for
bigger project perhaps)?
I have divided my package into submodules and would like to export their API
via the main module so all submodules can be imported by just importing
it./src|
---|---
\--- testPackage.nim --- /testPackage --- submodule1.nim ---
submodule2.nim --- submodule3.nim I have put a
I see, thank you both for your answers and your time
臘 hehe...
Is there any cases where a when-statement can be used in a proc?
Assume we have a proc like this (it doesn't do anything sensible):
proc coolProc[T](x: openArray[T]): T =
when x.len == 1:
echo "Nothing to see! Move on!"
else:
echo "How have you gotten " & x.len & "gold coins already?!"
Run
Let's say I
Thank you very much for your kind answers everyone :-D
Thank you for the answer! :-D
A follow up on question 1: let's say all I care for is that the input parameter
can be iterated over. Is there a way of specifying it or am I too pythonic in
my way of thinking?
1. If I have a proc that accepts a "list" of number, but doesn't care if it's
a seq or array, is there a simple way of declaring it's type in the proc's
input parameters or do I need to use multiple dispatch and create one proc for
seq and one proc for array?
2. In Python if I want to
That's some heavy stuff! And equally as interesting. Is it something you use
often?
Randomness heavy stuff ;-) How is Nim's support for random number generation?
What would be a typical problem solved with these?
Symbolic computation is a really cool tech. It's amazing that a computer can
"understand" math to a certain extent :-D. Would be interesting to see how much
easier it will be to implement in Nim compared to C++.
Your project seems really cool ;-) I really like the simplistic graphics!
The integrators are my favorite part of the simulations :-D It's really
interesting to compare the different integrators around. In this simulation
that is written in Javascript I have implemented most of the integrators
I'm a computational science enthusiast and I've mostly dabbled with Python
because of its ease of writing code. But it was lacking the speed I wanted for
my simulations (mostly gravitational n-body) so I started looking into other
options and I found Nim. And how grateful I am for that! It
72 matches
Mail list logo