Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add pad/shift/translate #180

Closed
Closed
@eriknw

Description

@eriknw

There is already .resize, which can add or trim an object on the right or the bottom. It might be handy to have a more general operation that can both resize objects and shift values (or only shift).

For example, such a function could be used to translate a small local chunk in dask-grblas to its proper place in the global matrix. This might be handy to implement metagraph-dev/dask-grblas#19.

We should also consider how this this would look as a C API and Python API. Some questions:

  • Should this mutate an existing object like .resize or create a new object?
  • What should the Python API be?
    • Should we try to mimic numpy.pad?
      • pad(2) to add a length 2 border around everything
      • pad((1, 2)) to pad with width 1 on the left and width 2 on the right
      • Should we allow negative such as pad(-2) to undo pad(2) or pad((1, -1)) to shift everything to the right by 1 but keep the shape the same?
  • Possible names: pad, shift, translate, etc.
  • If we "shift" all values by N, is there any value in having different boundary conditions such as drop or wraparound?

I think there are several possible variations here, and I don't yet have a strong opinion. So, let's discuss!

This function may come in handy:
https://github.com/numpy/numpy/blob/a8f9711493adee93fa3d61e7ef1bee11d7055a85/numpy/lib/arraypad.py#L454

Also, thanks to @ParticularMiner for first asking about this in a side channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussing a topic with no specific actions yetfeatureSomething is missing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions