Skip to content

astype with 1d array, copy=False and specified order always makes a copy #1926

@AlexanderKalistratov

Description

@AlexanderKalistratov
import dpctl.tensor as dpt
import time

a = dpt.zeros(10**7)

a.sycl_queue.wait()
begin = time.time()
a_ = dpt.astype(a, a.dtype, copy=False, order="C")
a_.sycl_queue.wait()
end = time.time()

print("astype time:", end - begin)
print("a is a_", a is a_)

a.sycl_queue.wait()
begin = time.time()
a__ = dpt.asarray(a, dtype=a.dtype)
a__.sycl_queue.wait()
end = time.time()

print("asarray time:", end - begin)
print("a is a__", a is a__)

Output:

astype time: 0.02135610580444336
a is a_ False
asarray time: 8.7738037109375e-05
a is a__ True

The problem is here

f_contig and order not in ["A", "F"]
:

    c_contig = usm_ary.flags.c_contiguous # = True for 1d contiguous array
    f_contig = usm_ary.flags.f_contiguous # Also = **True** for 1d contiguous array
    needs_copy = copy or not ary_dtype == target_dtype
    if not needs_copy and (order != "K"):
        needs_copy = (c_contig and order not in ["A", "C"]) or ( # = False since c_contig == True and order == "C"
            f_contig and order not in ["A", "F"] # = **True** since f_contig == True and order == "C"
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions