mxnet.util

general utility functions

Functions

TemporaryDirectory(*args, **kwargs)

A context wrapper of tempfile.TemporaryDirectory() that ignores cleanup errors on Windows.

default_array(source_array[, device, dtype])

Creates an array from any object exposing the default(nd or np) array interface.

dtype_from_number(number)

Get the data type from the given int or float number

get_cuda_compute_capability(device)

Returns the cuda compute capability of the input device.

get_max_supported_compute_capability()

Get the maximum compute capability (SM arch) supported by the nvrtc compiler

get_rtc_compile_opts(device)

Get the compile ops suitable for the context, given the toolkit/driver config

getenv(name)

Get the setting of an environment variable from the C Runtime.

is_np_array()

Checks whether the NumPy-array semantics is currently turned on.

is_np_default_dtype()

Checks whether the NumPy default dtype semantics is currently turned on.

is_np_shape()

Checks whether the NumPy shape semantics is currently turned on.

np_array([active])

Returns an activated/deactivated NumPy-array scope to be used in ‘with’ statement and captures code that needs the NumPy-array semantics.

np_default_dtype([active])

Returns an activated/deactivated NumPy-default_dtype scope to be used in ‘with’ statement and captures code that needs the NumPy default dtype semantics.

np_shape([active])

Returns an activated/deactivated NumPy shape scope to be used in ‘with’ statement and captures code that needs the NumPy shape semantics, i.e.

np_ufunc_legal_option(key, value)

Checking if ufunc arguments are legal inputs

numpy_fallback(func)

decorator for falling back to offical numpy for a specific function

reset_np()

Deactivate NumPy shape and array and deafult dtype semantics at the same time.

set_flush_denorms(value)

Change floating-point calculations on CPU when dealing with denormalized values.

set_module(module)

Decorator for overriding __module__ on a function or class.

set_np([shape, array, dtype])

Setting NumPy shape and array semantics at the same time.

set_np_default_dtype([is_np_default_dtype])

