Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unimplemented functions from array_api #453

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 12 additions & 56 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,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
Expand All @@ -63,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

<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%">
<col style="width: 90%">
</colgroup>
<tbody>
<tr class="row-odd">
<td>
<p><a class="reference internal" href="omnisci/array.html" title="rbc.omnisci_backend.Array">
<code class="xref py py-obj docutils literal notranslate">
<span class="pre">rbc.omnisci_backend.Array</span>
</code></a></p>
</td>
<td><p></p></td>
</tr>
<tr class="row-even">
<td>
<p><a class="reference internal" href="omnisci/bytes.html" title="rbc.omnisci_backend.Bytes">
<code class="xref py py-obj docutils literal notranslate">
<span class="pre">rbc.omnisci_backend.Bytes</span>
</code></a></p>
</td>
<td><p></p></td>
</tr>
<tr class="row-odd">
<td>
<p><a class="reference internal" href="omnisci/column.html" title="rbc.omnisci_backend.Column">
<code class="xref py py-obj docutils literal notranslate">
<span class="pre">rbc.omnisci_backend.Column</span>
</code></a></p>
</td>
<td><p></p></td>
</tr>
<tr class="row-even">
<td>
<p><a class="reference internal" href="omnisci/outputcolumn.html" title="rbc.omnisci_backend.OutputColumn">
<code class="xref py py-obj docutils literal notranslate">
<span class="pre">rbc.omnisci_backend.OutputColumn</span>
</code></a></p>
</td>
<td><p></p></td>
</tr>
<tr class="row-odd">
<td>
<p><a class="reference internal" href="omnisci/columnlist.html" title="rbc.omnisci_backend.ColumnList">
<code class="xref py py-obj docutils literal notranslate">
<span class="pre">rbc.omnisci_backend.ColumnList</span>
</code></a></p>
</td>
<td><p></p></td>
</tr>
</tbody>
</table>
.. autosummary::
:toctree: generated/

rbc.omnisci_backend.Array
100 changes: 99 additions & 1 deletion rbc/omnisci_backend/omnisci_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 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 my_arange(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 matrix (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)
Expand Down
23 changes: 14 additions & 9 deletions rbc/stdlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -75,16 +75,21 @@ def wrapper(overload_func):

return wrapper

def not_implemented(self, func_name):
s = f'def {func_name}(*args, **kwargs): pass'
exec(s, self._globals)
def not_implemented(self, func_name, api=API.ARRAY_API):
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(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 decorate(unimplemented)
return wraps


Expand Down
11 changes: 9 additions & 2 deletions rbc/stdlib/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("_")]
2 changes: 2 additions & 0 deletions rbc/stdlib/constants.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 10 additions & 9 deletions rbc/stdlib/creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,71 @@

__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'
]


expose = Expose(globals(), 'creation_functions')


@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.
"""
pass


@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.
"""
pass


@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.
"""
pass


@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.
"""
pass


@expose.not_implemented('meshgrid')
def meshgrid(*arrays, indexing='xy'):
def _array_api_meshgrid(*arrays, indexing='xy'):
"""
Return coordinate matrices from coordinate vectors.
"""
pass


@expose.not_implemented('tril')
def tril(x, k=0):
def _array_api_tril(x, k=0):
"""
Lower triangle of an array.
"""
pass


@expose.not_implemented('triu')
def triu(x, k=0):
def _array_api_triu(x, k=0):
"""
Upper triangle of an array.
"""
Expand Down
Loading