44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""!
|
|
Author: J.A. de Jong - ASCEE
|
|
|
|
Description: LASP configuration
|
|
"""
|
|
import numpy as np
|
|
from .lasp_cpp import LASP_DOUBLE_PRECISION
|
|
|
|
if LASP_DOUBLE_PRECISION:
|
|
LASP_NUMPY_FLOAT_TYPE = np.float64
|
|
LASP_NUMPY_COMPLEX_TYPE = np.complex128
|
|
else:
|
|
LASP_NUMPY_FLOAT_TYPE = np.float32
|
|
LASP_NUMPY_COMPLEX_TYPE = np.float64
|
|
|
|
|
|
def zeros(shape, dtype=float, order='F'):
|
|
if dtype == float:
|
|
return np.zeros(shape, dtype=LASP_NUMPY_FLOAT_TYPE, order=order)
|
|
elif dtype == complex:
|
|
return np.zeros(shape, dtype=LASP_NUMPY_COMPLEX_TYPE, order=order)
|
|
else:
|
|
raise RuntimeError(f"Unknown dtype: {dtype}")
|
|
|
|
|
|
def ones(shape, dtype=float, order='F'):
|
|
if dtype == float:
|
|
return np.ones(shape, dtype=LASP_NUMPY_FLOAT_TYPE, order=order)
|
|
elif dtype == complex:
|
|
return np.ones(shape, dtype=LASP_NUMPY_COMPLEX_TYPE, order=order)
|
|
else:
|
|
raise RuntimeError(f"Unknown dtype: {dtype}")
|
|
|
|
def empty(shape, dtype=float, order='F'):
|
|
if dtype == float:
|
|
return np.empty(shape, dtype=LASP_NUMPY_FLOAT_TYPE, order=order)
|
|
elif dtype == complex:
|
|
return np.empty(shape, dtype=LASP_NUMPY_COMPLEX_TYPE, order=order)
|
|
else:
|
|
raise RuntimeError(f"Unknown dtype: {dtype}")
|
|
|