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

improve pyopencl interoperability + added test #181

Merged
merged 1 commit into from
May 7, 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
8 changes: 8 additions & 0 deletions pyclesperanto_prototype/_tier0/_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def create_like(*args):
dimensions = dimensions.shape
elif isinstance(dimensions, np.ndarray):
dimensions = dimensions.shape[::-1]
elif hasattr(dimensions, "shape"):
dimensions = dimensions.shape
return create(dimensions)

def create_binary_like(*args):
Expand All @@ -37,6 +39,8 @@ def create_binary_like(*args):
dimensions = dimensions.shape
elif isinstance(dimensions, np.ndarray):
dimensions = dimensions.shape[::-1]
elif hasattr(dimensions, "shape"):
dimensions = dimensions.shape
return create(dimensions, np.uint8)

def create_labels_like(*args):
Expand All @@ -45,6 +49,8 @@ def create_labels_like(*args):
dimensions = dimensions.shape
elif isinstance(dimensions, np.ndarray):
dimensions = dimensions.shape[::-1]
elif hasattr(dimensions, "shape"):
dimensions = dimensions.shape
return create(dimensions, np.uint32)

def create_same_type_like(*args):
Expand All @@ -53,6 +59,8 @@ def create_same_type_like(*args):
dimensions = dimensions.shape
elif isinstance(dimensions, np.ndarray):
dimensions = dimensions.shape[::-1]
elif hasattr(dimensions, "shape"):
dimensions = dimensions.shape
return create(dimensions, dimensions.dtype)

def create_pointlist_from_labelmap(source, *args):
Expand Down
19 changes: 18 additions & 1 deletion tests/test_pyopencl_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ def test_pyopencl_compatibility():
cl_c = cl_a + cl_b

import pyclesperanto_prototype as cle
cl_c = cl_a + cl_b
cl_c = cl_a + cl_b

def test_semi_push():
import numpy as np
img = np.asarray([[1,2],[3,4], [5,6]])

import pyclesperanto_prototype as cle
device = cle.get_device()

import pyopencl.array as cla
pushed = cla.to_device(device.queue, img)

print(type(pushed))
print(pushed.shape)
blurred = cle.gaussian_blur(pushed, sigma_x=10, sigma_y=10, sigma_z=10)

assert np.array_equal(blurred.shape, pushed.shape)