Skip to content

Should we use AVOID_UNNECESSARY_COPY consistently, or remove it instead? #1714

@leftaroundabout

Description

@leftaroundabout

That variable is intended for copy arguments to methods that generate some data-carrying object. With it the caller signals that they do not wish any copy to be made (rather existing memory from the inputs should be reused), but that it is acceptable if it needs to happen anyway because e.g. some dtype conversion is required. This is usually the best strategy. By contrast, True means a copy is always created regardless if it is needed (which tends to take unnecessary time and memory) and False that no copy is allowed (which errors if it is actually necessary).

In the modern Python ecosystem, AVOID_UNNECESSARY_COPY is just an alias for None, which NumPy interprets this way since version 2.0. Having this definition in ODL was mainly to support also NumPy 1.x, but we do not do that anymore regardless.

I still think copy=None is a rather obscure way of expressing the intent, but ODL has now already hardcoded that in several places regardless.

We should either

  1. Use copy=AVOID_UNNECESSARY_COPY everywhere this is the default. It is quite verbose but at any rate clear
  2. Get rid of AVOID_UNNECESSARY_COPY and everywhere write copy=None instead, which I do not find very clear but mirrors NumPy.

The current half-hearted use makes no sense.

Opinions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions