Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
36919c1
Move _linspace_step/_linspace_affine to dpctl_ext/tensor/libtensor
vlad-perevezentsev Feb 23, 2026
95ac4f7
Move ti.linspace() and reuse it in dpnp
vlad-perevezentsev Feb 23, 2026
1054e2d
Move ti.empty() and reuse it in dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
d493454
Reuse dpctl_ext.tensor.empty() in dpnp
vlad-perevezentsev Feb 23, 2026
186ae3c
Move ti.empty_like() and reuse it in dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
5503b9a
Reuse dpctl_ext.tensor.empty_like() in dpnp
vlad-perevezentsev Feb 23, 2026
748c5b5
Move ti.arange() to dpctl_ext/tensor and reuse it in dpnp
vlad-perevezentsev Feb 23, 2026
a7370a8
Move ti.asarray() and reuse it in dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
effcbe8
Reuse dpctl_ext.tensor.asarray() in dpnp
vlad-perevezentsev Feb 23, 2026
f9f547a
Move ti.full_like() to dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
0d84d7b
Move ti.meshgrid() to dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
8c15ddb
Move ti.ones() to dpctl_ext/tensor and reuse it in dpnp
vlad-perevezentsev Feb 23, 2026
23d2229
Move ti.ones_like() to dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
97dc7e1
Move ti.zeros() to dpctl_ext/tensor and reuse it in dpnp
vlad-perevezentsev Feb 23, 2026
a6c397e
Move ti.zeros_like() to dpctl_ext/tensor
vlad-perevezentsev Feb 23, 2026
b8c5390
Move ti.broadcast_to() to dpctl_ext/tensor and reuse it in dpctl_ext/…
vlad-perevezentsev Feb 23, 2026
a7cbfdc
Reuse dpctl_ext.tensor.broadcast_to() in dpnp
vlad-perevezentsev Feb 23, 2026
bd265da
Move ti.broadcast_arrays() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
080c7d8
Move ti.concat() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
ea7ea3c
Move ti.expand_dims() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
d2e9279
Move ti.flip() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
4e63cca
Move ti.permute_dims() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
9c88edb
Move ti.moveaxis() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
ba51636
Move ti.squeeze() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
bb16c19
Move ti.stack() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
ccad5f0
Move ti.swapaxes() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
b5e3541
Move ti.tile() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
325729b
Move ti.unstack() to dpctl_ext.tensor and reuse it
vlad-perevezentsev Feb 23, 2026
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
4 changes: 2 additions & 2 deletions dpctl_ext/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set(_tensor_impl_sources
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_numpy_ndarray_into_usm_ndarray.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_for_reshape.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_for_roll.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/linear_sequences.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/linear_sequences.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/integer_advanced_indexing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/boolean_advanced_indexing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/eye_ctor.cpp
Expand Down Expand Up @@ -93,7 +93,7 @@ endif()
set(_no_fast_math_sources
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_and_cast_usm_to_usm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/full_ctor.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/linear_sequences.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/linear_sequences.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/clip.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/where.cpp
)
Expand Down
46 changes: 46 additions & 0 deletions dpctl_ext/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@
to_numpy,
)
from dpctl_ext.tensor._ctors import (
arange,
asarray,
empty,
empty_like,
eye,
full,
full_like,
linspace,
meshgrid,
ones,
ones_like,
tril,
triu,
zeros,
zeros_like,
)
from dpctl_ext.tensor._indexing_functions import (
extract,
Expand All @@ -52,39 +63,74 @@
take_along_axis,
)
from dpctl_ext.tensor._manipulation_functions import (
broadcast_arrays,
broadcast_to,
concat,
expand_dims,
flip,
moveaxis,
permute_dims,
repeat,
roll,
squeeze,
stack,
swapaxes,
tile,
unstack,
)
from dpctl_ext.tensor._reshape import reshape

from ._clip import clip
from ._type_utils import can_cast, finfo, iinfo, isdtype, result_type

