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

refactor: rename ak.nplikeak.nplikes & nplikes.ofnplikes.nplike_of #1744

Merged
merged 3 commits into from
Sep 28, 2022
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
2 changes: 1 addition & 1 deletion dev/generate-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def gencudakerneltests(specdict):
)

f.write(
"import cupy\nimport pytest\n\nimport awkward as ak\nimport awkward._connect.cuda as ak_cu\n\ncupy_nplike = ak.nplike.Cupy.instance()\n\n"
"import cupy\nimport pytest\n\nimport awkward as ak\nimport awkward._connect.cuda as ak_cu\n\ncupy_nplike = ak.nplikes.Cupy.instance()\n\n"
)
num = 1
if spec.tests == []:
Expand Down
2 changes: 1 addition & 1 deletion docs-sphinx/prepare_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def dofunction(link, linelink, shortname, name, astfcn):
"awkwardforth.rst",
])

if modulename.startswith("awkward._") or modulename == "awkward.nplike" or modulename == "awkward.types._awkward_datashape_parser":
if modulename.startswith("awkward._") or modulename == "awkward.nplikes" or modulename == "awkward.types._awkward_datashape_parser":
continue # don't show awkward._*, including _v2

link = ("`{0} <https://github.com/scikit-hep/awkward-1.0/blob/"
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

# NumPy-like alternatives
import awkward.nplike
import awkward.nplikes

# shims for C++ (now everything is compiled into one 'awkward._ext' module)
import awkward._ext
Expand Down
8 changes: 4 additions & 4 deletions src/awkward/_broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
)
from awkward.record import Record # noqa: F401

np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()
np = ak.nplikes.NumpyMetadata.instance()
numpy = ak.nplikes.Numpy.instance()

optiontypes = (IndexedOptionArray, ByteMaskedArray, BitMaskedArray, UnmaskedArray)
listtypes = (ListOffsetArray, ListArray, RegularArray)
Expand All @@ -48,7 +48,7 @@ def broadcast_pack(inputs, isscalar):
nextinputs = []
for x in inputs:
if isinstance(x, Record):
index = ak.nplike.of(*inputs).full(maxlen, x.at, dtype=np.int64)
index = ak.nplikes.nplike_of(*inputs).full(maxlen, x.at, dtype=np.int64)
nextinputs.append(RegularArray(x.array[index], maxlen, 1))
isscalar.append(True)
elif isinstance(x, Content):
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def broadcast_and_apply(
function_name=None,
broadcast_parameters_rule=BroadcastParameterRule.INTERSECT,
):
nplike = ak.nplike.of(*inputs)
nplike = ak.nplikes.nplike_of(*inputs)
isscalar = []
out = apply_step(
nplike,
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_connect/cling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()
np = ak.nplikes.NumpyMetadata.instance()
numpy = ak.nplikes.Numpy.instance()


cache = {}
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_connect/jax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def replace_numpyarray_nodes(node, **kwargs):
buffer,
layout.identifier,
layout.parameters,
nplike=ak.nplike.Jax.instance(),
nplike=ak.nplikes.Jax.instance(),
)

return layout.recursively_apply(action=replace_numpyarray_nodes)
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_connect/jax/_reducers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import awkward as ak
from awkward._connect.jax import import_jax

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


class Reducer:
Expand Down
10 changes: 5 additions & 5 deletions src/awkward/_connect/numba/arrayview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


def code_to_function(code, function_name, externals=None, debug=False):
Expand Down Expand Up @@ -871,7 +871,7 @@ def array_supported(dtype):
) or isinstance(dtype, (numba.types.NPDatetime, numba.types.NPTimedelta))


@numba.extending.overload(ak.nplike.numpy.array)
@numba.extending.overload(ak.nplikes.numpy.array)
def overload_np_array(array, dtype=None):
if isinstance(array, ArrayViewType):
ndim = array.type.ndim
Expand Down Expand Up @@ -936,11 +936,11 @@ def array_impl(array, dtype=None):
"\n ".join(fill_array),
),
"array_impl",
{"numpy": ak.nplike.numpy},
{"numpy": ak.nplikes.numpy},
)


