Skip to content

Commit

Permalink
update black format
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Aug 21, 2023
1 parent 9566a8a commit 96a0742
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 120 deletions.
61 changes: 34 additions & 27 deletions pyclesperanto/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import numpy as np
import warnings


def __str__(self) -> str:
return self.get().__str__()


def __repr__(self) -> str:
repr_str = self.get().__repr__()
extra_info = f"mtype={self.mtype}"
return repr_str[:-1] + f", {extra_info})"


def set(self, array: np.ndarray) -> None:
if array.dtype != self.dtype:
warnings.warn(
Expand All @@ -35,6 +38,7 @@ def set(self, array: np.ndarray) -> None:
self._write(array)
return self


def get(self) -> np.ndarray:
caster = {
"float32": self._read_float32,
Expand All @@ -49,11 +53,13 @@ def get(self) -> np.ndarray:
}
return caster[self.dtype.name]()


def __array__(self, dtype=None) -> np.ndarray:
if dtype is None:
return self.get()
else:
return self.get().astype(dtype)
if dtype is None:
return self.get()
else:
return self.get().astype(dtype)


# missing operators:
# __setitem__
Expand All @@ -66,32 +72,33 @@ def __array__(self, dtype=None) -> np.ndarray:
setattr(Array, "__str__", __str__)
setattr(Array, "__repr__", __repr__)
setattr(Array, "__array__", __array__)
setattr(Array,"astype",_operators.astype)
setattr(Array,"max",_operators.max)
setattr(Array,"min",_operators.min)
setattr(Array,"sum",_operators.sum)
setattr(Array,"__iadd__",_operators.__iadd__)
setattr(Array,"__sub__",_operators.__sub__)
setattr(Array,"__div__",_operators.__div__)
setattr(Array,"__truediv__",_operators.__truediv__)
setattr(Array,"__idiv__",_operators.__idiv__)
setattr(Array,"__itruediv__",_operators.__itruediv__)
setattr(Array,"__mul__",_operators.__mul__)
setattr(Array,"__imul__",_operators.__imul__)
setattr(Array,"__gt__",_operators.__gt__)
setattr(Array,"__ge__",_operators.__ge__)
setattr(Array,"__lt__",_operators.__lt__)
setattr(Array,"__le__",_operators.__le__)
setattr(Array,"__eq__",_operators.__eq__)
setattr(Array,"__ne__",_operators.__ne__)
setattr(Array,"__pow__",_operators.__pow__)
setattr(Array,"__ipow__",_operators.__ipow__)
setattr(Array,"_plt_to_png",_operators._plt_to_png)
setattr(Array,"_png_to_html",_operators._png_to_html)
setattr(Array,"_repr_html_",_operators._repr_html_)
setattr(Array, "astype", _operators.astype)
setattr(Array, "max", _operators.max)
setattr(Array, "min", _operators.min)
setattr(Array, "sum", _operators.sum)
setattr(Array, "__iadd__", _operators.__iadd__)
setattr(Array, "__sub__", _operators.__sub__)
setattr(Array, "__div__", _operators.__div__)
setattr(Array, "__truediv__", _operators.__truediv__)
setattr(Array, "__idiv__", _operators.__idiv__)
setattr(Array, "__itruediv__", _operators.__itruediv__)
setattr(Array, "__mul__", _operators.__mul__)
setattr(Array, "__imul__", _operators.__imul__)
setattr(Array, "__gt__", _operators.__gt__)
setattr(Array, "__ge__", _operators.__ge__)
setattr(Array, "__lt__", _operators.__lt__)
setattr(Array, "__le__", _operators.__le__)
setattr(Array, "__eq__", _operators.__eq__)
setattr(Array, "__ne__", _operators.__ne__)
setattr(Array, "__pow__", _operators.__pow__)
setattr(Array, "__ipow__", _operators.__ipow__)
setattr(Array, "_plt_to_png", _operators._plt_to_png)
setattr(Array, "_png_to_html", _operators._png_to_html)
setattr(Array, "_repr_html_", _operators._repr_html_)

Image = Union[np.ndarray, Array]


def is_image(any_array):
return (
isinstance(any_array, np.ndarray)
Expand Down
32 changes: 23 additions & 9 deletions pyclesperanto/_functionalities.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def imshow(
labels: Optional[bool] = False,
min_display_intensity: Optional[float] = None,
max_display_intensity: Optional[float] = None,
color_map: Optional[str]=None,
color_map: Optional[str] = None,
plot=None,
colorbar: Optional[bool] = False,
colormap: Union[str, None] = None,
Expand Down Expand Up @@ -172,7 +172,9 @@ def imshow(
plt.title(title)


def operations(must_have_categories : list = None, must_not_have_categories : list = None) -> dict:
def operations(
must_have_categories: list = None, must_not_have_categories: list = None
) -> dict:
"""Retrieve a dictionary of operations, which can be filtered by annotated categories.
Parameters
Expand Down Expand Up @@ -205,26 +207,38 @@ def operations(must_have_categories : list = None, must_not_have_categories : li
keep_it = True
if hasattr(operation, "categories") and operation.categories is not None:
if must_have_categories is not None:
if not all(item in operation.categories for item in must_have_categories):
if not all(
item in operation.categories for item in must_have_categories
):
keep_it = False

if must_not_have_categories is not None:
if any(item in operation.categories for item in must_not_have_categories):
if any(
item in operation.categories for item in must_not_have_categories
):
keep_it = False
else:
if must_have_categories is not None:
keep_it = False
if (keep_it):
if keep_it:
result[operation_name] = operation

return result


def list_operations(search_term = None):
def list_operations(search_term=None):
ops = operations(search_term)
for name in ops:
func = ops[name]
if hasattr(func, 'fullargspec'):
print(name + "(" + str(func.fullargspec.args).replace('[','').replace(']','').replace('\'','') + ")")
if hasattr(func, "fullargspec"):
print(
name
+ "("
+ str(func.fullargspec.args)
.replace("[", "")
.replace("]", "")
.replace("'", "")
+ ")"
)
else:
print(name)
print(name)
19 changes: 13 additions & 6 deletions pyclesperanto/_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import numpy as np
from typing import Tuple, Optional


def create(
shape: Tuple[int, ...],
dtype: Optional[type] = None,
mtype: Optional[str] = None,
device: Optional[Device] = None,
) -> Image:
""" Create a new image on the device.
"""Create a new image on the device.
Parameters
----------
Expand All @@ -36,7 +37,10 @@ def create(
dtype = np.float32
if dtype in [float, np.float64]:
dtype = np.float32
warnings.warn("Warning: float64 type is not a supported in GPUs. Casting data to float32 type.", UserWarning)
warnings.warn(
"Warning: float64 type is not a supported in GPUs. Casting data to float32 type.",
UserWarning,
)
if mtype is None:
mtype = "buffer"
if device is None:
Expand All @@ -50,7 +54,7 @@ def create_like(
mtype: Optional[str] = None,
device: Optional[Device] = None,
) -> Image:
""" Create a new image on the device with the same shape and dtype as the input image.
"""Create a new image on the device with the same shape and dtype as the input image.
Parameters
----------
Expand All @@ -72,7 +76,10 @@ def create_like(
dtype = array.dtype
if dtype in [float, np.float64]:
dtype = np.float32
warnings.warn("Warning: float64 type is not a supported in GPUs. Casting data to float32 type.", UserWarning)
warnings.warn(
"Warning: float64 type is not a supported in GPUs. Casting data to float32 type.",
UserWarning,
)
return create(array.shape, dtype, mtype, device)


Expand All @@ -82,7 +89,7 @@ def push(
mtype: Optional[str] = None,
device: Optional[Device] = None,
) -> Image:
""" Create a new image on the device and push the input image into it.
"""Create a new image on the device and push the input image into it.
Parameters
----------
Expand Down Expand Up @@ -110,7 +117,7 @@ def push(


def pull(array: Image) -> np.ndarray:
""" Pull the input image from the device to the host.
"""Pull the input image from the device to the host.
Parameters
----------
Expand Down
Loading

0 comments on commit 96a0742

Please sign in to comment.