__all__ = [
"arange",
"asarray",
"asnumpy",
"astype",
"broadcast_arrays",
"broadcast_to",
"can_cast",
"concat",
"copy",
"clip",
"empty",
"empty_like",
"extract",
"expand_dims",
"eye",
"finfo",
"flip",
"from_numpy",
"full",
"full_like",
"iinfo",
"isdtype",
"linspace",
"meshgrid",
"moveaxis",
"permute_dims",
"nonzero",
"ones",
"ones_like",
"place",
"put",
"put_along_axis",
"repeat",
"reshape",
"result_type",
"roll",
"squeeze",
"stack",
"swapaxes",
"take",
"take_along_axis",
"tile",
"to_numpy",
"tril",
"triu",
"unstack",
"where",
"zeros",
"zeros_like",
]
74 changes: 37 additions & 37 deletions dpctl_ext/tensor/_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,20 @@ def _clip_none(x, val, out, order, _binary_fn):

if ti._array_overlap(x, out):
if not ti._same_logical_tensors(x, out):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)

if isinstance(val, dpt.usm_ndarray):
if (
ti._array_overlap(val, out)
and not ti._same_logical_tensors(val, out)
and val_dtype == res_dt
):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)

if isinstance(val, dpt.usm_ndarray):
val_ary = val
else:
val_ary = dpt.asarray(val, dtype=val_dtype, sycl_queue=exec_q)
val_ary = dpt_ext.asarray(val, dtype=val_dtype, sycl_queue=exec_q)

if order == "A":
order = (
Expand All @@ -197,17 +197,17 @@ def _clip_none(x, val, out, order, _binary_fn):
x, val_ary, res_dt, res_shape, res_usm_type, exec_q
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
sycl_queue=exec_q,
order=order,
)
if x_shape != res_shape:
x = dpt.broadcast_to(x, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
if val_ary.shape != res_shape:
val_ary = dpt.broadcast_to(val_ary, res_shape)
val_ary = dpt_ext.broadcast_to(val_ary, res_shape)
_manager = SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
ht_binary_ev, binary_ev = _binary_fn(
Expand All @@ -229,7 +229,7 @@ def _clip_none(x, val, out, order, _binary_fn):
if order == "K":
buf = _empty_like_orderK(val_ary, res_dt)
else:
buf = dpt.empty_like(val_ary, dtype=res_dt, order=order)
buf = dpt_ext.empty_like(val_ary, dtype=res_dt, order=order)
_manager = SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
Expand All @@ -242,7 +242,7 @@ def _clip_none(x, val, out, order, _binary_fn):
x, buf, res_dt, res_shape, res_usm_type, exec_q
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
Expand All @@ -251,8 +251,8 @@ def _clip_none(x, val, out, order, _binary_fn):
)

if x_shape != res_shape:
x = dpt.broadcast_to(x, res_shape)
buf = dpt.broadcast_to(buf, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
buf = dpt_ext.broadcast_to(buf, res_shape)
ht_binary_ev, binary_ev = _binary_fn(
src1=x,
src2=buf,
Expand Down Expand Up @@ -353,14 +353,14 @@ def clip(x, /, min=None, max=None, out=None, order="K"):

if ti._array_overlap(x, out):
if not ti._same_logical_tensors(x, out):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)
else:
return out
else:
if order == "K":
out = _empty_like_orderK(x, x.dtype)
else:
out = dpt.empty_like(x, order=order)
out = dpt_ext.empty_like(x, order=order)

_manager = SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
Expand Down Expand Up @@ -519,32 +519,32 @@ def clip(x, /, min=None, max=None, out=None, order="K"):

if ti._array_overlap(x, out):
if not ti._same_logical_tensors(x, out):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)

if isinstance(min, dpt.usm_ndarray):
if (
ti._array_overlap(min, out)
and not ti._same_logical_tensors(min, out)
and buf1_dt is None
):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)

if isinstance(max, dpt.usm_ndarray):
if (
ti._array_overlap(max, out)
and not ti._same_logical_tensors(max, out)
and buf2_dt is None
):
out = dpt.empty_like(out)
out = dpt_ext.empty_like(out)

if isinstance(min, dpt.usm_ndarray):
a_min = min
else:
a_min = dpt.asarray(min, dtype=min_dtype, sycl_queue=exec_q)
a_min = dpt_ext.asarray(min, dtype=min_dtype, sycl_queue=exec_q)
if isinstance(max, dpt.usm_ndarray):
a_max = max
else:
a_max = dpt.asarray(max, dtype=max_dtype, sycl_queue=exec_q)
a_max = dpt_ext.asarray(max, dtype=max_dtype, sycl_queue=exec_q)

if order == "A":
order = (
Expand Down Expand Up @@ -572,19 +572,19 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
exec_q,
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
sycl_queue=exec_q,
order=order,
)
if x_shape != res_shape:
x = dpt.broadcast_to(x, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
if a_min.shape != res_shape:
a_min = dpt.broadcast_to(a_min, res_shape)
a_min = dpt_ext.broadcast_to(a_min, res_shape)
if a_max.shape != res_shape:
a_max = dpt.broadcast_to(a_max, res_shape)
a_max = dpt_ext.broadcast_to(a_max, res_shape)
_manager = SequentialOrderManager[exec_q]
dep_ev = _manager.submitted_events
ht_binary_ev, binary_ev = ti._clip(
Expand Down Expand Up @@ -612,7 +612,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
if order == "K":
buf2 = _empty_like_orderK(a_max, buf2_dt)
else:
buf2 = dpt.empty_like(a_max, dtype=buf2_dt, order=order)
buf2 = dpt_ext.empty_like(a_max, dtype=buf2_dt, order=order)
_manager = SequentialOrderManager[exec_q]
dep_ev = _manager.submitted_events
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
Expand All @@ -631,18 +631,18 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
exec_q,
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
sycl_queue=exec_q,
order=order,
)

x = dpt.broadcast_to(x, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
if a_min.shape != res_shape:
a_min = dpt.broadcast_to(a_min, res_shape)
buf2 = dpt.broadcast_to(buf2, res_shape)
a_min = dpt_ext.broadcast_to(a_min, res_shape)
buf2 = dpt_ext.broadcast_to(buf2, res_shape)
ht_binary_ev, binary_ev = ti._clip(
src=x,
min=a_min,
Expand All @@ -668,7 +668,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
if order == "K":
buf1 = _empty_like_orderK(a_min, buf1_dt)
else:
buf1 = dpt.empty_like(a_min, dtype=buf1_dt, order=order)
buf1 = dpt_ext.empty_like(a_min, dtype=buf1_dt, order=order)
_manager = SequentialOrderManager[exec_q]
dep_ev = _manager.submitted_events
ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray(
Expand All @@ -687,18 +687,18 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
exec_q,
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
sycl_queue=exec_q,
order=order,
)

x = dpt.broadcast_to(x, res_shape)
buf1 = dpt.broadcast_to(buf1, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
buf1 = dpt_ext.broadcast_to(buf1, res_shape)
if a_max.shape != res_shape:
a_max = dpt.broadcast_to(a_max, res_shape)
a_max = dpt_ext.broadcast_to(a_max, res_shape)
ht_binary_ev, binary_ev = ti._clip(
src=x,
min=buf1,
Expand Down Expand Up @@ -736,7 +736,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
if order == "K":
buf1 = _empty_like_orderK(a_min, buf1_dt)
else:
buf1 = dpt.empty_like(a_min, dtype=buf1_dt, order=order)
buf1 = dpt_ext.empty_like(a_min, dtype=buf1_dt, order=order)

_manager = SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
Expand All @@ -747,7 +747,7 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
if order == "K":
buf2 = _empty_like_orderK(a_max, buf2_dt)
else:
buf2 = dpt.empty_like(a_max, dtype=buf2_dt, order=order)
buf2 = dpt_ext.empty_like(a_max, dtype=buf2_dt, order=order)
ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray(
src=a_max, dst=buf2, sycl_queue=exec_q, depends=dep_evs
)
Expand All @@ -758,17 +758,17 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
x, buf1, buf2, res_dt, res_shape, res_usm_type, exec_q
)
else:
out = dpt.empty(
out = dpt_ext.empty(
res_shape,
dtype=res_dt,
usm_type=res_usm_type,
sycl_queue=exec_q,
order=order,
)

x = dpt.broadcast_to(x, res_shape)
buf1 = dpt.broadcast_to(buf1, res_shape)
buf2 = dpt.broadcast_to(buf2, res_shape)
x = dpt_ext.broadcast_to(x, res_shape)
buf1 = dpt_ext.broadcast_to(buf1, res_shape)
buf2 = dpt_ext.broadcast_to(buf2, res_shape)
ht_, clip_ev = ti._clip(
src=x,
min=buf1,
Expand Down
Loading
Loading