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
- Use
copy=AVOID_UNNECESSARY_COPY everywhere this is the default. It is quite verbose but at any rate clear
- 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?
That variable is intended for
copyarguments 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,Truemeans a copy is always created regardless if it is needed (which tends to take unnecessary time and memory) andFalsethat no copy is allowed (which errors if it is actually necessary).In the modern Python ecosystem,
AVOID_UNNECESSARY_COPYis just an alias forNone, 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=Noneis a rather obscure way of expressing the intent, but ODL has now already hardcoded that in several places regardless.We should either
copy=AVOID_UNNECESSARY_COPYeverywhere this is the default. It is quite verbose but at any rate clearAVOID_UNNECESSARY_COPYand everywhere writecopy=Noneinstead, which I do not find very clear but mirrors NumPy.The current half-hearted use makes no sense.
Opinions?