Skip to content

Commit

Permalink
Numpy 2.x support (#245)
Browse files Browse the repository at this point in the history
jschueller authored Jun 20, 2024
1 parent 95d4d50 commit 8c018ef
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
python-version: '3.9.x'
- name: Setup Python
run: |
python3 -m pip install Cython "numpy<2" scipy matplotlib nose-py3 setuptools==69.1.0
python3 -m pip install Cython numpy scipy matplotlib nose-py3 setuptools==69.1.0
- name: Install system
run: |
sudo apt-get -y install cmake liblapack-dev libsuitesparse-dev libhypre-dev
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
--- CHANGELOG ---

--- PyFMI-2.13.1 ---
* Numpy 2.x support

--- PyFMI-2.13.0 ---
* Upgraded to Cython3.

2 changes: 1 addition & 1 deletion src/common/io.py
Original file line number Diff line number Diff line change
@@ -2442,7 +2442,7 @@ def __write_header(self, header, name):
Dumps the header and name to file.
"""
self._file.write(header.tobytes(order="F"))
self._file.write(np.compat.asbytes(name +"\0"))
self._file.write(name.encode() + b"\0")

def _write_header(self, name, nbr_rows, nbr_cols, data_type):
"""
16 changes: 8 additions & 8 deletions src/pyfmi/fmi.pyx
Original file line number Diff line number Diff line change
@@ -1542,7 +1542,7 @@ cdef class FMUModelBase(ModelBase):
Calls the low-level FMI function: fmiGetReal
"""
cdef int status
cdef np.ndarray[FMIL.fmi1_value_reference_t, ndim=1,mode='c'] val_ref = np.array(valueref, copy=False, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi1_value_reference_t, ndim=1,mode='c'] val_ref = np.asarray(valueref, dtype=np.uint32).ravel()
cdef FMIL.size_t nref = np.size(val_ref)
cdef np.ndarray[FMIL.fmi1_real_t, ndim=1,mode='c'] val = np.array([0.0]*nref, dtype=float, ndmin=1)

@@ -1575,8 +1575,8 @@ cdef class FMUModelBase(ModelBase):
Calls the low-level FMI function: fmiSetReal
"""
cdef int status
cdef np.ndarray[FMIL.fmi1_value_reference_t, ndim=1,mode='c'] val_ref = np.array(valueref, copy=False, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi1_real_t, ndim=1,mode='c'] val = np.array(values, copy=False, dtype=float).ravel()
cdef np.ndarray[FMIL.fmi1_value_reference_t, ndim=1,mode='c'] val_ref = np.asarray(valueref, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi1_real_t, ndim=1,mode='c'] val = np.asarray(values, dtype=float).ravel()
cdef FMIL.size_t nref = np.size(val_ref)

if nref != np.size(val):
@@ -4187,7 +4187,7 @@ cdef class FMUModelBase2(ModelBase):
Calls the low-level FMI function: fmi2GetReal
"""
cdef int status
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1,mode='c'] input_valueref = np.array(valueref, copy=False, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1,mode='c'] input_valueref = np.asarray(valueref, dtype=np.uint32).ravel()
cdef FMIL.size_t nref = np.size(input_valueref)
cdef np.ndarray[FMIL.fmi2_real_t, ndim=1,mode='c'] output_value = np.zeros(nref)

@@ -4221,8 +4221,8 @@ cdef class FMUModelBase2(ModelBase):
"""
cdef int status

cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1,mode='c'] input_valueref = np.array(valueref, copy=False, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi2_real_t, ndim=1,mode='c'] set_value = np.array(values, copy=False, dtype=float).ravel()
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1,mode='c'] input_valueref = np.asarray(valueref, dtype=np.uint32).ravel()
cdef np.ndarray[FMIL.fmi2_real_t, ndim=1,mode='c'] set_value = np.asarray(values, dtype=float).ravel()

if np.size(input_valueref) != np.size(set_value):
raise FMUException('The length of valueref and values are inconsistent.')
@@ -8237,8 +8237,8 @@ cdef class FMUModelME2(FMUModelBase2):
cdef int method = FORWARD_DIFFERENCE if self.force_finite_differences is True or self.force_finite_differences == 0 else CENTRAL_DIFFERENCE
cdef double RUROUND = FORWARD_DIFFERENCE_EPS if method == FORWARD_DIFFERENCE else CENTRAL_DIFFERENCE_EPS
cdef np.ndarray[FMIL.fmi2_real_t, ndim=1, mode='c'] dfpert, df, eps, nominals
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1, mode='c'] v_ref = np.array(var_ref, copy=False, dtype = np.uint32)
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1, mode='c'] z_ref = np.array(func_ref, copy=False, dtype = np.uint32)
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1, mode='c'] v_ref = np.asarray(var_ref, dtype=np.uint32)
cdef np.ndarray[FMIL.fmi2_value_reference_t, ndim=1, mode='c'] z_ref = np.asarray(func_ref, dtype=np.uint32)
cdef int ind_local = 5 if add_diag else 4
cdef list local_group

0 comments on commit 8c018ef

Please sign in to comment.