From 4abfd927c4f026933607929f1cfb4a2e552c75af Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 14 Mar 2022 22:22:14 -0300 Subject: [PATCH 1/9] add files containing the missing functions --- rbc/stdlib/array_api.py | 11 +++- rbc/stdlib/array_attributes.py | 5 ++ rbc/stdlib/array_methods.py | 5 ++ rbc/stdlib/data_type_functions.py | 72 +++++++++++++++++++++++ rbc/stdlib/linear_algebra_functions.py | 40 +++++++++++++ rbc/stdlib/manipulation_functions.py | 81 ++++++++++++++++++++++++++ rbc/stdlib/searching_functions.py | 40 +++++++++++++ rbc/stdlib/set_functions.py | 40 +++++++++++++ rbc/stdlib/sorting_functions.py | 24 ++++++++ rbc/stdlib/utility_functions.py | 24 ++++++++ 10 files changed, 340 insertions(+), 2 deletions(-) create mode 100644 rbc/stdlib/array_attributes.py create mode 100644 rbc/stdlib/array_methods.py create mode 100644 rbc/stdlib/data_type_functions.py create mode 100644 rbc/stdlib/linear_algebra_functions.py create mode 100644 rbc/stdlib/manipulation_functions.py create mode 100644 rbc/stdlib/searching_functions.py create mode 100644 rbc/stdlib/set_functions.py create mode 100644 rbc/stdlib/sorting_functions.py create mode 100644 rbc/stdlib/utility_functions.py diff --git a/rbc/stdlib/array_api.py b/rbc/stdlib/array_api.py index 498de8a0..5a887f5d 100644 --- a/rbc/stdlib/array_api.py +++ b/rbc/stdlib/array_api.py @@ -2,10 +2,17 @@ Array API for rbc. """ -from .datatypes import * # noqa: F401, F403 from .constants import * # noqa: F401, F403 from .creation_functions import * # noqa: F401, F403 +from .datatypes import * # noqa: F401, F403 +from .data_type_functions import * # noqa: F401, F403 from .elementwise_functions import * # noqa: F401, F403 +from .linear_algebra_functions import * # noqa: F401, F403 +from .manipulation_functions import * # noqa: F401, F403 +from .searching_functions import * # noqa: F401, F403 +from .set_functions import * # noqa: F401, F403 +from .sorting_functions import * # noqa: F401, F403 from .statistical_functions import * # noqa: F401, F403 +from .utility_functions import * # noqa: F401, F403 -__all__ = [s for s in dir() if not s.startswith('_')] +__all__ = [s for s in dir() if not s.startswith("_")] diff --git a/rbc/stdlib/array_attributes.py b/rbc/stdlib/array_attributes.py new file mode 100644 index 00000000..2c0e7f9a --- /dev/null +++ b/rbc/stdlib/array_attributes.py @@ -0,0 +1,5 @@ +""" +https://data-apis.org/array-api/latest/API_specification/array_object.html#attributes +""" + +__all__ = [] diff --git a/rbc/stdlib/array_methods.py b/rbc/stdlib/array_methods.py new file mode 100644 index 00000000..927a4a60 --- /dev/null +++ b/rbc/stdlib/array_methods.py @@ -0,0 +1,5 @@ +""" +https://data-apis.org/array-api/latest/API_specification/data_type_functions.html +""" + +__all__ = [] diff --git a/rbc/stdlib/data_type_functions.py b/rbc/stdlib/data_type_functions.py new file mode 100644 index 00000000..667bd4a9 --- /dev/null +++ b/rbc/stdlib/data_type_functions.py @@ -0,0 +1,72 @@ +""" +https://data-apis.org/array-api/latest/API_specification/data_type_functions.html +""" +from rbc.stdlib import Expose + +__all__ = [ + "astype", + "broadcast_arrays", + "broadcast_to", + "can_cast", + "finfo", + "iinfo", + "result_type", +] + +expose = Expose(globals(), "data_type_functions") + + +@expose.not_implemented("astype") +def _array_api_astype(x, dtype, /, *, copy=True): + """ + Copies an array to a specified data type irrespective of + """ + pass + + +@expose.not_implemented("broadcast_arrays") +def _array_api_broadcast_arrays(*arrays): + """ + Broadcasts one or more arrays against one another. + """ + pass + + +@expose.not_implemented("broadcast_to") +def _array_api_broadcast_to(x, /, shape): + """ + Broadcasts an array to a specified shape. + """ + pass + + +@expose.not_implemented("can_cast") +def _array_api_can_cast(from_, to, /): + """ + Determines if one data type can be cast to another data type according + """ + pass + + +@expose.not_implemented("finfo") +def _array_api_finfo(type, /): + """ + Machine limits for floating-point data types. + """ + pass + + +@expose.not_implemented("iinfo") +def _array_api_iinfo(type, /): + """ + Machine limits for integer data types. + """ + pass + + +@expose.not_implemented("result_type") +def _array_api_result_type(*arrays_and_dtypes): + """ + Returns the dtype that results from applying the type promotion rules (see + """ + pass diff --git a/rbc/stdlib/linear_algebra_functions.py b/rbc/stdlib/linear_algebra_functions.py new file mode 100644 index 00000000..88691c11 --- /dev/null +++ b/rbc/stdlib/linear_algebra_functions.py @@ -0,0 +1,40 @@ +""" +https://data-apis.org/array-api/latest/API_specification/linear_algebra_functions.html +""" +from rbc.stdlib import Expose + +__all__ = ["matmul", "matrix_transpose", "tensordot", "vecdot"] + +expose = Expose(globals(), "linear_algebra_functions") + + +@expose.not_implemented("matmul") +def _array_api_matmul(x1, x2, /): + """ + Computes the matrix product. + """ + pass + + +@expose.not_implemented("matrix_transpose") +def _array_api_matrix_transpose(x, /): + """ + Transposes a matrix (or a stack of matrices) + """ + pass + + +@expose.not_implemented("tensordot") +def _array_api_tensordot(x1, x2, /, *, axes=2): + """ + Returns a tensor contraction of + """ + pass + + +@expose.not_implemented("vecdot") +def _array_api_vecdot(x1, x2, /, *, axis=-1): + """ + Computes the (vector) dot product of two arrays. + """ + pass diff --git a/rbc/stdlib/manipulation_functions.py b/rbc/stdlib/manipulation_functions.py new file mode 100644 index 00000000..5944e64d --- /dev/null +++ b/rbc/stdlib/manipulation_functions.py @@ -0,0 +1,81 @@ +""" +https://data-apis.org/array-api/latest/API_specification/manipulation_functions.html +""" +from rbc.stdlib import Expose + +__all__ = [ + "concat", + "expand_dims", + "flip", + "permute_dims", + "reshape", + "roll", + "squeeze", + "stack", +] + +expose = Expose(globals(), "manipulation_functions") + + +@expose.not_implemented("concat") +def _array_api_concat(arrays, /, *, axis=0): + """ + Joins a sequence of arrays along an existing axis. + """ + pass + + +@expose.not_implemented("expand_dims") +def _array_api_expand_dims(x, /, *, axis=0): + """ + Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by + """ + pass + + +@expose.not_implemented("flip") +def _array_api_flip(x, /, *, axis=None): + """ + Reverses the order of elements in an array along the given axis. + """ + pass + + +@expose.not_implemented("permute_dims") +def _array_api_permute_dims(x, /, axes): + """ + Permutes the axes (dimensions) of an array + """ + pass + + +@expose.not_implemented("reshape") +def _array_api_reshape(x, /, shape, *, copy=None): + """ + Reshapes an array without changing its data. + """ + pass + + +@expose.not_implemented("roll") +def _array_api_roll(x, /, shift, *, axis=None): + """ + Rolls array elements along a specified axis. + """ + pass + + +@expose.not_implemented("squeeze") +def _array_api_squeeze(x, /, axis): + """ + Removes singleton dimensions (axes) from + """ + pass + + +@expose.not_implemented("stack") +def _array_api_stack(arrays, /, *, axis=0): + """ + Joins a sequence of arrays along a new axis. + """ + pass diff --git a/rbc/stdlib/searching_functions.py b/rbc/stdlib/searching_functions.py new file mode 100644 index 00000000..18aed2d4 --- /dev/null +++ b/rbc/stdlib/searching_functions.py @@ -0,0 +1,40 @@ +""" +https://data-apis.org/array-api/latest/API_specification/searching_functions.html +""" +from rbc.stdlib import Expose + +__all__ = ["argmax", "argmin", "nonzero", "where"] + +expose = Expose(globals(), "searching_functions") + + +@expose.not_implemented("argmax") +def _array_api_argmax(x, /, *, axis=None, keepdims=False): + """ + Returns the indices of the maximum values along a specified axis. + """ + pass + + +@expose.not_implemented("argmin") +def _array_api_argmin(x, /, *, axis=None, keepdims=False): + """ + Returns the indices of the minimum values along a specified axis. + """ + pass + + +@expose.not_implemented("nonzero") +def _array_api_nonzero(x, /): + """ + Returns the indices of the array elements which are non-zero. + """ + pass + + +@expose.not_implemented("where") +def _array_api_where(condition, x1, x2, /): + """ + Returns elements chosen from + """ + pass diff --git a/rbc/stdlib/set_functions.py b/rbc/stdlib/set_functions.py new file mode 100644 index 00000000..b0f90205 --- /dev/null +++ b/rbc/stdlib/set_functions.py @@ -0,0 +1,40 @@ +""" +https://data-apis.org/array-api/latest/API_specification/set_functions.html +""" +from rbc.stdlib import Expose + +__all__ = ["unique_all", "unique_counts", "unique_inverse", "unique_values"] + +expose = Expose(globals(), "set_functions") + + +@expose.not_implemented("unique_all") +def _array_api_unique_all(x, /): + """ + Returns the unique elements of an input array + """ + pass + + +@expose.not_implemented("unique_counts") +def _array_api_unique_counts(x, /): + """ + Returns the unique elements of an input array + """ + pass + + +@expose.not_implemented("unique_inverse") +def _array_api_unique_inverse(x, /): + """ + Returns the unique elements of an input array + """ + pass + + +@expose.not_implemented("unique_values") +def _array_api_unique_values(x, /): + """ + Returns the unique elements of an input array + """ + pass diff --git a/rbc/stdlib/sorting_functions.py b/rbc/stdlib/sorting_functions.py new file mode 100644 index 00000000..7f1708ae --- /dev/null +++ b/rbc/stdlib/sorting_functions.py @@ -0,0 +1,24 @@ +""" +https://data-apis.org/array-api/latest/API_specification/sorting_functions.html +""" +from rbc.stdlib import Expose + +__all__ = ["argsort", "sort"] + +expose = Expose(globals(), "sorting_functions") + + +@expose.not_implemented("argsort") +def _array_api_all(x, /, *, axis=-1, descending=False, stable=True): + """ + Returns the indices that sort an array x along a specified axis. + """ + pass + + +@expose.not_implemented("sort") +def _array_api_any(x, /, *, axis=-1, descending=False, stable=True): + """ + Returns the indices that sort an array x along a specified axis. + """ + pass diff --git a/rbc/stdlib/utility_functions.py b/rbc/stdlib/utility_functions.py new file mode 100644 index 00000000..30875d6c --- /dev/null +++ b/rbc/stdlib/utility_functions.py @@ -0,0 +1,24 @@ +""" +https://data-apis.org/array-api/latest/API_specification/utility_functions.html +""" +from rbc.stdlib import Expose + +__all__ = ["all", "any"] + +expose = Expose(globals(), "utility_functions") + + +@expose.not_implemented("all") +def _array_api_all(x, /, *, axis=None, keepdims=False): + """ + Tests whether all input array elements evaluate to True along a specified axis. + """ + pass + + +@expose.not_implemented("any") +def _array_api_any(x, /, *, axis=None, keepdims=False): + """ + Tests whether any input array element evaluates to True along a specified axis. + """ + pass From 23e9b5f83388100b3dc90db0efe923ef9f2ee09e Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 14 Mar 2022 22:25:30 -0300 Subject: [PATCH 2/9] flake8 --- rbc/stdlib/manipulation_functions.py | 3 ++- setup.cfg | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rbc/stdlib/manipulation_functions.py b/rbc/stdlib/manipulation_functions.py index 5944e64d..ce932cdd 100644 --- a/rbc/stdlib/manipulation_functions.py +++ b/rbc/stdlib/manipulation_functions.py @@ -28,7 +28,8 @@ def _array_api_concat(arrays, /, *, axis=0): @expose.not_implemented("expand_dims") def _array_api_expand_dims(x, /, *, axis=0): """ - Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by + Expands the shape of an array by inserting a new axis (dimension) + of size one at the position specified by """ pass diff --git a/setup.cfg b/setup.cfg index 9d3e0fd4..4f442525 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,13 @@ per-file-ignores = rbc/omnisci_backend/numpy_ufuncs.py: F822 # undefined name in __all__ rbc/omnisci_backend/numpy_funcs.py: F822 rbc/stdlib/creation_functions.py: F822 + rbc/stdlib/data_type_functions.py: F822 + rbc/stdlib/linear_algebra_functions.py: F822 + rbc/stdlib/manipulation_functions.py: F822 + rbc/stdlib/searching_functions.py: F822 + rbc/stdlib/set_functions.py: F822 + rbc/stdlib/sorting_functions.py: F822 + rbc/stdlib/utility_functions.py: F822 rbc/stdlib/elementwise_functions.py: F822 rbc/stdlib/statistical_functions.py: F822 exclude = From 233a5eb81dde6d25b0c8755e27fd0353f107b0d9 Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 14 Mar 2022 22:57:34 -0300 Subject: [PATCH 3/9] fix python 3.7 failures --- doc/api.rst | 23 ++++++++--------------- rbc/stdlib/__init__.py | 11 ++++++----- rbc/stdlib/array_attributes.py | 2 ++ rbc/stdlib/array_methods.py | 2 ++ rbc/stdlib/constants.py | 2 ++ rbc/stdlib/data_type_functions.py | 18 ++++++++++++------ rbc/stdlib/datatypes.py | 2 ++ rbc/stdlib/linear_algebra_functions.py | 10 ++++++---- rbc/stdlib/manipulation_functions.py | 18 ++++++++++-------- rbc/stdlib/searching_functions.py | 10 ++++++---- rbc/stdlib/set_functions.py | 10 ++++++---- rbc/stdlib/sorting_functions.py | 6 ++++-- rbc/stdlib/utility_functions.py | 6 ++++-- setup.cfg | 2 +- 14 files changed, 71 insertions(+), 51 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 311d6ca2..a23970b7 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -15,15 +15,6 @@ Top-level functions :toctree: generated/ ctools - external - errors - libfuncs - omniscidb - remotejit - structure_type - targetinfo - typesystem - utils Array API @@ -32,11 +23,18 @@ Array API .. autosummary:: :toctree: generated/ - stdlib.datatypes stdlib.constants stdlib.creation_functions + stdlib.datatypes + stdlib.data_type_functions stdlib.elementwise_functions + stdlib.linear_algebra_functions + stdlib.manipulation_functions + stdlib.searching_functions + stdlib.set_functions + stdlib.sorting_functions stdlib.statistical_functions + stdlib.utility_functions Externals @@ -45,11 +43,6 @@ Externals .. autosummary:: :toctree: generated/ - externals.cmath - externals.libdevice - externals.macros - externals.omniscidb - externals.stdio OmniSciDB Backend diff --git a/rbc/stdlib/__init__.py b/rbc/stdlib/__init__.py index 2be91e9f..c71bc2e6 100644 --- a/rbc/stdlib/__init__.py +++ b/rbc/stdlib/__init__.py @@ -75,16 +75,17 @@ def wrapper(overload_func): return wrapper - def not_implemented(self, func_name): + def not_implemented(self, func_name, api=API.ARRAY_API): s = f'def {func_name}(*args, **kwargs): pass' exec(s, self._globals) fn = self._globals.get(func_name) - def wraps(func): - func.__doc__ = "❌ Not implemented" - functools.update_wrapper(fn, func) - return func + def wraps(overload_func): + original_doc = self.format_docstring(overload_func, func_name, api) + overload_func.__doc__ = f"❌ Not implemented\n{original_doc}" + functools.update_wrapper(fn, overload_func) + return overload_func return wraps diff --git a/rbc/stdlib/array_attributes.py b/rbc/stdlib/array_attributes.py index 2c0e7f9a..9a22afe3 100644 --- a/rbc/stdlib/array_attributes.py +++ b/rbc/stdlib/array_attributes.py @@ -1,4 +1,6 @@ """ +Array API specification for array attributes. + https://data-apis.org/array-api/latest/API_specification/array_object.html#attributes """ diff --git a/rbc/stdlib/array_methods.py b/rbc/stdlib/array_methods.py index 927a4a60..0b61df00 100644 --- a/rbc/stdlib/array_methods.py +++ b/rbc/stdlib/array_methods.py @@ -1,4 +1,6 @@ """ +Array API specification for array methods. + https://data-apis.org/array-api/latest/API_specification/data_type_functions.html """ diff --git a/rbc/stdlib/constants.py b/rbc/stdlib/constants.py index 8473411d..3b99ff91 100644 --- a/rbc/stdlib/constants.py +++ b/rbc/stdlib/constants.py @@ -1,4 +1,6 @@ """ +Array API specification for creation functions. + https://data-apis.org/array-api/latest/API_specification/constants.html """ import numpy as np diff --git a/rbc/stdlib/data_type_functions.py b/rbc/stdlib/data_type_functions.py index 667bd4a9..4d9bed7f 100644 --- a/rbc/stdlib/data_type_functions.py +++ b/rbc/stdlib/data_type_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for data type functions. + https://data-apis.org/array-api/latest/API_specification/data_type_functions.html """ from rbc.stdlib import Expose @@ -17,9 +19,10 @@ @expose.not_implemented("astype") -def _array_api_astype(x, dtype, /, *, copy=True): +def _array_api_astype(x, dtype, *, copy=True): """ Copies an array to a specified data type irrespective of + `Type Promotion Rules `_ rules. """ pass @@ -33,7 +36,7 @@ def _array_api_broadcast_arrays(*arrays): @expose.not_implemented("broadcast_to") -def _array_api_broadcast_to(x, /, shape): +def _array_api_broadcast_to(x, shape): """ Broadcasts an array to a specified shape. """ @@ -41,15 +44,16 @@ def _array_api_broadcast_to(x, /, shape): @expose.not_implemented("can_cast") -def _array_api_can_cast(from_, to, /): +def _array_api_can_cast(from_, to): """ Determines if one data type can be cast to another data type according + `Type Promotion Rules `_ rules. """ pass @expose.not_implemented("finfo") -def _array_api_finfo(type, /): +def _array_api_finfo(type): """ Machine limits for floating-point data types. """ @@ -57,7 +61,7 @@ def _array_api_finfo(type, /): @expose.not_implemented("iinfo") -def _array_api_iinfo(type, /): +def _array_api_iinfo(type): """ Machine limits for integer data types. """ @@ -67,6 +71,8 @@ def _array_api_iinfo(type, /): @expose.not_implemented("result_type") def _array_api_result_type(*arrays_and_dtypes): """ - Returns the dtype that results from applying the type promotion rules (see + Returns the dtype that results from applying the type promotion + rules (see `Type Promotion Rules `_) + to the arguments. """ pass diff --git a/rbc/stdlib/datatypes.py b/rbc/stdlib/datatypes.py index 5a1197f0..b7090a5e 100644 --- a/rbc/stdlib/datatypes.py +++ b/rbc/stdlib/datatypes.py @@ -1,4 +1,6 @@ """ +Array API specification for data types. + https://data-apis.org/array-api/latest/API_specification/data_types.html """ diff --git a/rbc/stdlib/linear_algebra_functions.py b/rbc/stdlib/linear_algebra_functions.py index 88691c11..1495d2cd 100644 --- a/rbc/stdlib/linear_algebra_functions.py +++ b/rbc/stdlib/linear_algebra_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for linear algebra functions. + https://data-apis.org/array-api/latest/API_specification/linear_algebra_functions.html """ from rbc.stdlib import Expose @@ -9,7 +11,7 @@ @expose.not_implemented("matmul") -def _array_api_matmul(x1, x2, /): +def _array_api_matmul(x1, x2): """ Computes the matrix product. """ @@ -17,7 +19,7 @@ def _array_api_matmul(x1, x2, /): @expose.not_implemented("matrix_transpose") -def _array_api_matrix_transpose(x, /): +def _array_api_matrix_transpose(x): """ Transposes a matrix (or a stack of matrices) """ @@ -25,7 +27,7 @@ def _array_api_matrix_transpose(x, /): @expose.not_implemented("tensordot") -def _array_api_tensordot(x1, x2, /, *, axes=2): +def _array_api_tensordot(x1, x2, *, axes=2): """ Returns a tensor contraction of """ @@ -33,7 +35,7 @@ def _array_api_tensordot(x1, x2, /, *, axes=2): @expose.not_implemented("vecdot") -def _array_api_vecdot(x1, x2, /, *, axis=-1): +def _array_api_vecdot(x1, x2, *, axis=-1): """ Computes the (vector) dot product of two arrays. """ diff --git a/rbc/stdlib/manipulation_functions.py b/rbc/stdlib/manipulation_functions.py index ce932cdd..fe5a3df8 100644 --- a/rbc/stdlib/manipulation_functions.py +++ b/rbc/stdlib/manipulation_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for manipulation functions. + https://data-apis.org/array-api/latest/API_specification/manipulation_functions.html """ from rbc.stdlib import Expose @@ -18,7 +20,7 @@ @expose.not_implemented("concat") -def _array_api_concat(arrays, /, *, axis=0): +def _array_api_concat(arrays, *, axis=0): """ Joins a sequence of arrays along an existing axis. """ @@ -26,7 +28,7 @@ def _array_api_concat(arrays, /, *, axis=0): @expose.not_implemented("expand_dims") -def _array_api_expand_dims(x, /, *, axis=0): +def _array_api_expand_dims(x, *, axis=0): """ Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by @@ -35,7 +37,7 @@ def _array_api_expand_dims(x, /, *, axis=0): @expose.not_implemented("flip") -def _array_api_flip(x, /, *, axis=None): +def _array_api_flip(x, *, axis=None): """ Reverses the order of elements in an array along the given axis. """ @@ -43,7 +45,7 @@ def _array_api_flip(x, /, *, axis=None): @expose.not_implemented("permute_dims") -def _array_api_permute_dims(x, /, axes): +def _array_api_permute_dims(x, axes): """ Permutes the axes (dimensions) of an array """ @@ -51,7 +53,7 @@ def _array_api_permute_dims(x, /, axes): @expose.not_implemented("reshape") -def _array_api_reshape(x, /, shape, *, copy=None): +def _array_api_reshape(x, shape, *, copy=None): """ Reshapes an array without changing its data. """ @@ -59,7 +61,7 @@ def _array_api_reshape(x, /, shape, *, copy=None): @expose.not_implemented("roll") -def _array_api_roll(x, /, shift, *, axis=None): +def _array_api_roll(x, shift, *, axis=None): """ Rolls array elements along a specified axis. """ @@ -67,7 +69,7 @@ def _array_api_roll(x, /, shift, *, axis=None): @expose.not_implemented("squeeze") -def _array_api_squeeze(x, /, axis): +def _array_api_squeeze(x, axis): """ Removes singleton dimensions (axes) from """ @@ -75,7 +77,7 @@ def _array_api_squeeze(x, /, axis): @expose.not_implemented("stack") -def _array_api_stack(arrays, /, *, axis=0): +def _array_api_stack(arrays, *, axis=0): """ Joins a sequence of arrays along a new axis. """ diff --git a/rbc/stdlib/searching_functions.py b/rbc/stdlib/searching_functions.py index 18aed2d4..64f48c60 100644 --- a/rbc/stdlib/searching_functions.py +++ b/rbc/stdlib/searching_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for searching functions. + https://data-apis.org/array-api/latest/API_specification/searching_functions.html """ from rbc.stdlib import Expose @@ -9,7 +11,7 @@ @expose.not_implemented("argmax") -def _array_api_argmax(x, /, *, axis=None, keepdims=False): +def _array_api_argmax(x, *, axis=None, keepdims=False): """ Returns the indices of the maximum values along a specified axis. """ @@ -17,7 +19,7 @@ def _array_api_argmax(x, /, *, axis=None, keepdims=False): @expose.not_implemented("argmin") -def _array_api_argmin(x, /, *, axis=None, keepdims=False): +def _array_api_argmin(x, *, axis=None, keepdims=False): """ Returns the indices of the minimum values along a specified axis. """ @@ -25,7 +27,7 @@ def _array_api_argmin(x, /, *, axis=None, keepdims=False): @expose.not_implemented("nonzero") -def _array_api_nonzero(x, /): +def _array_api_nonzero(x): """ Returns the indices of the array elements which are non-zero. """ @@ -33,7 +35,7 @@ def _array_api_nonzero(x, /): @expose.not_implemented("where") -def _array_api_where(condition, x1, x2, /): +def _array_api_where(condition, x1, x2): """ Returns elements chosen from """ diff --git a/rbc/stdlib/set_functions.py b/rbc/stdlib/set_functions.py index b0f90205..7ece515b 100644 --- a/rbc/stdlib/set_functions.py +++ b/rbc/stdlib/set_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for set functions. + https://data-apis.org/array-api/latest/API_specification/set_functions.html """ from rbc.stdlib import Expose @@ -9,7 +11,7 @@ @expose.not_implemented("unique_all") -def _array_api_unique_all(x, /): +def _array_api_unique_all(x): """ Returns the unique elements of an input array """ @@ -17,7 +19,7 @@ def _array_api_unique_all(x, /): @expose.not_implemented("unique_counts") -def _array_api_unique_counts(x, /): +def _array_api_unique_counts(x): """ Returns the unique elements of an input array """ @@ -25,7 +27,7 @@ def _array_api_unique_counts(x, /): @expose.not_implemented("unique_inverse") -def _array_api_unique_inverse(x, /): +def _array_api_unique_inverse(x): """ Returns the unique elements of an input array """ @@ -33,7 +35,7 @@ def _array_api_unique_inverse(x, /): @expose.not_implemented("unique_values") -def _array_api_unique_values(x, /): +def _array_api_unique_values(x): """ Returns the unique elements of an input array """ diff --git a/rbc/stdlib/sorting_functions.py b/rbc/stdlib/sorting_functions.py index 7f1708ae..820ca5a7 100644 --- a/rbc/stdlib/sorting_functions.py +++ b/rbc/stdlib/sorting_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for sorting functions. + https://data-apis.org/array-api/latest/API_specification/sorting_functions.html """ from rbc.stdlib import Expose @@ -9,7 +11,7 @@ @expose.not_implemented("argsort") -def _array_api_all(x, /, *, axis=-1, descending=False, stable=True): +def _array_api_all(x, *, axis=-1, descending=False, stable=True): """ Returns the indices that sort an array x along a specified axis. """ @@ -17,7 +19,7 @@ def _array_api_all(x, /, *, axis=-1, descending=False, stable=True): @expose.not_implemented("sort") -def _array_api_any(x, /, *, axis=-1, descending=False, stable=True): +def _array_api_any(x, *, axis=-1, descending=False, stable=True): """ Returns the indices that sort an array x along a specified axis. """ diff --git a/rbc/stdlib/utility_functions.py b/rbc/stdlib/utility_functions.py index 30875d6c..ad0a7183 100644 --- a/rbc/stdlib/utility_functions.py +++ b/rbc/stdlib/utility_functions.py @@ -1,4 +1,6 @@ """ +Array API specification for utility functions. + https://data-apis.org/array-api/latest/API_specification/utility_functions.html """ from rbc.stdlib import Expose @@ -9,7 +11,7 @@ @expose.not_implemented("all") -def _array_api_all(x, /, *, axis=None, keepdims=False): +def _array_api_all(x, *, axis=None, keepdims=False): """ Tests whether all input array elements evaluate to True along a specified axis. """ @@ -17,7 +19,7 @@ def _array_api_all(x, /, *, axis=None, keepdims=False): @expose.not_implemented("any") -def _array_api_any(x, /, *, axis=None, keepdims=False): +def _array_api_any(x, *, axis=None, keepdims=False): """ Tests whether any input array element evaluates to True along a specified axis. """ diff --git a/setup.cfg b/setup.cfg index 4f442525..e55babbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,7 @@ per-file-ignores = rbc/omnisci_backend/numpy_ufuncs.py: F822 # undefined name in __all__ rbc/omnisci_backend/numpy_funcs.py: F822 rbc/stdlib/creation_functions.py: F822 - rbc/stdlib/data_type_functions.py: F822 + rbc/stdlib/data_type_functions.py: F822, E501 rbc/stdlib/linear_algebra_functions.py: F822 rbc/stdlib/manipulation_functions.py: F822 rbc/stdlib/searching_functions.py: F822 From 447270ccce2c009eb17291ea7b24d0c1530ead95 Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 14 Mar 2022 23:01:53 -0300 Subject: [PATCH 4/9] undo code deletion --- doc/api.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/api.rst b/doc/api.rst index a23970b7..c0021da4 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -15,6 +15,15 @@ Top-level functions :toctree: generated/ ctools + external + errors + libfuncs + omniscidb + remotejit + structure_type + targetinfo + typesystem + utils Array API @@ -43,6 +52,11 @@ Externals .. autosummary:: :toctree: generated/ + externals.cmath + externals.libdevice + externals.macros + externals.omniscidb + externals.stdio OmniSciDB Backend From f7868cfc9a678e6ecf32f163d57d4bbaea58bc8b Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Mon, 14 Mar 2022 23:42:46 -0300 Subject: [PATCH 5/9] more fixes --- rbc/stdlib/linear_algebra_functions.py | 4 ++-- rbc/stdlib/manipulation_functions.py | 6 +++--- rbc/stdlib/searching_functions.py | 2 +- rbc/stdlib/set_functions.py | 13 +++++++++---- rbc/stdlib/sorting_functions.py | 6 +++--- rbc/stdlib/utility_functions.py | 4 ++-- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/rbc/stdlib/linear_algebra_functions.py b/rbc/stdlib/linear_algebra_functions.py index 1495d2cd..caac3a87 100644 --- a/rbc/stdlib/linear_algebra_functions.py +++ b/rbc/stdlib/linear_algebra_functions.py @@ -21,7 +21,7 @@ def _array_api_matmul(x1, x2): @expose.not_implemented("matrix_transpose") def _array_api_matrix_transpose(x): """ - Transposes a matrix (or a stack of matrices) + Transposes a matrix (or a stack of matrices) x. """ pass @@ -29,7 +29,7 @@ def _array_api_matrix_transpose(x): @expose.not_implemented("tensordot") def _array_api_tensordot(x1, x2, *, axes=2): """ - Returns a tensor contraction of + Returns a tensor contraction of x1 and x2 over specific axis. """ pass diff --git a/rbc/stdlib/manipulation_functions.py b/rbc/stdlib/manipulation_functions.py index fe5a3df8..01cc8ba6 100644 --- a/rbc/stdlib/manipulation_functions.py +++ b/rbc/stdlib/manipulation_functions.py @@ -31,7 +31,7 @@ def _array_api_concat(arrays, *, axis=0): def _array_api_expand_dims(x, *, axis=0): """ Expands the shape of an array by inserting a new axis (dimension) - of size one at the position specified by + of size one at the position specified by axis """ pass @@ -47,7 +47,7 @@ def _array_api_flip(x, *, axis=None): @expose.not_implemented("permute_dims") def _array_api_permute_dims(x, axes): """ - Permutes the axes (dimensions) of an array + Permutes the axes (dimensions) of an array x. """ pass @@ -71,7 +71,7 @@ def _array_api_roll(x, shift, *, axis=None): @expose.not_implemented("squeeze") def _array_api_squeeze(x, axis): """ - Removes singleton dimensions (axes) from + Removes singleton dimensions (axes) from x. """ pass diff --git a/rbc/stdlib/searching_functions.py b/rbc/stdlib/searching_functions.py index 64f48c60..851c900e 100644 --- a/rbc/stdlib/searching_functions.py +++ b/rbc/stdlib/searching_functions.py @@ -37,6 +37,6 @@ def _array_api_nonzero(x): @expose.not_implemented("where") def _array_api_where(condition, x1, x2): """ - Returns elements chosen from + Returns elements chosen from `x1` or `x2` depending on `condition`. """ pass diff --git a/rbc/stdlib/set_functions.py b/rbc/stdlib/set_functions.py index 7ece515b..cac80599 100644 --- a/rbc/stdlib/set_functions.py +++ b/rbc/stdlib/set_functions.py @@ -13,7 +13,10 @@ @expose.not_implemented("unique_all") def _array_api_unique_all(x): """ - Returns the unique elements of an input array + Returns the unique elements of an input array `x`, the first + ocurring indices for each unique element in `x`, the indices from + the set of unique elements that reconstruct `x`, and the corresponding + counts for each unique element in `x`. """ pass @@ -21,7 +24,8 @@ def _array_api_unique_all(x): @expose.not_implemented("unique_counts") def _array_api_unique_counts(x): """ - Returns the unique elements of an input array + Returns the unique elements of an input array `x` and the corresponding + counts for each unique element in `x`. """ pass @@ -29,7 +33,8 @@ def _array_api_unique_counts(x): @expose.not_implemented("unique_inverse") def _array_api_unique_inverse(x): """ - Returns the unique elements of an input array + Returns the unique elements of an input array `x` and the indices + from the set of unique elements that reconstruct `x`. """ pass @@ -37,6 +42,6 @@ def _array_api_unique_inverse(x): @expose.not_implemented("unique_values") def _array_api_unique_values(x): """ - Returns the unique elements of an input array + Returns the unique elements of an input array `x`. """ pass diff --git a/rbc/stdlib/sorting_functions.py b/rbc/stdlib/sorting_functions.py index 820ca5a7..ff493587 100644 --- a/rbc/stdlib/sorting_functions.py +++ b/rbc/stdlib/sorting_functions.py @@ -11,9 +11,9 @@ @expose.not_implemented("argsort") -def _array_api_all(x, *, axis=-1, descending=False, stable=True): +def _array_api_argsort(x, *, axis=-1, descending=False, stable=True): """ - Returns the indices that sort an array x along a specified axis. + Returns the indices that sort an array `x` along a specified axis. """ pass @@ -21,6 +21,6 @@ def _array_api_all(x, *, axis=-1, descending=False, stable=True): @expose.not_implemented("sort") def _array_api_any(x, *, axis=-1, descending=False, stable=True): """ - Returns the indices that sort an array x along a specified axis. + Returns a sorted copy of an input array `x`. """ pass diff --git a/rbc/stdlib/utility_functions.py b/rbc/stdlib/utility_functions.py index ad0a7183..5a221a84 100644 --- a/rbc/stdlib/utility_functions.py +++ b/rbc/stdlib/utility_functions.py @@ -13,7 +13,7 @@ @expose.not_implemented("all") def _array_api_all(x, *, axis=None, keepdims=False): """ - Tests whether all input array elements evaluate to True along a specified axis. + Tests whether all input array elements evaluate to `True` along a specified axis. """ pass @@ -21,6 +21,6 @@ def _array_api_all(x, *, axis=None, keepdims=False): @expose.not_implemented("any") def _array_api_any(x, *, axis=None, keepdims=False): """ - Tests whether any input array element evaluates to True along a specified axis. + Tests whether any input array element evaluates to `True` along a specified axis. """ pass From 3f2b6ad2cde5a146f8970431be01ad37b61dce09 Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Tue, 15 Mar 2022 14:58:59 -0300 Subject: [PATCH 6/9] test unsupported functions --- parse.py | 49 ++++++++++++++++++++++++ rbc/stdlib/creation_functions.py | 19 +++++----- rbc/stdlib/elementwise_functions.py | 5 ++- rbc/stdlib/sorting_functions.py | 2 +- rbc/stdlib/statistical_functions.py | 2 +- rbc/tests/test_array_api_unsupported.py | 50 +++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 parse.py create mode 100644 rbc/tests/test_array_api_unsupported.py diff --git a/parse.py b/parse.py new file mode 100644 index 00000000..a0ab9b79 --- /dev/null +++ b/parse.py @@ -0,0 +1,49 @@ +from collections import namedtuple +import requests +from rich import print +from bs4 import BeautifulSoup +import sys + +t = namedtuple('p', ('name', 'signature', 'docstring')) + + +def gen(page, l): + template = f''' +""" +https://data-apis.org/array-api/latest/API_specification/{page}.html +""" +from rbc.stdlib import Expose + +__all__ = [{', '.join([f"'{func.name}'" for func in l])}] + +expose = Expose(globals(), "{page}") +''' + + for func in l: + template += f''' + +@expose.not_implemented("{func.name}") +def _array_api_{func.name}{func.signature}: + """ + {func.docstring} + """ + pass +''' + return template.lstrip() + + +if __name__ == '__main__': + page = sys.argv[1] + link = f"https://data-apis.org/array-api/latest/API_specification/{page}.html" + r = requests.get(link) + html = BeautifulSoup(r.content, 'html.parser') + l = [] + for c in html.article.table.tbody: + if c == '\n': + continue + name = c.contents[0].p.a.span.contents[0] + sig = c.contents[0].p.contents[-1] + docstring = c.contents[2].p.contents[0].strip() + l.append(t(name, sig, docstring)) + + print(gen(page, l)) \ No newline at end of file diff --git a/rbc/stdlib/creation_functions.py b/rbc/stdlib/creation_functions.py index 4dbaed0b..91d7bb61 100644 --- a/rbc/stdlib/creation_functions.py +++ b/rbc/stdlib/creation_functions.py @@ -12,7 +12,8 @@ __all__ = [ 'full', 'full_like', 'empty_like', 'empty', 'zeros', 'zeros_like', - 'ones', 'ones_like', 'array', 'cumsum' + 'ones', 'ones_like', 'array', 'cumsum', 'arange', 'asarray', + 'eye', 'from_dlpack', 'linspace', 'meshgrid', 'tril', 'triu' ] @@ -20,7 +21,7 @@ @expose.not_implemented('arange') -def arange(start, stop=None, step=1, dtype=None, device=None): +def _array_api_arange(start, stop=None, step=1, dtype=None, device=None): """ Return evenly spaced values within a given interval. """ @@ -28,7 +29,7 @@ def arange(start, stop=None, step=1, dtype=None, device=None): @expose.not_implemented('asarray') -def asarray(obj, dtype=None, device=None, copy=None): +def _array_api_asarray(obj, dtype=None, device=None, copy=None): """ Convert the input to an array. """ @@ -36,7 +37,7 @@ def asarray(obj, dtype=None, device=None, copy=None): @expose.not_implemented('eye') -def eye(n_rows, n_cols=None, k=0, dtype=None, device=None): +def _array_api_eye(n_rows, n_cols=None, k=0, dtype=None, device=None): """ Return a 2-D array with ones on the diagonal and zeros elsewhere. """ @@ -44,14 +45,14 @@ def eye(n_rows, n_cols=None, k=0, dtype=None, device=None): @expose.not_implemented('from_dlpack') -def from_dlpack(x): +def _array_api_from_dlpack(x): """ """ pass @expose.not_implemented('linspace') -def linspace(start, stop, num, dtype=None, device=None, endpoint=True): +def _array_api_linspace(start, stop, num, dtype=None, device=None, endpoint=True): """ Return evenly spaced numbers over a specified interval. """ @@ -59,7 +60,7 @@ def linspace(start, stop, num, dtype=None, device=None, endpoint=True): @expose.not_implemented('meshgrid') -def meshgrid(*arrays, indexing='xy'): +def _array_api_meshgrid(*arrays, indexing='xy'): """ Return coordinate matrices from coordinate vectors. """ @@ -67,7 +68,7 @@ def meshgrid(*arrays, indexing='xy'): @expose.not_implemented('tril') -def tril(x, k=0): +def _array_api_tril(x, k=0): """ Lower triangle of an array. """ @@ -75,7 +76,7 @@ def tril(x, k=0): @expose.not_implemented('triu') -def triu(x, k=0): +def _array_api_triu(x, k=0): """ Upper triangle of an array. """ diff --git a/rbc/stdlib/elementwise_functions.py b/rbc/stdlib/elementwise_functions.py index c5b01fce..5bc415d2 100644 --- a/rbc/stdlib/elementwise_functions.py +++ b/rbc/stdlib/elementwise_functions.py @@ -27,10 +27,11 @@ 'rad2deg', 'logical_not', 'isfinite', 'isinf', 'isnan', 'fabs', 'floor', 'ceil', 'trunc', 'signbit', 'copysign', 'spacing', 'heaviside', 'bitwise_left_shift', 'bitwise_right_shift', - 'round', + 'round', 'isnat', # numpy specifics 'power', 'arctan2', 'left_shift', 'right_shift', 'absolute', - 'invert', 'arcsin', 'arctan', 'arccos', 'arcsinh', 'arccosh', 'arctanh' + 'invert', 'arcsin', 'arctan', 'arccos', 'arcsinh', 'arccosh', 'arctanh', + 'float_power', 'divmod', 'cbrt', ] diff --git a/rbc/stdlib/sorting_functions.py b/rbc/stdlib/sorting_functions.py index ff493587..f6831999 100644 --- a/rbc/stdlib/sorting_functions.py +++ b/rbc/stdlib/sorting_functions.py @@ -19,7 +19,7 @@ def _array_api_argsort(x, *, axis=-1, descending=False, stable=True): @expose.not_implemented("sort") -def _array_api_any(x, *, axis=-1, descending=False, stable=True): +def _array_api_sort(x, *, axis=-1, descending=False, stable=True): """ Returns a sorted copy of an input array `x`. """ diff --git a/rbc/stdlib/statistical_functions.py b/rbc/stdlib/statistical_functions.py index c6d58d17..1bba880f 100644 --- a/rbc/stdlib/statistical_functions.py +++ b/rbc/stdlib/statistical_functions.py @@ -13,7 +13,7 @@ __all__ = [ - 'min', 'max', 'mean', 'prod', 'sum' + 'min', 'max', 'mean', 'prod', 'sum', 'std', 'var' ] diff --git a/rbc/tests/test_array_api_unsupported.py b/rbc/tests/test_array_api_unsupported.py new file mode 100644 index 00000000..aed1308e --- /dev/null +++ b/rbc/tests/test_array_api_unsupported.py @@ -0,0 +1,50 @@ +import pytest +from rbc.stdlib import array_api +from rbc.tests import omnisci_fixture +from numba import TypingError + + +@pytest.fixture(scope="module") +def omnisci(): + + for o in omnisci_fixture(globals()): + yield o + + +unsupported_functions = [ + # statistical_function + 'std', 'var', + # manipulation_functions + "concat", "expand_dims", "flip", "permute_dims", "reshape", "roll", "squeeze", "stack", + # utility_functions + "all", "any", + # sorting_functions + "argsort", "sort", + # searching_functions + "argmax", "argmin", "nonzero", "where", + # elementwise_functions + 'float_power', 'divmod', 'cbrt', 'isnat', + # set_functions + "unique_all", "unique_counts", "unique_inverse", "unique_values", + # linear_algebra_functions + "matmul", "matrix_transpose", "tensordot", "vecdot", + # data_type_functions + "astype", "broadcast_arrays", "broadcast_to", "can_cast", "finfo", "iinfo", "result_type", + # creation_functions + 'arange', 'asarray', 'eye', 'from_dlpack', 'linspace', 'meshgrid', 'tril', 'triu', +] + + +# ensure unimplemented functions raise a meaninful exception +@pytest.mark.parametrize('func_name', unsupported_functions) +def test_unimplemented(omnisci, func_name): + + func = getattr(array_api, func_name) + + @omnisci('int64(int64)') + def test_exception_raised(x): + return func(x) + + # NumbaNotSupportedError is captured and a TypingError is returned instead + with pytest.raises(TypingError, match=f'Function "{func_name}" is not supported.'): + omnisci.register() From 6f1285c5a058b13982f53f17498738ceb31c5eca Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Tue, 15 Mar 2022 16:29:32 -0300 Subject: [PATCH 7/9] upd --- parse.py | 49 ------------------------------------------ rbc/stdlib/__init__.py | 14 +++++++----- 2 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 parse.py diff --git a/parse.py b/parse.py deleted file mode 100644 index a0ab9b79..00000000 --- a/parse.py +++ /dev/null @@ -1,49 +0,0 @@ -from collections import namedtuple -import requests -from rich import print -from bs4 import BeautifulSoup -import sys - -t = namedtuple('p', ('name', 'signature', 'docstring')) - - -def gen(page, l): - template = f''' -""" -https://data-apis.org/array-api/latest/API_specification/{page}.html -""" -from rbc.stdlib import Expose - -__all__ = [{', '.join([f"'{func.name}'" for func in l])}] - -expose = Expose(globals(), "{page}") -''' - - for func in l: - template += f''' - -@expose.not_implemented("{func.name}") -def _array_api_{func.name}{func.signature}: - """ - {func.docstring} - """ - pass -''' - return template.lstrip() - - -if __name__ == '__main__': - page = sys.argv[1] - link = f"https://data-apis.org/array-api/latest/API_specification/{page}.html" - r = requests.get(link) - html = BeautifulSoup(r.content, 'html.parser') - l = [] - for c in html.article.table.tbody: - if c == '\n': - continue - name = c.contents[0].p.a.span.contents[0] - sig = c.contents[0].p.contents[-1] - docstring = c.contents[2].p.contents[0].strip() - l.append(t(name, sig, docstring)) - - print(gen(page, l)) \ No newline at end of file diff --git a/rbc/stdlib/__init__.py b/rbc/stdlib/__init__.py index c71bc2e6..10fed296 100644 --- a/rbc/stdlib/__init__.py +++ b/rbc/stdlib/__init__.py @@ -2,7 +2,7 @@ from enum import Enum from numba.core import extending from rbc.omnisci_backend import Array, ArrayPointer -from rbc import typesystem +from rbc import typesystem, errors ARRAY_API_ADDRESS = ("https://data-apis.org/array-api/latest/API_specification" @@ -76,16 +76,20 @@ def wrapper(overload_func): return wrapper def not_implemented(self, func_name, api=API.ARRAY_API): - s = f'def {func_name}(*args, **kwargs): pass' - exec(s, self._globals) + fn = self.create_function(func_name) + decorate = extending.overload(fn) - fn = self._globals.get(func_name) + def unimplemented(*args, **kwargs): + raise errors.NumbaNotImplementedError(f'Function "{func_name}" is not supported.\n' + 'Please, open a ticket on the RBC project ' + 'and report this error if you need support for ' + 'this function.') def wraps(overload_func): original_doc = self.format_docstring(overload_func, func_name, api) overload_func.__doc__ = f"❌ Not implemented\n{original_doc}" functools.update_wrapper(fn, overload_func) - return overload_func + return decorate(unimplemented) return wraps From 3cd9c855d0cc5e1d23b9a8b5c9a85bc45a0af8fc Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Tue, 15 Mar 2022 19:07:23 -0300 Subject: [PATCH 8/9] redo array table of contents --- doc/api.rst | 59 ++-------------- rbc/omnisci_backend/omnisci_array.py | 100 ++++++++++++++++++++++++++- rbc/stdlib/array_attributes.py | 7 -- rbc/stdlib/array_methods.py | 7 -- 4 files changed, 103 insertions(+), 70 deletions(-) delete mode 100644 rbc/stdlib/array_attributes.py delete mode 100644 rbc/stdlib/array_methods.py diff --git a/doc/api.rst b/doc/api.rst index c0021da4..a6360f1d 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -70,58 +70,7 @@ The set of types below are only materialize inside the OmniSciDB SQL Engine. Thu one cannot create and use them inside the REPL, for instance. -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

