Skip to content

always cast to float32, try to convert other array types too #527

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

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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
32 changes: 7 additions & 25 deletions fastplotlib/graphics/_features/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,18 @@
WGPU_MAX_TEXTURE_SIZE = 8192


supported_dtypes = [
np.uint8,
np.uint16,
np.uint32,
np.int8,
np.int16,
np.int32,
np.float16,
np.float32,
]


def to_gpu_supported_dtype(array):
"""
If ``array`` is a numpy array, converts it to a supported type. GPUs don't support 64 bit dtypes.
convert input array to float32 numpy array
"""
if isinstance(array, np.ndarray):
if array.dtype not in supported_dtypes:
if np.issubdtype(array.dtype, np.integer):
warn(f"converting {array.dtype} array to int32")
return array.astype(np.int32)
elif np.issubdtype(array.dtype, np.floating):
warn(f"converting {array.dtype} array to float32")
return array.astype(np.float32, copy=False)
else:
raise TypeError(
"Unsupported type, supported array types must be int or float dtypes"
)
if not array.dtype == np.float32:
warn(f"casting {array.dtype} array to float32")
return array.astype(np.float32)
return array

return array
# try to make a numpy array from it, should not copy, tested with jax arrays
return np.asarray(array).astype(np.float32)


class FeatureEvent(pygfx.Event):
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy