Re: How to instantiate `ptr object`

2020-05-15 Thread dataPulverizer
@mratsim Thank you for your detailed and informative response, also I didn't know about the do statement in Nim that's something else new for me. My main takeaway is that I don't always have to use runtime resolution, especially because the kind of code I write is mostly statistics/machine

Re: How to instantiate `ptr object`

2020-05-14 Thread dataPulverizer
> No you don't, you can have AbstractKernel be a procNo you don't, you can have > AbstractKernel be a proc. > > > type AbstractKernel[F] = proc(loc: var F) {.nimcall.} > > > Run I don't understand and have a couple of questions. Firstly, what would be the syntax for

Re: How to instantiate `ptr object`

2020-05-13 Thread dataPulverizer
One of the things that intrigued me about Nim was it's object system, you could create value, reference and pointer types with/without inheritance. As I understand it, an important distinction between ptr and ref classes is that ref classes are managed by the garbage collector while ptr classes

Re: How to instantiate `ptr object`

2020-05-13 Thread dataPulverizer
Isn't the point of inheritance method dispatch? Why isn't that a separate issue from objects that are dissociated from the garbage collector?

Re: How to instantiate `ptr object`

2020-05-13 Thread dataPulverizer
I just wasn't sure whether when allocating for objects you have to account for any "gubbings", just cautious I guess: type MyTypeA = ptr object of RootObj x: int64 MyTypeB = ptr object of RootObj x: array[0..4, int64] var x0 =

How to instantiate `ptr object`

2020-05-12 Thread dataPulverizer
One of the interesting things I remember about Nim is that you can have ptr object rather than ref object, since ptr object is not garbage collected. How do you create and destroy an ptr object? For example how do you correctly instantiate and destroy the two types below? type

Re: Parallel nested outer for loop

2020-05-11 Thread dataPulverizer
I have noticed that multiple CPU's were not being used, each process is spawned and seems to wait till it's finished before the next one starts so that only on CPU is being used at once. Is there something I should check about my implementation to make sure that I'm not doing something

Re: Parallel nested outer for loop

2020-05-11 Thread dataPulverizer
Actually, I could just put the inner loop into its own function which should be fine.

Parallel nested outer for loop

2020-05-10 Thread dataPulverizer
I am trying to parallelize kernel matrix calculations using threadpool: proc calculateKernelMatrix*(K: AbstractKernel, data: Matrix[F]): Matrix[F] = let n = int64(ncol(data)); var mat = Matrix[F](data: newSeq[F](n*n), dim: @[n, n]); for j in 0..

Re: Reference to sequence

2020-05-10 Thread dataPulverizer
Thanks, I don't know why I didn't think of that. I thought there would be a builtin for transforming something to ref, but this is fine.

Re: Reference to sequence

2020-05-10 Thread dataPulverizer
Sorry quick extension to that question, if I have a variable that is a seq[T], how do I assign it to a new variable that is a ref seq[T] ... or otherwise how do I transform a variable that is a seq[T] to a ref seq[T] ?

Re: Reference to sequence

2020-05-10 Thread dataPulverizer
Many thanks, dereferencing ref s is done using x[] as in your answer.

Reference to sequence

2020-05-10 Thread dataPulverizer
How do you create a reference to a sequence? I can see how you create a pointer to a sequence: var x: seq[float64] = @[1.0, 2, 3, 4, 5]; var y = x.addr; Run But have no idea how to create ref seq[float64], or is it only possible to create a ptr seq[float] while

Re: Byte Order (Endians) Library

2020-05-08 Thread dataPulverizer
> I don't think your code is standard though, usually void are implicit in the > return type, also var are used for in-place mutation, not pointers. Thanks for letting me know, I haven't written a lot of Nim so I'm still learning. I didn't realise that using var means in-place mutation, I've

Byte Order (Endians) Library

2020-05-08 Thread dataPulverizer
://gist.github.com/dataPulverizer/744fadf8924ae96135fc600ac86c7060](https://gist.github.com/dataPulverizer/744fadf8924ae96135fc600ac86c7060)

Re: Cast float64 to sequence of bytes and cast sequence of bytes to float64

2020-05-08 Thread dataPulverizer
Thanks for the advice and the references.

Cast float64 to sequence of bytes and cast sequence of bytes to float64

2020-05-07 Thread dataPulverizer
How do I cast float64 to sequence of byte`s and cast sequence of `byte`s to `float64? float64 is just an example it could be any basic type. I already did it for an array, but don't know how to do it for a sequence. Thanks

Re: Named Argument Bug?

2019-12-24 Thread dataPulverizer
Ah, many apologies! I saw it in the manual and assumed that it worked in the same thing as Julia.

Re: Named Argument Bug?

2019-12-24 Thread dataPulverizer
I'll not make anymore assumptions and read more carefully.

Named Argument Bug?

2019-12-24 Thread dataPulverizer
Why is this not legal code? proc printName(;firstName: string = "Jimmy", lastName: string = "Hendrix") = echo "First Name:", firstName, ", Last Name: ", lastName Run

Re: Code substitution with templates

2017-09-29 Thread dataPulverizer
The above code was just an example. In general I would like to be able to paste code using templates or macros in a similar way that you can with D's string mixins which allow you to generate strings using functions and then paste them anywhere and generate code in compile time. In the above

Re: Code substitution with templates

2017-09-26 Thread dataPulverizer
> No, parser cannot understand `extraCode` in an object declaration, in the > template, which is there an invalid syntax. I would like to substitute `id: int` for extra code in the template by doing: typeGen(Employee): id: int I thought (incorrectly) that this is how

Re: Code substitution with templates

2017-09-25 Thread dataPulverizer
@Udiknedormin many thanks for the thorough explanation and for your correction of age from string - silly error on my part. @stisa thanks for the heads up on dirty templates I guess the way to generate types using templates is to insert code into a template type structure rather than inserting

Code substitution with templates

2017-09-25 Thread dataPulverizer
I'm trying to use templates to paste code: template someCode(): untyped = var fname: string = "Mark" age: int = "44" someCode() echo fname The above code does not recognise the var declarations and the code below doesn't run either

Re: Error: invalid indentation

2017-09-25 Thread dataPulverizer
@LeuGim - thanks for the clarification @mratsim I didn't know about SomeReal thanks for pointing that out. > By the way, I don't really understand your need but you can usually go very > far in Nim with just generics and overloading without to implement class-like > types. > > If you need

Re: Arraymancer - A n-dimensional array / tensor library

2017-09-24 Thread dataPulverizer
This looks like a very useful library for me. I shall certainly be checking it out. Nice one!

Re: Error: invalid indentation

2017-09-24 Thread dataPulverizer
Many thanks! Looks like I didn't read the manual properly, I ended up thinking that ref Parent was how inheritance works. Just for confirmation: type # This is equivalent to a struct Object1 = object # This is a reference type to the "struct" Object1 Object2

Error: invalid indentation

2017-09-24 Thread dataPulverizer
Brand new to Nim, trying out parametric type with hierarchy, got stung with an indentation error for the last two lines that I can't figure out why type floatingPoint = float | float64 | float32 Parent1 = ref object Parent2 = ref Parent1 Parent3 = ref Parent1