- - rbc.omnisci_backend.Array -

-

-

- - rbc.omnisci_backend.Bytes -

-

-

- - rbc.omnisci_backend.Column -

-

-

- - rbc.omnisci_backend.OutputColumn -

-

-

- - rbc.omnisci_backend.ColumnList -

-

+.. autosummary:: + :toctree: generated/ + + rbc.omnisci_backend.Array diff --git a/rbc/omnisci_backend/omnisci_array.py b/rbc/omnisci_backend/omnisci_array.py index ac0573fc..53e0345b 100644 --- a/rbc/omnisci_backend/omnisci_array.py +++ b/rbc/omnisci_backend/omnisci_array.py @@ -8,6 +8,10 @@ OmnisciBufferType, omnisci_buffer_constructor) from numba.core import extending, types +from typing import Union, TypeVar + + +T = TypeVar('T') class OmnisciArrayType(OmnisciBufferType): @@ -31,7 +35,101 @@ def buffer_extra_members(self): class Array(Buffer): - pass + """ + In HeavyDB, an Array of type `T` is represented as follows: + + .. code-block:: C + + { + T* data, + int64_t size, + int8_t is_null + } + + Array is a contiguous block of memory that behaves like a python list. + + Example + + + .. code-block:: python + + from numba import types + from rbc.omnisci_backend import Array + + @omnisci('int64[](int64)') + def create_and_fill_array(size): + arr = Array(size, types.int64) + for i in range(size): + a[i] = i + return a + """ + + def __init__(self, size: int, dtype: Union[str, types.Type]) -> None: + pass + + def is_null(self) -> bool: + pass + + @property + def dtype(self): + """ + Data type of the array elements. + """ + pass + + @property + def device(self): + """ + ❌ Not implemented + + Hardware device the array data resides on. + """ + pass + + @property + def mT(self): + """ + ❌ Not implemented + + Transpose of a amtrix (or a stack of matrices). + """ + pass + + @property + def ndim(self): + """ + ❌ Not implemented + + Number of array dimensions (axes). + """ + pass + + @property + def shape(self): + """ + ❌ Not implemented + + Array dimensions. + """ + pass + + @property + def size(self): + """ + ❌ Not implemented + + Number of elements in an array. + """ + pass + + @property + def T(self): + """ + ❌ Not implemented + + Transpose of the array. + """ + pass @extending.lower_builtin(Array, types.Integer, types.StringLiteral) diff --git a/rbc/stdlib/array_attributes.py b/rbc/stdlib/array_attributes.py deleted file mode 100644 index 9a22afe3..00000000 --- a/rbc/stdlib/array_attributes.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -Array API specification for array attributes. - -https://data-apis.org/array-api/latest/API_specification/array_object.html#attributes -""" - -__all__ = [] diff --git a/rbc/stdlib/array_methods.py b/rbc/stdlib/array_methods.py deleted file mode 100644 index 0b61df00..00000000 --- a/rbc/stdlib/array_methods.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -Array API specification for array methods. - -https://data-apis.org/array-api/latest/API_specification/data_type_functions.html -""" - -__all__ = [] From ac4a8c468320cb4e7b8718d37e60829d8585c201 Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Thu, 17 Mar 2022 14:38:00 -0300 Subject: [PATCH 9/9] address reviewer comments --- rbc/omnisci_backend/omnisci_array.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rbc/omnisci_backend/omnisci_array.py b/rbc/omnisci_backend/omnisci_array.py index 53e0345b..1670c3a6 100644 --- a/rbc/omnisci_backend/omnisci_array.py +++ b/rbc/omnisci_backend/omnisci_array.py @@ -46,18 +46,18 @@ class Array(Buffer): int8_t is_null } - Array is a contiguous block of memory that behaves like a python list. + Array holds a contiguous block of memory and it implements a + subset of the array protocol. Example - .. code-block:: python from numba import types from rbc.omnisci_backend import Array @omnisci('int64[](int64)') - def create_and_fill_array(size): + def my_arange(size): arr = Array(size, types.int64) for i in range(size): a[i] = i @@ -91,7 +91,7 @@ def mT(self): """ ❌ Not implemented - Transpose of a amtrix (or a stack of matrices). + Transpose of a matrix (or a stack of matrices). """ pass