From 69bec844fd684005a7236646d5a57598d7195a61 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 2 Apr 2016 13:33:51 -0400 Subject: [PATCH] [Python] Fix setting composition using arrays with singleton dimensions --- interfaces/cython/cantera/test/test_thermo.py | 8 ++++++++ interfaces/cython/cantera/thermo.pyx | 1 + 2 files changed, 9 insertions(+) diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index beda40f49..d097188b9 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -112,6 +112,14 @@ class TestThermoPhase(utilities.CanteraTest): self.assertEqual(list(X), list(Y)) + def test_setComposition_singleton(self): + X = np.zeros((1,self.phase.n_species,1)) + X[0,2,0] = 1.0 + self.phase.X = X + Y = self.phase.Y + + self.assertEqual(list(X[0,:,0]), list(Y)) + def test_setCompositionString(self): self.phase.X = 'H2:1.0, O2:1.0' X = self.phase.X diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index ae50fddc0..953168e53 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -465,6 +465,7 @@ cdef class ThermoPhase(_SolutionBase): cdef void _setArray1(self, thermoMethod1d method, values) except *: cdef np.ndarray[np.double_t, ndim=1] data + values = np.squeeze(values) if len(values) == self.n_species: data = np.ascontiguousarray(values, dtype=np.double) elif len(values) == len(self._selected_species):