Skip to content
Snippets Groups Projects
Unverified Commit c472a481 authored by Thomas Baumann's avatar Thomas Baumann Committed by GitHub
Browse files

Fix for missing numpy data types on some platforms (#514)

* Fix for missing numpy data types on some platforms

* Implemented @tlunet's suggestions

* Aesthetic changes
parent c468fb78
Branches
Tags
No related merge requests found
...@@ -49,6 +49,7 @@ wether code is run in parallel or not. ...@@ -49,6 +49,7 @@ wether code is run in parallel or not.
import os import os
import numpy as np import numpy as np
from typing import Type, TypeVar from typing import Type, TypeVar
import logging
T = TypeVar("T") T = TypeVar("T")
...@@ -69,11 +70,26 @@ except ImportError: ...@@ -69,11 +70,26 @@ except ImportError:
DTYPES = { DTYPES = {
0: np.float64, # double precision 0: np.float64, # double precision
1: np.complex128, 1: np.complex128,
}
try:
DTYPES.update(
{
2: np.float128, # quadruple precision 2: np.float128, # quadruple precision
3: np.complex256, 3: np.complex256,
}
)
except AttributeError:
logging.getLogger('FieldsIO').debug('Warning: Quadruple precision not available on this machine')
try:
DTYPES.update(
{
4: np.float32, # single precision 4: np.float32, # single precision
5: np.complex64, 5: np.complex64,
} }
)
except AttributeError:
logging.getLogger('FieldsIO').debug('Warning: Single precision not available on this machine')
DTYPES_AVAIL = {val: key for key, val in DTYPES.items()} DTYPES_AVAIL = {val: key for key, val in DTYPES.items()}
# Header dtype # Header dtype
...@@ -100,7 +116,7 @@ class FieldsIO: ...@@ -100,7 +116,7 @@ class FieldsIO:
fileName : str fileName : str
File. File.
""" """
assert dtype in DTYPES_AVAIL, f"{dtype=} not available" assert dtype in DTYPES_AVAIL, f"{dtype=} not available. Supported on this machine: {list(DTYPES_AVAIL.keys())}"
self.dtype = dtype self.dtype = dtype
self.fileName = fileName self.fileName = fileName
self.initialized = False self.initialized = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment