Skip to content

Commit c472a48

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
1 parent c468fb7 commit c472a48

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pySDC/helpers/fieldsIO.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import os
5050
import numpy as np
5151
from typing import Type, TypeVar
52+
import logging
5253

5354
T = TypeVar("T")
5455

@@ -69,11 +70,26 @@ class MPI:
6970
DTYPES = {
7071
0: np.float64, # double precision
7172
1: np.complex128,
72-
2: np.float128, # quadruple precision
73-
3: np.complex256,
74-
4: np.float32, # single precision
75-
5: np.complex64,
7673
}
74+
try:
75+
DTYPES.update(
76+
{
77+
2: np.float128, # quadruple precision
78+
3: np.complex256,
79+
}
80+
)
81+
except AttributeError:
82+
logging.getLogger('FieldsIO').debug('Warning: Quadruple precision not available on this machine')
83+
try:
84+
DTYPES.update(
85+
{
86+
4: np.float32, # single precision
87+
5: np.complex64,
88+
}
89+
)
90+
except AttributeError:
91+
logging.getLogger('FieldsIO').debug('Warning: Single precision not available on this machine')
92+
7793
DTYPES_AVAIL = {val: key for key, val in DTYPES.items()}
7894

7995
# Header dtype
@@ -100,7 +116,7 @@ def __init__(self, dtype, fileName):
100116
fileName : str
101117
File.
102118
"""
103-
assert dtype in DTYPES_AVAIL, f"{dtype=} not available"
119+
assert dtype in DTYPES_AVAIL, f"{dtype=} not available. Supported on this machine: {list(DTYPES_AVAIL.keys())}"
104120
self.dtype = dtype
105121
self.fileName = fileName
106122
self.initialized = False

0 commit comments

Comments
 (0)