Turns on/off NumPy default dtype semantics, because mxnet.numpy.ndarray use 32 bit data storage as default (e.g.

set_np_shape(active)

Turns on/off NumPy shape semantics, in which () represents the shape of scalar tensors, and tuples with 0 elements, for example, (0,), (1, 0, 2), represent the shapes of zero-size tensors.

setenv(name, value)

Set an environment variable in the C Runtime.

use_np(func)

A convenience decorator for wrapping user provided functions and classes in the scope of both NumPy-shape and NumPy-array semantics, which means that (1) empty tuples () and tuples with zeros, such as (0, 1), (1, 0, 2), will be treated as scalar tensors’ shapes and zero-size tensors’ shapes in shape inference functions of operators, instead of as unknown in legacy mode; (2) ndarrays of type mxnet.numpy.ndarray should be created instead of mx.nd.NDArray.

use_np_array(func)

A decorator wrapping Gluon Block`s and all its methods, properties, and static functions with the semantics of NumPy-array, which means that where ndarrays are created, `mxnet.numpy.ndarray`s should be created, instead of legacy ndarrays of type `mx.nd.NDArray.

use_np_default_dtype(func)

A decorator wrapping a function or class with activated NumPy-default_dtype semantics.

use_np_shape(func)

A decorator wrapping a function or class with activated NumPy-shape semantics.

wrap_ctx_to_device_func(func)

A convenience decorator for converting ctx to device keyward backward compatibility

wrap_data_api_linalg_func(func)

A convenience decorator for wrapping data apis standardized linalg functions to provide context keyward backward compatibility :param func: :type func: a numpy-compatible array linalg function to be wrapped for context keyward change.

wrap_data_api_statical_func(func)

A convenience decorator for wrapping data apis standardized statical functions to provide context keyward backward compatibility :param func: :type func: a numpy-compatible array statical function to be wrapped for context keyward change.

wrap_np_binary_func(func)

A convenience decorator for wrapping numpy-compatible binary ufuncs to provide uniform error handling.

wrap_np_unary_func(func)

A convenience decorator for wrapping numpy-compatible unary ufuncs to provide uniform error handling.

wrap_sort_functions(func)

A convenience decorator for wrapping sort functions

TemporaryDirectory(*args, **kwargs)[source]

A context wrapper of tempfile.TemporaryDirectory() that ignores cleanup errors on Windows.

default_array(source_array, device=None, dtype=None)[source]

Creates an array from any object exposing the default(nd or np) array interface.

Parameters
  • source_array (array_like) – An object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.

  • device (Device, optional) – Device context (default is the current default context).

  • dtype (str or numpy.dtype, optional) – The data type of the output array. The default dtype is source_array.dtype if source_array is an NDArray, float32 otherwise.

Returns

An NDArray`(nd or np) with the same contents as the `source_array.

Return type

NDArray

dtype_from_number(number)[source]

Get the data type from the given int or float number

get_cuda_compute_capability(device)[source]

Returns the cuda compute capability of the input device.

Parameters

device (Device) – GPU context whose corresponding cuda compute capability is to be retrieved.

Returns

cuda_compute_capability – CUDA compute capability. For example, it returns 70 for CUDA arch equal to sm_70.

Return type

int

References

https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549#file-cuda_check-py

get_max_supported_compute_capability()[source]

Get the maximum compute capability (SM arch) supported by the nvrtc compiler

get_rtc_compile_opts(device)[source]

Get the compile ops suitable for the context, given the toolkit/driver config

getenv(name)[source]

Get the setting of an environment variable from the C Runtime.

Parameters

name (string type) – The environment variable name

Returns

value – The value of the environment variable, or None if not set

Return type

string

is_np_array()[source]

Checks whether the NumPy-array semantics is currently turned on. This is currently used in Gluon for checking whether an array of type mxnet.numpy.ndarray or mx.nd.NDArray should be created. For example, at the time when a parameter is created in a Block, an mxnet.numpy.ndarray is created if this returns true; else an mx.nd.NDArray is created.

Normally, users are not recommended to use this API directly unless you known exactly what is going on under the hood.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy within this semantics.

Returns

Return type

A bool value indicating whether the NumPy-array semantics is currently on.

is_np_default_dtype()[source]

Checks whether the NumPy default dtype semantics is currently turned on. In NumPy default dtype semantics, default dtype is float64.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy even within this scope.

Returns

Return type

A bool value indicating whether the NumPy default dtype semantics is currently on.

See also

set_np_default_dtype()

Set default dtype equals to offical numpy

set_np()

npx.set_np(dtype=True) has equal performance to npx.set_np_default_dtype(True)

Example

>>> import mxnet as mx
>>> from mxnet import npx
>>> prev_state = npx.set_np_default_dtype(True)
>>> print(prev_state)
False
>>> print(npx.is_np_default_dtype())
True
is_np_shape()[source]

Checks whether the NumPy shape semantics is currently turned on. In NumPy shape semantics, () represents the shape of scalar tensors, and tuples with 0 elements, for example, (0,), (1, 0, 2), represent the shapes of zero-size tensors. This is turned off by default for keeping backward compatibility.

In the NumPy shape semantics, -1 indicates an unknown size. For example, (-1, 2, 2) means that the size of the first dimension is unknown. Its size may be inferred during shape inference.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy within this semantics.

Returns

Return type

A bool value indicating whether the NumPy shape semantics is currently on.

Example

>>> import mxnet as mx
>>> prev_state = mx.set_np_shape(True)
>>> print(prev_state)
False
>>> print(mx.is_np_shape())
True
np_array(active=True)[source]

Returns an activated/deactivated NumPy-array scope to be used in ‘with’ statement and captures code that needs the NumPy-array semantics.

Currently, this is used in Gluon to enforce array creation in Block`s as type `mxnet.numpy.ndarray, instead of mx.nd.NDArray.

It is recommended to use the decorator use_np_array to decorate the classes that need this semantics, instead of using this function in a with statement unless you know exactly what has been scoped by this semantics.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy even within this scope.

Parameters

active (bool) – Indicates whether to activate NumPy-array semantics.

Returns

A scope object for wrapping the code w/ or w/o NumPy-shape semantics.

Return type

_NumpyShapeScope

np_default_dtype(active=True)[source]

Returns an activated/deactivated NumPy-default_dtype scope to be used in ‘with’ statement and captures code that needs the NumPy default dtype semantics. i.e. default dtype is float64.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy even within this scope.

Parameters

active (bool) – Indicates whether to activate NumPy default dtype semantics.

Returns

  • _NumpyDefaultDtypeScope – A scope object for wrapping the code w/ or w/o NumPy-default_dtype semantics.

  • Example::

    with mx.np_default_dtype(active=True):

    # Default Dtype is ‘float64’, consistent with offical NumPy behavior. arr = mx.np.array([1, 2, 3]) assert arr.dtype == ‘float64’

    with mx.np_default_dtype(active=False):

    # Default Dtype is ‘float32’ in the legacy default dtype definition. arr = mx.np.array([1, 2, 3]) assert arr.dtype == ‘float32’

np_shape(active=True)[source]

Returns an activated/deactivated NumPy shape scope to be used in ‘with’ statement and captures code that needs the NumPy shape semantics, i.e. support of scalar and zero-size tensors.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy even within this scope.

Parameters

active (bool) – Indicates whether to activate NumPy-shape semantics.

Returns

  • _NumpyShapeScope – A scope object for wrapping the code w/ or w/o NumPy-shape semantics.

  • Example::

    with mx.np_shape(active=True):

    # A scalar tensor’s shape is (), whose ndim is 0. scalar = mx.nd.ones(shape=()) assert scalar.shape == ()

    # If NumPy shape semantics is enabled, 0 in a shape means that # dimension contains zero elements. data = mx.sym.var(“data”, shape=(0, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape() assert arg_shapes[0] == (0, 2, 3) assert out_shapes[0] == (0, 2, 3)

    # -1 means unknown shape dimension size in the new NumPy shape definition data = mx.sym.var(“data”, shape=(-1, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == (-1, 2, 3) assert out_shapes[0] == (-1, 2, 3)

    # When a shape is completely unknown when NumPy shape semantics is on, it is # represented as None in Python. data = mx.sym.var(“data”) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] is None assert out_shapes[0] is None

    with mx.np_shape(active=False):

    # 0 means unknown shape dimension size in the legacy shape definition. data = mx.sym.var(“data”, shape=(0, 2, 3)) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == (0, 2, 3) assert out_shapes[0] == (0, 2, 3)

    # When a shape is completely unknown in the legacy mode (default), its ndim is # equal to 0 and it is represented as () in Python. data = mx.sym.var(“data”) ret = mx.sym.sin(data) arg_shapes, out_shapes, _ = ret.infer_shape_partial() assert arg_shapes[0] == () assert out_shapes[0] == ()

Checking if ufunc arguments are legal inputs

Parameters
  • key (string) – the key of the ufunc argument.

  • value (string) – the value of the ufunc argument.

Returns

legal – Whether or not the argument is a legal one. True when the key is one of the ufunc arguments and value is an allowed value. False when the key is not one of the ufunc arugments or the value is not an allowed value even when the key is a legal one.

Return type

boolean

numpy_fallback(func)[source]

decorator for falling back to offical numpy for a specific function

reset_np()[source]

Deactivate NumPy shape and array and deafult dtype semantics at the same time.

set_flush_denorms(value)[source]
Change floating-point calculations on CPU when dealing with denormalized values.

This is only applicable to architectures which supports flush-to-zero. Denormalized values are positive and negative values that are very close to 0 (exponent is the smallest possible value). Flushing denormalized values to 0 can speedup calculations if such values occurs, but if fulfilling whole IEEE 754 standard is required this option should be disabled. Flushing denormalized values is enabled in MXNet by default.

Parameters

value (bool) – State of flush-to-zero and denormals-are-zero in MXCSR register

Returns

prev_state – Previous state of flush-to-zero in MXCSR register

Return type

bool

set_module(module)[source]

Decorator for overriding __module__ on a function or class.

Example usage:

@set_module('mxnet.numpy')
def example():
    pass

assert example.__module__ == 'numpy'
set_np(shape=True, array=True, dtype=False)[source]

Setting NumPy shape and array semantics at the same time. It is required to keep NumPy shape semantics active while activating NumPy array semantics. Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed. It is highly recommended to set these two flags to True at the same time to fully enable NumPy-like behaviors. Please refer to the Examples section for a better understanding.

Parameters
  • shape (bool) – A boolean value indicating whether the NumPy-shape semantics should be turned on or off. When this flag is set to True, zero-size and zero-dim shapes are all valid shapes in shape inference process, instead of treated as unknown shapes in legacy mode.

  • array (bool) – A boolean value indicating whether the NumPy-array semantics should be turned on or off. When this flag is set to True, it enables Gluon code flow to use or generate mxnet.numpy.ndarray`s instead of `mxnet.ndarray.NDArray. For example, a Block would create parameters of type mxnet.numpy.ndarray.

  • dtype (bool) – A boolean value indicating whether the NumPy-dtype semantics should be turned on or off. When this flag is set to True, default dtype is float64. When this flag is set to False, default dtype is float32.

Examples

>>> import mxnet as mx

Creating zero-dim ndarray in legacy mode would fail at shape inference.

>>> mx.nd.ones(shape=())
mxnet.base.MXNetError: Operator _ones inferring shapes failed.
>>> mx.nd.ones(shape=(2, 0, 3))
mxnet.base.MXNetError: Operator _ones inferring shapes failed.

In legacy mode, Gluon layers would create parameters and outputs of type mx.nd.NDArray.

>>> from mxnet.gluon import nn
>>> dense = nn.Dense(2)
>>> dense.initialize()
>>> dense(mx.nd.ones(shape=(3, 2)))
[[0.01983214 0.07832371]
 [0.01983214 0.07832371]
 [0.01983214 0.07832371]]
<NDArray 3x2 @cpu(0)>
>>> [p.data() for p in dense.collect_params().values()]
[
[[0.0068339  0.01299825]
 [0.0301265  0.04819721]]
<NDArray 2x2 @cpu(0)>,
[0. 0.]
<NDArray 2 @cpu(0)>]

When the shape flag is True, both shape inferences are successful.

>>> from mxnet import np, npx
>>> npx.set_np()  # this is required to activate NumPy-like behaviors
>>> np.ones(shape=())
array(1.)
>>> np.ones(shape=(2, 0, 3))
array([], shape=(2, 0, 3))

When the array flag is True, Gluon layers would create parameters and outputs of type mx.np.ndarray.

>>> dense = nn.Dense(2)
>>> dense.initialize()
>>> dense(np.ones(shape=(3, 2)))
array([[0.01983214, 0.07832371],
       [0.01983214, 0.07832371],
       [0.01983214, 0.07832371]])
>>> [p.data() for p in dense.collect_params().values()]
[array([[0.0068339 , 0.01299825],
       [0.0301265 , 0.04819721]]), array([0., 0.])]
>>> npx.set_np(dtype=True)
>>> np.ones(shape=()).dtype
dtype('float64')
set_np_default_dtype(is_np_default_dtype=True)[source]

Turns on/off NumPy default dtype semantics, because mxnet.numpy.ndarray use 32 bit data storage as default (e.g. float32 and int 32) while offical NumPy use 64 bit data storage as default (e.g. float64 and int64). This is turned off by default for keeping backward compatibility.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy within this semantics.

Parameters

active (bool) – Indicates whether to turn on/off NumPy default dtype semantics.

Returns

Return type

A bool value indicating the previous state of NumPy default dtype semantics.

Example

>>> import mxnet as mx
>>> from mxnet import npx
>>> prev_state = npx.set_np_default_dtype(True)
>>> print(prev_state)
False
>>> print(npx.is_np_default_dtype())
True
set_np_shape(active)[source]

Turns on/off NumPy shape semantics, in which () represents the shape of scalar tensors, and tuples with 0 elements, for example, (0,), (1, 0, 2), represent the shapes of zero-size tensors. This is turned off by default for keeping backward compatibility.

Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules mx.nd and mx.sym are not guaranteed to behave like their counterparts in NumPy within this semantics.

Parameters

active (bool) – Indicates whether to turn on/off NumPy shape semantics.

Returns

Return type

A bool value indicating the previous state of NumPy shape semantics.

Example

>>> import mxnet as mx
>>> prev_state = mx.set_np_shape(True)
>>> print(prev_state)
False
>>> print(mx.is_np_shape())
True
setenv(name, value)[source]

Set an environment variable in the C Runtime.

Parameters
  • name (string type) – The environment variable name

  • value (string type) – The desired value to set the environment value to

use_np(func)[source]

A convenience decorator for wrapping user provided functions and classes in the scope of both NumPy-shape and NumPy-array semantics, which means that (1) empty tuples () and tuples with zeros, such as (0, 1), (1, 0, 2), will be treated as scalar tensors’ shapes and zero-size tensors’ shapes in shape inference functions of operators, instead of as unknown in legacy mode; (2) ndarrays of type mxnet.numpy.ndarray should be created instead of mx.nd.NDArray.

import mxnet as mx
from mxnet import gluon, nd, np
from mxnet.gluon import Parameter

class TestHybridBlock1(gluon.HybridBlock):
    def __init__(self):
        super(TestHybridBlock1, self).__init__()
        self.w = Parameter('w', shape=(2, 2))

    def forward(self, x):
        return nd.dot(x, self.w.data()) + nd.ones((1,))

x = mx.nd.ones((2, 2))
net1 = TestHybridBlock1()
net1.initialize()
out = net1.forward(x)
for _, v in net1.collect_params().items():
    assert type(v.data()) is mx.nd.NDArray
assert type(out) is mx.nd.NDArray

@mx.util.use_np
class TestHybridBlock2(gluon.HybridBlock):
    def __init__(self):
        super(TestHybridBlock2, self).__init__()
        self.w = Parameter('w', shape=(2, 2))

    def forward(self, x):
        return np.dot(x, self.w.data()) + np.ones(())

x = np.ones((2, 2))
net2 = TestHybridBlock2()
net2.initialize()
out = net2.forward(x)
for _, v in net2.collect_params().items():
    print(type(v.data()))
    assert type(v.data()) is np.ndarray
assert type(out) is np.ndarray
Parameters

func (a user-provided callable function or class to be scoped by the) – NumPy-shape and NumPy-array semantics.

Returns

A function or class wrapped in the Numpy-shape and NumPy-array scope.

Return type

Function or class

use_np_array(func)[source]

A decorator wrapping Gluon Block`s and all its methods, properties, and static functions with the semantics of NumPy-array, which means that where ndarrays are created, `mxnet.numpy.ndarray`s should be created, instead of legacy ndarrays of type `mx.nd.NDArray. For example, at the time when a parameter is created in a Block, an mxnet.numpy.ndarray is created if it’s decorated with this decorator.

import mxnet as mx
from mxnet import gluon, nd, np
from mxnet.gluon import Parameter

class TestHybridBlock1(gluon.HybridBlock):
    def __init__(self):
        super(TestHybridBlock1, self).__init__()
        self.w = Parameter('w', shape=(2, 2))

    def forward(self, x):
        return nd.dot(x, self.w.data())

x = mx.nd.ones((2, 2))
net1 = TestHybridBlock1()
net1.initialize()
out = net1.forward(x)
for _, v in net1.collect_params().items():
    assert type(v.data()) is mx.nd.NDArray
assert type(out) is mx.nd.NDArray

@mx.util.use_np_array
class TestHybridBlock2(gluon.HybridBlock):
    def __init__(self):
        super(TestHybridBlock2, self).__init__()
        self.w = Parameter('w', shape=(2, 2))

    def forward(self, x):
        return np.dot(x, self.w.data())

x = np.ones((2, 2))
net2 = TestHybridBlock2()
net2.initialize()
out = net2.forward(x)
for _, v in net2.collect_params().items():
    print(type(v.data()))
    assert type(v.data()) is np.ndarray
assert type(out) is np.ndarray
Parameters

func (a user-provided callable function or class to be scoped by the NumPy-array semantics.) –

Returns

A function or class wrapped in the NumPy-array scope.

Return type

Function or class

use_np_default_dtype(func)[source]

A decorator wrapping a function or class with activated NumPy-default_dtype semantics. When func is a function, this ensures that the execution of the function is scoped with NumPy default dtype semantics, with the support for float64 as default dtype. When`func` is a class, it ensures that all the methods, static functions, and properties of the class are executed with the NumPy-default_dtype semantics.

import mxnet as mx
@mx.use_np_default_dtype
def float64_one():
    return mx.nd.ones(()).dtype
print(float64_one())

@np.use_np_default_dtype
class Float64Tensor(object):
    def __init__(self, data=None):
        if data is None:
            data = Float64Tensor.random().data
        self._data = data

    def __repr__(self):
        print("Is __repr__ in np_default_dtype semantics? {}!".format(str(np.is_np_deafult_dtype())))
        return str(self._data.asnumpy())

    @staticmethod
    def random():
        data = mx.nd.random.uniform(shape=(2,2))
        return ScalarTensor(data)

    @property
    def value(self):
        print("Is value property in np_dafault_dtype semantics? {}!".format(str(np.is_np_default_dtype())))
        return self._data.asnumpy()

print("Is global scope of np_default_dtype activated? {}!".format(str(np.is_np_default_dtype())))
float64_tensor = Float64Tensor()
print(float64_tensor)
Parameters

func (a user-provided callable function or class to be scoped by the NumPy-default_dtype semantics.) –

Returns

A function or class wrapped in the NumPy-default_dtype scope.

Return type

Function or class

use_np_shape(func)[source]

A decorator wrapping a function or class with activated NumPy-shape semantics. When func is a function, this ensures that the execution of the function is scoped with NumPy shape semantics, such as the support for zero-dim and zero size tensors. When func is a class, it ensures that all the methods, static functions, and properties of the class are executed with the NumPy shape semantics.

import mxnet as mx
@mx.use_np_shape
def scalar_one():
    return mx.nd.ones(())
print(scalar_one())

@np.use_np_shape
class ScalarTensor(object):
    def __init__(self, val=None):
        if val is None:
            val = ScalarTensor.random().value
        self._scalar = mx.nd.ones(()) * val

    def __repr__(self):
        print("Is __repr__ in np_shape semantics? {}!".format(str(np.is_np_shape())))
        return str(self._scalar.asnumpy())

    @staticmethod
    def random():
        val = mx.nd.random.uniform().asnumpy().item()
        return ScalarTensor(val)

    @property
    def value(self):
        print("Is value property in np_shape semantics? {}!".format(str(np.is_np_shape())))
        return self._scalar.asnumpy().item()

print("Is global scope of np_shape activated? {}!".format(str(np.is_np_shape())))
scalar_tensor = ScalarTensor()
print(scalar_tensor)
Parameters

func (a user-provided callable function or class to be scoped by the NumPy-shape semantics.) –

Returns

A function or class wrapped in the NumPy-shape scope.

Return type

Function or class

wrap_ctx_to_device_func(func)[source]

A convenience decorator for converting ctx to device keyward backward compatibility

Parameters

func (a function to be wrapped for context keyward change.) –

Returns

A function wrapped with context keyward changes.

Return type

Function

wrap_data_api_linalg_func(func)[source]

A convenience decorator for wrapping data apis standardized linalg functions to provide context keyward backward compatibility :param func: :type func: a numpy-compatible array linalg function to be wrapped for context keyward change.

Returns

  • Function

  • A function wrapped with context keyward changes.

wrap_data_api_statical_func(func)[source]

A convenience decorator for wrapping data apis standardized statical functions to provide context keyward backward compatibility :param func: :type func: a numpy-compatible array statical function to be wrapped for context keyward change.

Returns

  • Function

  • A function wrapped with context keyward changes.

wrap_np_binary_func(func)[source]

A convenience decorator for wrapping numpy-compatible binary ufuncs to provide uniform error handling.

Parameters

func (a numpy-compatible binary function to be wrapped for better error handling.) –

Returns

A function wrapped with proper error handling.

Return type

Function

wrap_np_unary_func(func)[source]

A convenience decorator for wrapping numpy-compatible unary ufuncs to provide uniform error handling.

Parameters

func (a numpy-compatible unary function to be wrapped for better error handling.) –

Returns

A function wrapped with proper error handling.

Return type

Function

wrap_sort_functions(func)[source]

A convenience decorator for wrapping sort functions

Parameters

func (a numpy-compatible array creation function to be wrapped for parameter keyword change.) –

Returns

A function wrapped with changed keywords.

Return type

Function