@numba.extending.type_callable(ak.nplike.numpy.asarray)
@numba.extending.type_callable(ak.nplikes.numpy.asarray)
def type_asarray(context):
def typer(arrayview):
if (
Expand All @@ -954,7 +954,7 @@ def typer(arrayview):
return typer


@numba.extending.lower_builtin(ak.nplike.numpy.asarray, ArrayViewType)
@numba.extending.lower_builtin(ak.nplikes.numpy.asarray, ArrayViewType)
def lower_asarray(context, builder, sig, args):
rettype, (viewtype,) = sig.return_type, sig.args
(viewval,) = args
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_connect/numba/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import awkward as ak

numpy = ak.nplike.Numpy.instance()
numpy = ak.nplikes.Numpy.instance()

dynamic_addrs = {}

Expand Down
4 changes: 2 additions & 2 deletions src/awkward/_connect/numba/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()
np = ak.nplikes.NumpyMetadata.instance()
numpy = ak.nplikes.Numpy.instance()


@numba.extending.typeof_impl.register(ak.contents.Content)
Expand Down
10 changes: 5 additions & 5 deletions src/awkward/_connect/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def convert_to_array(layout, args, kwargs):

def _to_rectilinear(arg):
if isinstance(arg, tuple):
nplike = ak.nplike.of(*arg)
nplike = ak.nplikes.nplike_of(*arg)
return tuple(nplike.to_rectilinear(x) for x in arg)
else:
nplike = ak.nplike.of(arg)
nplike = ak.nplikes.nplike_of(arg)
nplike.to_rectilinear(arg)


Expand All @@ -39,7 +39,7 @@ def array_function(func, types, args, kwargs):
args = tuple(_to_rectilinear(x) for x in args)
kwargs = {k: _to_rectilinear(v) for k, v in kwargs.items()}
out = func(*args, **kwargs)
nplike = ak.nplike.of(out)
nplike = ak.nplikes.nplike_of(out)
if isinstance(out, nplike.ndarray) and len(out.shape) != 0:
return ak.Array(out)
else:
Expand Down Expand Up @@ -149,7 +149,7 @@ def action(inputs, **ignore):
isinstance(x, NumpyArray) or not isinstance(x, ak.contents.Content)
for x in inputs
):
nplike = ak.nplike.of(*inputs)
nplike = ak.nplikes.nplike_of(*inputs)

# Broadcast parameters against one another
parameters_factory = ak._broadcasting.intersection_parameters_factory(
Expand All @@ -164,7 +164,7 @@ def action(inputs, **ignore):
else:
args.append(x)

if isinstance(nplike, ak.nplike.Jax):
if isinstance(nplike, ak.nplikes.Jax):
from awkward._connect.jax import import_jax

jax = import_jax()
Expand Down
10 changes: 5 additions & 5 deletions src/awkward/_connect/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()

try:
import pyarrow
Expand Down Expand Up @@ -491,7 +491,7 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
ak.contents.NumpyArray(
numpy.frombuffer(pacontent, dtype=np.uint8),
parameters=sub_parameters,
nplike=ak.nplike.Numpy.instance(),
nplike=ak.nplikes.Numpy.instance(),
),
storage_type.byte_width,
parameters=parameters,
Expand Down Expand Up @@ -527,7 +527,7 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
ak.contents.NumpyArray(
numpy.frombuffer(pacontent, dtype=np.uint8),
parameters=sub_parameters,
nplike=ak.nplike.Numpy.instance(),
nplike=ak.nplikes.Numpy.instance(),
),
parameters=parameters,
)
Expand Down Expand Up @@ -627,7 +627,7 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
out = ak.contents.NumpyArray(
bytedata.view(np.bool_),
parameters=node_parameters(awkwardarrow_type),
nplike=ak.nplike.Numpy.instance(),
nplike=ak.nplikes.Numpy.instance(),
)
return popbuffers_finalize(
out, paarray, validbits, awkwardarrow_type, generate_bitmasks
Expand All @@ -647,7 +647,7 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers, generate_bitma
out = ak.contents.NumpyArray(
numpy.frombuffer(data, dtype=dt),
parameters=node_parameters(awkwardarrow_type),
nplike=ak.nplike.Numpy.instance(),
nplike=ak.nplikes.Numpy.instance(),
)
return popbuffers_finalize(
out, paarray, validbits, awkwardarrow_type, generate_bitmasks
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/_connect/rdataframe/from_rdataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"timedelta64": "std::difftime",
}

np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()
np = ak.nplikes.NumpyMetadata.instance()
numpy = ak.nplikes.Numpy.instance()


cppyy.add_include_path(
Expand Down Expand Up @@ -64,7 +64,7 @@ def form_dtype(form):
def empty_buffers(cpp_buffers_self, names_nbytes):
buffers = {}
for item in names_nbytes:
buffers[item.first] = ak.nplike.numpy.empty(item.second)
buffers[item.first] = ak.nplikes.numpy.empty(item.second)
cpp_buffers_self.append(
item.first,
buffers[item.first].ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte)),
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


class Lookup:
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import awkward as ak

numpy = ak.nplike.Numpy.instance()
numpy = ak.nplikes.Numpy.instance()


def half(integer):
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_reducers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


class Reducer:
Expand Down
8 changes: 4 additions & 4 deletions src/awkward/_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


def headtail(oldtail):
Expand Down Expand Up @@ -61,7 +61,7 @@ def prepare_advanced_indexing(items):
)

