Skip to content

Commit

Permalink
Fix for missing numpy data types on some platforms (#514)
Browse files Browse the repository at this point in the history
* Fix for missing numpy data types on some platforms

* Implemented @tlunet's suggestions

* Aesthetic changes
  • Loading branch information
brownbaerchen authored Jan 22, 2025
1 parent c468fb7 commit c472a48
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pySDC/helpers/fieldsIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import os
import numpy as np
from typing import Type, TypeVar
import logging

T = TypeVar("T")

Expand All @@ -69,11 +70,26 @@ class MPI:
DTYPES = {
0: np.float64, # double precision
1: np.complex128,
2: np.float128, # quadruple precision
3: np.complex256,
4: np.float32, # single precision
5: np.complex64,
}
try:
DTYPES.update(
{
2: np.float128, # quadruple precision
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
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()}

# Header dtype
Expand All @@ -100,7 +116,7 @@ def __init__(self, dtype, fileName):
fileName : str
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.fileName = fileName
self.initialized = False
Expand Down

0 comments on commit c472a48

Please sign in to comment.