Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tile and repeat_values procedures #648

Merged
merged 3 commits into from
May 7, 2024

Commits on Apr 21, 2024

  1. Add a (set of) repeat_values procedures

    These procedures let you repeat the values of a Tensor multiple times. This functionality exists both in numpy (`repeat`) and in Matlab (`repelem`).
    A different name was chosen here to avoid confusion with nim's `repeat` function, which behaves differently (it repeats the whole input sequence, like numpy's `tile` or Matlab's `repmat` functions), and to make the name more self explanatory.
    
    There are two versions of this procedure (with multiple overloads):
    
    - One that repeats all values the same amount of times over a given axis.
    - One that repeats each value a different amount of times, but returns a rank-1 tensor.
    
    Note that the second one is implemented as 2 procs with different argument types (openArray[int] and Tensor[int]).
    
    I measured the performance using the timeit library. The results show that the performance is comparable to numpy's `repeat` function. In particular, a small example which takes numpy's `repeat` ~2-3 usec per iteration, takes ~4 usec in --d:release mode, and ~1-2 usec in --d:danger mode.
    AngelEzquerra committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    e34dc35 View commit details
    Browse the repository at this point in the history
  2. Add a tile procedure

    This procedure lets you construct a new tensor by repeating the input tensor a number of times on one or more axes. This is similar to numpy's `tile` and Matlab's `repmat` functions.
    
    I measured the performance using the `timeit` library. The results show that the performance is comparable to (but not as good as) numpy's `tile`. In particular, a small example which takes numpy's `tile` ~3-4 usec per iteration, takes ~8-9 usec in --d:release mode, and ~5-6 usec in --d:danger mode.
    
    I believe that the performance could be improved further by preallocating the result Tensor before the tiling operation. The current implementation is not as efficient as it could be because it is based on calling `concat` multiple times, which requires at least as many tensor allocations (of increasing size).
    AngelEzquerra committed Apr 21, 2024
    Configuration menu
    Copy the full SHA
    535db47 View commit details
    Browse the repository at this point in the history

Commits on May 7, 2024

  1. fix docstring typo

    Vindaar authored May 7, 2024
    Configuration menu
    Copy the full SHA
    6a77260 View commit details
    Browse the repository at this point in the history