# Then broadcast the index items
nplike = ak.nplike.of(*broadcastable)
nplike = ak.nplikes.nplike_of(*broadcastable)
broadcasted = nplike.broadcast_arrays(*broadcastable)

# And re-assemble the index with the broadcasted items
Expand Down Expand Up @@ -391,7 +391,7 @@ def normalise_item_bool_to_int(item):
and issubclass(item.content.content.dtype.type, (bool, np.bool_))
):
if item.nplike.known_data or item.nplike.known_shape:
if isinstance(item.nplike, ak.nplike.Jax):
if isinstance(item.nplike, ak.nplikes.Jax):
raise ak._util.error(
"This slice is not supported for JAX differentiation."
)
Expand Down Expand Up @@ -460,7 +460,7 @@ def normalise_item_bool_to_int(item):
item.content.dtype.type, (bool, np.bool_)
):
if item.nplike.known_data or item.nplike.known_shape:
if isinstance(item.nplike, ak.nplike.Jax):
if isinstance(item.nplike, ak.nplikes.Jax):
raise ak._util.error(
"This slice is not supported for JAX differentiation."
)
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/_typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import numpy

import awkward as ak
import awkward.nplike
import awkward.nplikes

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()


class NoError:
Expand Down Expand Up @@ -464,7 +464,7 @@ def copy(self):
return self


class TypeTracer(ak.nplike.NumpyLike):
class TypeTracer(ak.nplikes.NumpyLike):
known_data = False
known_shape = False

Expand Down
16 changes: 8 additions & 8 deletions src/awkward/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import awkward as ak

np = ak.nplike.NumpyMetadata.instance()
np = ak.nplikes.NumpyMetadata.instance()

win = os.name == "nt"
bits32 = ak.nplike.numpy.iinfo(np.intp).bits == 32
bits32 = ak.nplikes.numpy.iinfo(np.intp).bits == 32

# matches include/awkward/common.h
kMaxInt8 = 127 # 2**7 - 1
Expand All @@ -32,9 +32,9 @@
kMaxLevels = 48

_backends = {
"cpu": ak.nplike.Numpy,
"cuda": ak.nplike.Cupy,
"jax": ak.nplike.Jax,
"cpu": ak.nplikes.Numpy,
"cuda": ak.nplikes.Cupy,
"jax": ak.nplikes.Jax,
}


Expand Down Expand Up @@ -782,7 +782,7 @@ def extra(args, kwargs, defaults):


def union_to_record(unionarray, anonymous):
nplike = ak.nplike.of(unionarray)
nplike = ak.nplikes.nplike_of(unionarray)

contents = []
for layout in unionarray.contents:
Expand Down Expand Up @@ -921,8 +921,8 @@ def expand_braces(text, seen=None):


def from_arraylib(array, regulararray, recordarray, highlevel, behavior):
np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()
np = ak.nplikes.NumpyMetadata.instance()
numpy = ak.nplikes.Numpy.instance()

def recurse(array, mask=None):
if regulararray and len(array.shape) > 1:
Expand Down
Loading