Re: Question about move semantics for objects and seqs

2020-07-13 Thread hugogranstrom
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

Question about move semantics for objects and seqs

2020-07-12 Thread hugogranstrom
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

Re: Generic function resolution

2020-07-06 Thread hugogranstrom
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

Re: NumericalNim, a basic ODE and integration library written in Nim

2020-07-05 Thread hugogranstrom
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

Re: Parallel coding in Nim (as compared to OpenMP/MPI)

2020-06-18 Thread hugogranstrom
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

Re: Having problems with concepts that won't finish compiling

2020-04-07 Thread hugogranstrom
Ahh, yes that is more convenient then passing all the fields manually! Thank you very much for the help :-D

Re: Having problems with concepts that won't finish compiling

2020-04-07 Thread hugogranstrom
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

Re: Having problems with concepts that won't finish compiling

2020-04-06 Thread hugogranstrom
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? :/

Having problems with concepts that won't finish compiling

2020-04-05 Thread hugogranstrom
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

Re: Announcement: The Nim compiler is rewritten in Python with some modules optimized in C

2020-04-01 Thread hugogranstrom
Took to long for me to realize XD

Re: Proposal to start a Nim-Scientific Community

2019-12-14 Thread hugogranstrom
That sound like a good idea :-) Thank you!

Re: Proposal to start a Nim-Scientific Community

2019-12-13 Thread hugogranstrom
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?

Re: Nim extension libs for python

2019-12-05 Thread hugogranstrom
I haven't tried this one out but it might be worth a look [https://github.com/Pebaz/nimporter](https://github.com/Pebaz/nimporter)

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
I'm glad it worked out in the end :-D Have a nice day JPLRouge

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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.

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
Do you have an example using the + operator (not +=) that changes the variable?

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
* \- / 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.

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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. :-)

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
Does my explanation answer your question? :-)

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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 *.

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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

Re: Nim-Decimal test

2019-11-12 Thread hugogranstrom
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?

Re: Nim for Statistics

2019-11-09 Thread hugogranstrom
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

Re: Nim equivilent of Python's slicing with step list[start: end: step]

2019-11-03 Thread hugogranstrom
It was interesting ;) I should use iterators more instead of hard to read loops with indices

Nim equivilent of Python's slicing with step list[start: end: step]

2019-11-03 Thread hugogranstrom
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

Re: Proposal to start a Nim-Scientific Community

2019-10-01 Thread hugogranstrom
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?

Re: Proposal to start a Nim-Scientific Community

2019-10-01 Thread hugogranstrom
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 ;)

Re: Proposal to start a Nim-Scientific Community

2019-10-01 Thread hugogranstrom
Couldn't agree more! A plotting library that can both do a simple plot(x, y) Run And more advanced customization.

Re: Proposal to start a Nim-Scientific Community

2019-10-01 Thread hugogranstrom
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

Re: Proposal to start a Nim-Scientific Community

2019-09-29 Thread hugogranstrom
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,

Proposal to start a Nim-Scientific Community

2019-09-29 Thread hugogranstrom
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,

Re: nim cannot reference libraries installed with nimble.

2019-09-20 Thread hugogranstrom
I think moigagoo meant choosenim [https://github.com/dom96/choosenim](https://github.com/dom96/choosenim)

Re: How to create a proc from an object?

2019-09-17 Thread hugogranstrom
Aaa makes total sense :) this is what's called a closure? Thank you very much @LeuGim :-D

How to create a proc from an object?

2019-09-16 Thread hugogranstrom
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

Re: NumericalNim, a basic ODE and integration library written in Nim

2019-08-22 Thread hugogranstrom
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.

Re: What text editor are you using for Nim?

2019-08-02 Thread hugogranstrom
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.

Re: What text editor are you using for Nim?

2019-08-02 Thread hugogranstrom
VS Code with Nim plugin

Re: FFI: help converting macro into template

2019-07-25 Thread hugogranstrom
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

Re: FFI: help converting macro into template

2019-07-24 Thread hugogranstrom
> 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.

Re: Wrap C library that needs CMake

2019-07-23 Thread hugogranstrom
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.

Re: Wrap C library that needs CMake

2019-07-20 Thread hugogranstrom
Tank you :-) Awesome work from you too ;-) will test it out!

Re: Nim Equivalent of Python Range [with Step]

2019-07-16 Thread hugogranstrom
> 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

Re: Nim Equivalent of Python Range [with Step]

2019-07-16 Thread hugogranstrom
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

Re: Wrap C library that needs CMake

2019-07-16 Thread hugogranstrom
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

Problem wrapping a shared library with Nimterop (Sundials-N_Vector)

2019-07-16 Thread hugogranstrom
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

Re: Wrap C library that needs CMake

2019-07-15 Thread 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 :-)

Re: Wrap C library that needs CMake

2019-07-15 Thread hugogranstrom
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)

Re: Wrap C library that needs CMake

2019-07-15 Thread hugogranstrom
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

Re: Wrap C library that needs CMake

2019-07-11 Thread hugogranstrom
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?

Re: Wrap C library that needs CMake

2019-07-11 Thread hugogranstrom
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?

Wrap C library that needs CMake

2019-07-11 Thread hugogranstrom
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? :-)

Re: NumericalNim, a basic ODE and integration library written in Nim

2019-06-30 Thread hugogranstrom
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.

Re: NumericalNim, a basic ODE and integration library written in Nim

2019-06-30 Thread hugogranstrom
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

NumericalNim, a basic ODE and integration library written in Nim

2019-06-29 Thread hugogranstrom
[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

Re: Giving my library access to types in the file that import it

2019-06-28 Thread hugogranstrom
That's embarrassing XD I must have mistyped something. Thank you :-D

Re: exporting API from submodules

2019-06-25 Thread hugogranstrom
Thanks both of you :-) Is there any advantages of using one over the other (for bigger project perhaps)?

exporting API from submodules

2019-06-25 Thread hugogranstrom
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

Re: Question about using when-statement in (generic) proc

2019-06-19 Thread hugogranstrom
I see, thank you both for your answers and your time 

Re: Question about using when-statement in (generic) proc

2019-06-19 Thread hugogranstrom
臘 hehe... Is there any cases where a when-statement can be used in a proc?

Question about using when-statement in (generic) proc

2019-06-19 Thread hugogranstrom
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

Re: A few questions about procs

2019-06-17 Thread hugogranstrom
Thank you very much for your kind answers everyone :-D

Re: A few questions about procs

2019-06-16 Thread hugogranstrom
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?

A few questions about procs

2019-06-16 Thread hugogranstrom
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

Re: What kinds of Computational Science problems do you usually solve

2019-06-03 Thread hugogranstrom
That's some heavy stuff! And equally as interesting. Is it something you use often?

Re: What kinds of Computational Science problems do you usually solve

2019-06-03 Thread hugogranstrom
Randomness heavy stuff ;-) How is Nim's support for random number generation? What would be a typical problem solved with these?

Re: What kinds of Computational Science problems do you usually solve

2019-06-03 Thread hugogranstrom
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++.

Re: What kinds of Computational Science problems do you usually solve

2019-06-03 Thread hugogranstrom
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

What kinds of Computational Science problems do you usually solve

2019-06-03 Thread hugogranstrom
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