Re: Idea: Nim Online Conference
> The conference time (or at least timezone to get an idea) is rather important > because depending on your timezone the conference could effectively be on > another date. The registration form currently says: _Proposed start at 11 a.m. UTC_. That should give you a rough idea about when can you expect the talks to happen. (The exact timeline and other details will be announced after the registration deadline)
hello world execute on openwrt
compile OS is Debian 10.4 x86_64 # nim --version Nim Compiler Version 1.2.0 [Linux: amd64] Compiled at 2020-04-03 Copyright (c) 2006-2020 by Andreas Rumpf git hash: 7e83adff84be5d0c401a213eccb61e321a3fb1ff active boot switches: -d:release # cat hello.nim echo "Hello World" # nim -d:release --opt=size --passL:-s --cpu:arm --os:linux --gcc.exe:arm-openwrt-linux-gcc --gcc.linkerexe:arm-openwrt-linux-gcc c hello.nim When I execute the hello program on Openwrt(arm_cortex-a9_vfpv3) # ./hello -ash: ./hello: not found| ---|--- # opkg print_architecture arch all 1 arch noarch 1 arch arm_cortex-a9_vfpv3 10
Re: Nim Compiler Documentation
Have you read [Internals of the Nim Compiler](https://nim-lang.org/docs/intern.html)?
Nim Compiler Documentation
This is just a simple question. I have started looking at the nim compiler source and trying to implement my own backend for nim. Is there not documentation for the nim compiler or is it reserved for developers? I might just not have found where it is though.
Re: Experimenting with a FreeRTOS OS Port
Also, it'd be cool to see how many standard Nim libraries on threads could be extended to the ESP32 as well. That's far down the list, but how would one integrate vTasks*** with Nim?
Experimenting with a FreeRTOS OS Port
Hey all! I'm experimenting with an OS port for FreeRTOS, similar to that for the Nintendo Switch. Currently I'm focusing on the esp-idf (esp32) which includes LwIP. Essentially so far it's posix.nim with all the non-FreeRTOS parts removed (probably 80% of it). Importantly, there's a couple of core IP addr structs that differ due to LwIP. My main goal is getting net module (esp select for sockets) working with async. It'd be fun to have a Nim async-http server "just work" on FreeRTOS/LwIP devices. Would anyone else be interested in helping with such a project? Given Amazon's acquisition and re-licensing of FreeRTOS, it has given it a bit of a market boost. It appears to be a (the?) market leader, but it lacks a number of POSIX standards. Still a surprising amount of the standard libs works despite that. Currently I'm not sure how/if the net libraries for interfaces can be handled. The branch can be found here: [https://github.com/elcritch/Nim/tree/freertos](https://github.com/elcritch/Nim/tree/freertos)
Re: Revisiting my oldest Nim project.
> 5\. Always put your code into a src dir. Even though nimble supports not > having src dir, it’s just better in every way. In my experience that's the best way to break your project because on install nimble removes the `src` directory and then all your paths are wrong. This is so broken that even in nimble you had workaround like this: [https://github.com/nim-lang/nimble/blob/3ba8bd94/nimble.nimble#L4-L9](https://github.com/nim-lang/nimble/blob/3ba8bd94/nimble.nimble#L4-L9) when fileExists(thisModuleFile.parentDir / "src/nimblepkg/common.nim"): # In the git repository the Nimble sources are in a ``src`` directory. import src/nimblepkg/common else: # When the package is installed, the ``src`` directory disappears. import nimblepkg/common Run
Re: How to instantiate `ptr object`
For machine learning in particular deep learning this is how I do it: 1\. I use inheritance, but only to be able to store the objects in the same container, **never for dispatch**. Example on neural network layer, called `Gate`, re-using the terminology from Andrej Karpathy's [Hacker's Guide to Neural Network](http://karpathy.github.io/neuralnets/) [https://github.com/mratsim/Arraymancer/blob/5b24877b/src/autograd/autograd_common.nim#L72-L85](https://github.com/mratsim/Arraymancer/blob/5b24877b/src/autograd/autograd_common.nim#L72-L85) type Gate*[TT] = ref object of RootObj # {.acyclic.} ## Base operator or layer. You can describe your custom operations or layers ## by inheriting from Gate and add a forward and optionally a backward method. ## Each operations should set the number of gradients produced during backpropagation. ## Additional fields specific to the operations like weights or inputs cache should be added too. PayloadKind* = enum pkVar, pkSeq Payload*[TT] = object case kind*: PayloadKind of pkVar: variable*: Variable[TT] of pkSeq: sequence*: seq[Variable[TT]] Backward*[TT] = proc(self: Gate[TT], payload: Payload[TT]): SmallDiffs[TT] {.nimcall.} Run 2\. For dispatching I associate a compile-time proc for each kind of `Gate` I have. The `Gate` carry the state I need to pass. The compile-time proc just unwrap it and pass it to the _[real](https://forum.nim-lang.org/postActivity.xml#real) which has the proper signature. For example for a MaxPool layer, the backward proc should have for signature. [https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn_primitives/nnp_maxpooling.nim#L70-L74](https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn_primitives/nnp_maxpooling.nim#L70-L74) So how to map it to `proc(self: Gate[TT], payload: Payload[TT]): SmallDiffs[TT] {.nimcall.}`? The MaxPoolGate and backward shim does the trick [https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn/layers/maxpool2D.nim#L20-L46](https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn/layers/maxpool2D.nim#L20-L46), `maxpool2D_backward_ag` stands for autograd version type MaxPool2DGate*[TT] {.final.} = ref object of Gate[TT] cached_input_shape: MetadataArray cached_max_indices: Tensor[int] kernel, padding, stride: Size2D proc maxpool2D_backward_ag[TT](self: MaxPool2DGate[TT], payload: Payload[TT]): SmallDiffs[TT] = let gradient = payload.variable.grad result = newDiffs[TT](1) result[0] = maxpool2d_backward( self.cached_input_shape, self.cached_max_indices, gradient ) Run So I get compile-time dispatch on arbitrary state with a fixed interface. And even though the wrapper proc does not much, 2 static function calls are always faster than a closure or a method. Other example, convolution, this may seem more complex as the backward operation has a lot of inputs: [https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn_primitives/nnp_convolution.nim#L65-L70](https://github.com/mratsim/Arraymancer/blob/5b24877b/src/nn_primitives/nnp_convolution.nim#L65-L70) proc conv2d_backward*[T](input, weight, bias: Tensor[T], padding: Size2D, stride: Size2D, grad_output: Tensor[T], grad_input, grad_weight, grad_bias: var Tensor[T], algorithm = Conv2DAlgorithm.Im2ColGEMM) Run But it's actually straightforward as well type Conv2DGate*[TT]{.final.} = ref object of Gate[TT] cached_input: Variable[TT] weight, bias: Variable[TT] padding, stride: Size2D # TODO: store the algorithm (NNPACK / im2col) proc conv2d_backward_ag[TT](self: Conv2DGate[TT], payload: Payload[TT]): SmallDiffs[TT] = let gradient = payload.variable.grad if self.bias.isNil: result = newDiffs[TT](2) else: result = newDiffs[TT](3) conv2d_backward( self.cached_input.value, self.weight.value, self.bias.value, self.padding, self.stride, gradient, result[0], result[1], result[2] ) Run
Re: Unicode support for Windows 10 console
# console.nim when defined(windows): import system/widestrs proc setMode(fd: int, mode: int): int {.importc: "_setmode", header: "io.h".} proc fgetws(str: WideCString, numChars: int, stream: File): bool {.importc, header: "stdio.h".} discard setMode(getFileHandle(stdin), 0x0002) # _O_U16TEXT proc consoleReadLine*(line: var string): bool = let buffer = newWideCString("", 256) result = fgetws(buffer, 256, stdin) let length = buffer.len if length > 0 and buffer[length - 1].int16 == 10: # discard '\n' buffer[length - 1] = Utf16Char(0) # discard extra '\n' in waiting: let buffer2 = newWideCString("", 2) discard fgetws(buffer2, 2, stdin) line = $buffer proc consoleReadLine*(): string = discard consoleReadLine(result) else: proc consoleReadLine*(line: var string): bool = result = stdin.readLine(line) proc consoleReadLine*(): string = result = stdin.readLine() Run ^ when using "nim c" ^ when using "nim c --gc:arc" hmm it outputs (bytes: 1026, data: input) instead of string itself when using --gc:arc
Re: Idea: Nim Online Conference
Personally, I never streamed a talk yet, so I'd be quite interested in the technological side and what preparations I'd have to do; ideally also some hints how to test this beforehand. I just learnt about OBS from the above post, sounds interesting, but will definitely want to have the tech confirmed at some point, so that I can have time to try and test and experiment with it - assuming my talk submission is accepted. TIA!
Re: A good word for idiomatic nim?
nimby? nimpish?
Re: Revisiting my oldest Nim project.
> 5\. Always put your code into a src dir. Even though nimble supports not > having src dir, it’s just better in every way. What's the difference between putting my source code files into a `src` folder instead of putting them into my root folder? I'm not so familiar with nimble, but isn't nimble forcing (at default) to put all my files into `src` folder. Also if I have other dependencies like `assets`. I don't want to putt a `assets` folder or something similar into a `src` folder. And i do not see any benefits except if the project becomes huge. And if the project becomes huge, then I setup a project structure by myself I would like.
Re: Nim godbolt does not work with command line arguments
It seems to be a problem with Godbolt itself as far as I can see - it prepends these arguments for compilation (so it outputs assembly and not the binary) -o:/tmp/compiler-explorer-compiler2020416-1360-d68wkg.sqfva/output.s --nolinking --nimcache:/tmp/compiler-explorer-compiler2020416-1360-d68wkg.sqfva/output.s.cache Run And about arguments themselves - if you want to have equivalent of the flags you use for D, you should use: -d:danger --gc:arc --passC:"-flto" --passL:"-flto" Run
Re: Conflict of nfatype.Regex and nre.Regex
Thank you both! Indeed, I simply wrote = pathsplit.tail.replace(re"^[\!\+\-]+\s", "") Run without importing any regexp library explicitly, and it works fine.