Indexing

2023-06-01 Thread Colins
Hey everyone, I could use some assistance regarding my website [www.learnaboutcat.com](https://forum.nim-lang.org/www.learnaboutcat.com). My goal is to enhance the indexing of my backlinks and boost my search engine rankings. Do you think it's advisable to employ software that compels Goog

Overloaded array operator allows changing the indexing sequence for objects, but not for tuples.

2021-11-02 Thread Araq
What's a `distinct tuple` if not an `object`? ;-)

Overloaded array operator allows changing the indexing sequence for objects, but not for tuples.

2021-11-02 Thread Dabod
If you insist to override `[]`, `[]=` for tuple, try this import unittest import typetraits type VectorTup* = distinct tuple x, y, z: int proc `[]`* (v: VectorTup, i: int): int = template base(v: typed): untyped = (distinctBase(v.type

Overloaded array operator allows changing the indexing sequence for objects, but not for tuples.

2021-11-02 Thread Araq
The compiler could disallow it but you're indeed not supposed to overload [] for tuples. For objects it's fine since objects don't have any [].

Overloaded array operator allows changing the indexing sequence for objects, but not for tuples.

2021-11-02 Thread FernandoTorres
Thanks, I'll bear it in mind.

Overloaded array operator allows changing the indexing sequence for objects, but not for tuples.

2021-11-02 Thread FernandoTorres
While experimenting with the array access operator [ ] overload for objects and tuples, I noticed a difference between both cases. The intention was to override the array indexing sequence. Instead of using the default [0], [1], [2], I tried to change it to [1], [2], [3]. The idea worked for

nimpy pandas slicing/indexing

2021-07-16 Thread mratsim
I have extracted Arraymancer slicing syntax so that it can be reused for Flambeau, a libtorch (PyTorch backend) bindings. It closely reproduces Numpy/PyTorch/Pandas syntax: * The `py.slice` would be generate

nimpy pandas slicing/indexing

2021-07-15 Thread sdmcallister
Works, thanks!

nimpy pandas slicing/indexing

2021-07-15 Thread yglukhov
Nimpy doesn't support this notation yet, but something like this should work: let py = pyBuiltinsModule() echo test.iloc[(py.slice(1, 2), py.slice(0, 2))] Run

nimpy pandas slicing/indexing

2021-07-14 Thread sdmcallister
Thanks for the suggestion! Unfortunately there is a type mismatch.

nimpy pandas slicing/indexing

2021-07-14 Thread ynfle
Try echo test.iloc[1..<3, 0..<3] Run

nimpy pandas slicing/indexing

2021-07-14 Thread sdmcallister
This works fine (and is awesome): import nimpy let pd = pyImport("pandas") let datasets = pyImport("sklearn.datasets") var data = datasets.load_iris(as_frame=true, return_X_y=true) echo data[0] var test = data[0] echo test.iloc[[0]] Run

array sample slower than indexing into rand(size-1)

2021-03-23 Thread peheje
Nice shirleyquirk! I guess I should just use arrays when performance really matters and I know the size compile time. Would you do it like this? import sequtils import random import times const size = 10_000_000 iterations = 100_000_000 type

array sample slower than indexing into rand(size-1)

2021-03-23 Thread cblake
Also, I am pretty sure that, besides being slow, `proc rand(r: var Rand; max: Natural)` is also buggy/biased. Git VC history says it used to be correct, but then someone hastily re-did some logic to make it range-inclusive. Briefly, if x <= randMax - (randMax mod Ui(max)): re

array sample slower than indexing into rand(size-1)

2021-03-22 Thread cblake
Your state cannot start as all zero which is the default without init. See usage of the `random` module.

array sample slower than indexing into rand(size-1)

2021-03-22 Thread HJarausch
I've just added under `when isMainModule` var randState:Rand Run Then your code goes into an endless loop (even for `for trial in 1..1`)

array sample slower than indexing into rand(size-1)

2021-03-22 Thread cblake
This may get someone started on a PR or at least get @shirleyquirk a-benchmarkin': import random # Lemire2018 https://r-libre.teluq.ca/1437/ proc mul(a, b: uint64; hi, lo: var uint64) = # Store hi & low parts of full product a*b; # Note VM & JS branches need doi

array sample slower than indexing into rand(size-1)

2021-03-22 Thread cblake
Also, for what it's worth, I think `proc rand*(r: var Rand; max Natural)` could be profitably upgraded/sped up with the techniques of [Lemire 2018](https://r-libre.teluq.ca/1437/). But you can also just use `random.next()` and do that on your own. { It would also be unsurprising if @mratsim had

array sample slower than indexing into rand(size-1)

2021-03-22 Thread cblake
Note that if you look at the implementation for `proc rand*(r: var Rand; max: Natural)`, it is possible to do this more quickly in a loop if `max` does not change in said loop. The `mod` is constant over the loop and `randMax mod Ui(max)` can be computed just once instead of every function call.

array sample slower than indexing into rand(size-1)

2021-03-22 Thread alexeypetrushin
Why not use `sum += xs[rand(xs_len - 1)]` instead of `sum += xs[rand(int.high) mod size]`?

array sample slower than indexing into rand(size-1)

2021-03-21 Thread shirleyquirk
it's that `size` is `const` for i in 0..

array sample slower than indexing into rand(size-1)

2021-03-21 Thread HJarausch
In `random.nim`, _sample_ is function which consists of result = a[r.rand(a.low..a.high)] Run So, I think it is the function call overhead which makes the difference, especially since there is no **inline** pragma.

array sample slower than indexing into rand(size-1)

2021-03-21 Thread doofenstein
opps right I have similar results, for me it's 0.7 and 0.07 I misread the number by one magnitude haha

array sample slower than indexing into rand(size-1)

2021-03-21 Thread peheje
I am getting even larger difference between sample and rand(size-1) with flto passed to C time taken sample: 1.021981 time taken rand: 0.098158 nim c -r -d=danger --passC:-flto --passC:-ffast-math hue.nim Nim Compiler Version 1.4.4 [MacOSX: amd64]

array sample slower than indexing into rand(size-1)

2021-03-21 Thread dawkot
Copying the proc into the same file makes the difference go away on my machine.

array sample slower than indexing into rand(size-1)

2021-03-21 Thread peheje
Hi, I am experiencing that the [sample](https://nim-lang.org/docs/random.html#sample%2CopenArray%5BT%5D) function is more than two times slower than manually indexing into rand(size-1): import sequtils import random import times proc main() = const

array sample slower than indexing into rand(size-1)

2021-03-21 Thread doofenstein
I can reproduce the slowness by approximately the same factor. Though when building with lto enabled (--passC:"-flto") sample is for some reason even a bit faster.