Skip to content

Commit 0831756

Browse files
committed
Avoid increasing refcounts in Python where possible
1 parent ba11bbb commit 0831756

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

py-feos/src/ad/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type GradResult<'py> = (
5050
#[pyfunction]
5151
pub fn vapor_pressure_derivatives<'py>(
5252
model: PyEquationOfStateAD,
53-
parameter_names: Bound<'py, PyAny>,
53+
parameter_names: &Bound<'py, PyAny>,
5454
parameters: PyReadonlyArray2<f64>,
5555
input: PyReadonlyArray2<f64>,
5656
) -> GradResult<'py> {
@@ -76,7 +76,7 @@ pub fn vapor_pressure_derivatives<'py>(
7676
#[pyfunction]
7777
pub fn liquid_density_derivatives<'py>(
7878
model: PyEquationOfStateAD,
79-
parameter_names: Bound<'py, PyAny>,
79+
parameter_names: &Bound<'py, PyAny>,
8080
parameters: PyReadonlyArray2<f64>,
8181
input: PyReadonlyArray2<f64>,
8282
) -> GradResult<'py> {
@@ -102,7 +102,7 @@ pub fn liquid_density_derivatives<'py>(
102102
#[pyfunction]
103103
pub fn equilibrium_liquid_density_derivatives<'py>(
104104
model: PyEquationOfStateAD,
105-
parameter_names: Bound<'py, PyAny>,
105+
parameter_names: &Bound<'py, PyAny>,
106106
parameters: PyReadonlyArray2<f64>,
107107
input: PyReadonlyArray2<f64>,
108108
) -> GradResult<'py> {
@@ -129,7 +129,7 @@ pub fn equilibrium_liquid_density_derivatives<'py>(
129129
#[pyfunction]
130130
pub fn bubble_point_pressure_derivatives<'py>(
131131
model: PyEquationOfStateAD,
132-
parameter_names: Bound<'py, PyAny>,
132+
parameter_names: &Bound<'py, PyAny>,
133133
parameters: PyReadonlyArray2<f64>,
134134
input: PyReadonlyArray2<f64>,
135135
) -> GradResult<'py> {
@@ -156,7 +156,7 @@ pub fn bubble_point_pressure_derivatives<'py>(
156156
#[pyfunction]
157157
pub fn dew_point_pressure_derivatives<'py>(
158158
model: PyEquationOfStateAD,
159-
parameter_names: Bound<'py, PyAny>,
159+
parameter_names: &Bound<'py, PyAny>,
160160
parameters: PyReadonlyArray2<f64>,
161161
input: PyReadonlyArray2<f64>,
162162
) -> GradResult<'py> {
@@ -169,7 +169,7 @@ macro_rules! expand_models {
169169
#[pyfunction]
170170
fn [<_ $prop _derivatives>]<'py>(
171171
model: PyEquationOfStateAD,
172-
parameter_names: Bound<'py, PyAny>,
172+
parameter_names: &Bound<'py, PyAny>,
173173
parameters: PyReadonlyArray2<f64>,
174174
input: PyReadonlyArray2<f64>,
175175
) -> GradResult<'py> {
@@ -194,7 +194,7 @@ macro_rules! impl_evaluate_gradients {
194194
expand_models!($enum, $prop, $($model: $type),*);
195195
paste!(
196196
fn $prop<'py, R: ParametersAD<$n>>(
197-
parameter_names: Bound<'py, PyAny>,
197+
parameter_names: &Bound<'py, PyAny>,
198198
parameters: PyReadonlyArray2<f64>,
199199
input: PyReadonlyArray2<f64>,
200200
) -> (

py-feos/src/dft/adsorption/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ macro_rules! impl_adsorption_isotherm {
6262
temperature: Temperature,
6363
pressure: Pressure<Array1<f64>>,
6464
pore: &$py_pore,
65-
composition: Option<Bound<'_, PyAny>>,
65+
composition: Option<&Bound<'_, PyAny>>,
6666
solver: Option<PyDFTSolver>,
6767
) -> PyResult<Self> {
6868
Ok(Self(Adsorption::adsorption_isotherm(
@@ -106,7 +106,7 @@ macro_rules! impl_adsorption_isotherm {
106106
temperature: Temperature,
107107
pressure: Pressure<Array1<f64>>,
108108
pore: &$py_pore,
109-
composition: Option<Bound<'_, PyAny>>,
109+
composition: Option<&Bound<'_, PyAny>>,
110110
solver: Option<PyDFTSolver>,
111111
) -> PyResult<Self> {
112112
Ok(Self(Adsorption::desorption_isotherm(
@@ -153,7 +153,7 @@ macro_rules! impl_adsorption_isotherm {
153153
temperature: Temperature,
154154
pressure: Pressure<Array1<f64>>,
155155
pore: &$py_pore,
156-
composition: Option<Bound<'_, PyAny>>,
156+
composition: Option<&Bound<'_, PyAny>>,
157157
solver: Option<PyDFTSolver>,
158158
) -> PyResult<Self> {
159159
Ok(Self(Adsorption::equilibrium_isotherm(
@@ -205,7 +205,7 @@ macro_rules! impl_adsorption_isotherm {
205205
p_min: Pressure,
206206
p_max: Pressure,
207207
pore: &$py_pore,
208-
composition: Option<Bound<'_, PyAny>>,
208+
composition: Option<&Bound<'_, PyAny>>,
209209
solver: Option<PyDFTSolver>,
210210
max_iter: Option<usize>,
211211
tol: Option<f64>,

py-feos/src/eos/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl PyEquationOfState {
6565
/// -------
6666
/// SINumber
6767
#[pyo3(text_signature = "(composition=None)", signature = (composition=None))]
68-
fn max_density(&self, composition: Option<Bound<'_, PyAny>>) -> PyResult<Density> {
68+
fn max_density(&self, composition: Option<&Bound<'_, PyAny>>) -> PyResult<Density> {
6969
Ok(self
7070
.0
7171
.max_density(Compositions::try_from(composition)?)
@@ -88,7 +88,7 @@ impl PyEquationOfState {
8888
fn second_virial_coefficient(
8989
&self,
9090
temperature: Temperature,
91-
composition: Option<Bound<'_, PyAny>>,
91+
composition: Option<&Bound<'_, PyAny>>,
9292
) -> PyResult<Quot<f64, Density>> {
9393
Ok(self
9494
.0
@@ -112,7 +112,7 @@ impl PyEquationOfState {
112112
fn third_virial_coefficient(
113113
&self,
114114
temperature: Temperature,
115-
composition: Option<Bound<'_, PyAny>>,
115+
composition: Option<&Bound<'_, PyAny>>,
116116
) -> PyResult<Quot<Quot<f64, Density>, Density>> {
117117
Ok(self
118118
.0
@@ -137,7 +137,7 @@ impl PyEquationOfState {
137137
fn second_virial_coefficient_temperature_derivative(
138138
&self,
139139
temperature: Temperature,
140-
composition: Option<Bound<'_, PyAny>>,
140+
composition: Option<&Bound<'_, PyAny>>,
141141
) -> PyResult<Quot<Quot<f64, Density>, Temperature>> {
142142
Ok(self
143143
.0
@@ -166,7 +166,7 @@ impl PyEquationOfState {
166166
fn third_virial_coefficient_temperature_derivative(
167167
&self,
168168
temperature: Temperature,
169-
composition: Option<Bound<'_, PyAny>>,
169+
composition: Option<&Bound<'_, PyAny>>,
170170
) -> PyResult<Quot<Quot<Quot<f64, Density>, Density>, Temperature>> {
171171
Ok(self
172172
.0
@@ -237,9 +237,9 @@ impl Composition<f64, Dyn> for Compositions {
237237
}
238238
}
239239

240-
impl TryFrom<Option<Bound<'_, PyAny>>> for Compositions {
240+
impl TryFrom<Option<&Bound<'_, PyAny>>> for Compositions {
241241
type Error = PyErr;
242-
fn try_from(composition: Option<Bound<'_, PyAny>>) -> PyResult<Compositions> {
242+
fn try_from(composition: Option<&Bound<'_, PyAny>>) -> PyResult<Compositions> {
243243
let Some(composition) = composition else {
244244
return Ok(Compositions::None);
245245
};

py-feos/src/phase_equilibria.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl PyPhaseEquilibrium {
6161
#[pyo3(signature = (eos, temperature_or_pressure, initial_state=None, max_iter=None, tol=None, verbosity=None))]
6262
pub(crate) fn pure(
6363
eos: &PyEquationOfState,
64-
temperature_or_pressure: Bound<'_, PyAny>,
64+
temperature_or_pressure: &Bound<'_, PyAny>,
6565
initial_state: Option<&PyPhaseEquilibrium>,
6666
max_iter: Option<usize>,
6767
tol: Option<f64>,
@@ -198,9 +198,9 @@ impl PyPhaseEquilibrium {
198198
#[expect(clippy::too_many_arguments)]
199199
pub(crate) fn bubble_point<'py>(
200200
eos: &PyEquationOfState,
201-
temperature_or_pressure: Bound<'_, PyAny>,
201+
temperature_or_pressure: &Bound<'_, PyAny>,
202202
liquid_molefracs: PyReadonlyArray1<'py, f64>,
203-
tp_init: Option<Bound<'_, PyAny>>,
203+
tp_init: Option<&Bound<'_, PyAny>>,
204204
vapor_molefracs: Option<PyReadonlyArray1<'py, f64>>,
205205
max_iter_inner: Option<usize>,
206206
max_iter_outer: Option<usize>,
@@ -286,9 +286,9 @@ impl PyPhaseEquilibrium {
286286
#[expect(clippy::too_many_arguments)]
287287
pub(crate) fn dew_point<'py>(
288288
eos: &PyEquationOfState,
289-
temperature_or_pressure: Bound<'_, PyAny>,
289+
temperature_or_pressure: &Bound<'_, PyAny>,
290290
vapor_molefracs: PyReadonlyArray1<'py, f64>,
291-
tp_init: Option<Bound<'_, PyAny>>,
291+
tp_init: Option<&Bound<'_, PyAny>>,
292292
liquid_molefracs: Option<PyReadonlyArray1<'py, f64>>,
293293
max_iter_inner: Option<usize>,
294294
max_iter_outer: Option<usize>,
@@ -398,7 +398,7 @@ impl PyPhaseEquilibrium {
398398
#[staticmethod]
399399
fn vle_pure_comps(
400400
eos: &PyEquationOfState,
401-
temperature_or_pressure: Bound<'_, PyAny>,
401+
temperature_or_pressure: &Bound<'_, PyAny>,
402402
) -> PyResult<Vec<Option<Self>>> {
403403
if let Ok(t) = temperature_or_pressure.extract::<Temperature>() {
404404
Ok(PhaseEquilibrium::vle_pure_comps(&eos.0, t)
@@ -514,9 +514,9 @@ impl PyPhaseEquilibrium {
514514
#[expect(clippy::too_many_arguments)]
515515
fn heteroazeotrope(
516516
eos: &PyEquationOfState,
517-
temperature_or_pressure: Bound<'_, PyAny>,
517+
temperature_or_pressure: &Bound<'_, PyAny>,
518518
x_init: (f64, f64),
519-
tp_init: Option<Bound<'_, PyAny>>,
519+
tp_init: Option<&Bound<'_, PyAny>>,
520520
max_iter: Option<usize>,
521521
tol: Option<f64>,
522522
verbosity: Option<PyVerbosity>,
@@ -1224,7 +1224,7 @@ impl PyPhaseDiagram {
12241224
#[expect(clippy::too_many_arguments)]
12251225
pub(crate) fn binary_vle(
12261226
eos: &PyEquationOfState,
1227-
temperature_or_pressure: Bound<'_, PyAny>,
1227+
temperature_or_pressure: &Bound<'_, PyAny>,
12281228
npoints: Option<usize>,
12291229
x_lle: Option<(f64, f64)>,
12301230
max_iter_inner: Option<usize>,
@@ -1299,7 +1299,7 @@ impl PyPhaseDiagram {
12991299
#[pyo3(signature = (eos, temperature_or_pressure, feed, min_tp, max_tp, npoints=None))]
13001300
pub(crate) fn lle(
13011301
eos: &PyEquationOfState,
1302-
temperature_or_pressure: Bound<'_, PyAny>,
1302+
temperature_or_pressure: &Bound<'_, PyAny>,
13031303
feed: Moles<DVector<f64>>,
13041304
min_tp: Bound<'_, PyAny>,
13051305
max_tp: Bound<'_, PyAny>,
@@ -1388,10 +1388,10 @@ impl PyPhaseDiagram {
13881388
#[expect(clippy::too_many_arguments)]
13891389
pub(crate) fn binary_vlle(
13901390
eos: &PyEquationOfState,
1391-
temperature_or_pressure: Bound<'_, PyAny>,
1391+
temperature_or_pressure: &Bound<'_, PyAny>,
13921392
x_lle: (f64, f64),
1393-
tp_lim_lle: Option<Bound<'_, PyAny>>,
1394-
tp_init_vlle: Option<Bound<'_, PyAny>>,
1393+
tp_lim_lle: Option<&Bound<'_, PyAny>>,
1394+
tp_init_vlle: Option<&Bound<'_, PyAny>>,
13951395
npoints_vle: Option<usize>,
13961396
npoints_lle: Option<usize>,
13971397
max_iter_inner: Option<usize>,

py-feos/src/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl PyState {
111111
temperature: Option<Temperature>,
112112
volume: Option<Volume>,
113113
density: Option<Density>,
114-
composition: Option<Bound<'py, PyAny>>,
114+
composition: Option<&Bound<'py, PyAny>>,
115115
pressure: Option<Pressure>,
116116
molar_enthalpy: Option<MolarEnergy>,
117117
molar_entropy: Option<MolarEntropy>,
@@ -225,7 +225,7 @@ impl PyState {
225225
#[pyo3(signature = (eos, composition=None, initial_temperature=None, initial_density=None, max_iter=None, tol=None, verbosity=None))]
226226
fn critical_point<'py>(
227227
eos: &PyEquationOfState,
228-
composition: Option<Bound<'py, PyAny>>,
228+
composition: Option<&Bound<'py, PyAny>>,
229229
initial_temperature: Option<Temperature>,
230230
initial_density: Option<Density>,
231231
max_iter: Option<usize>,
@@ -274,7 +274,7 @@ impl PyState {
274274
#[expect(clippy::too_many_arguments)]
275275
fn critical_point_binary(
276276
eos: &PyEquationOfState,
277-
temperature_or_pressure: Bound<'_, PyAny>,
277+
temperature_or_pressure: &Bound<'_, PyAny>,
278278
initial_temperature: Option<Temperature>,
279279
initial_molefracs: Option<[f64; 2]>,
280280
initial_density: Option<Density>,
@@ -346,7 +346,7 @@ impl PyState {
346346
fn spinodal<'py>(
347347
eos: &PyEquationOfState,
348348
temperature: Temperature,
349-
composition: Option<Bound<'py, PyAny>>,
349+
composition: Option<&Bound<'py, PyAny>>,
350350
max_iter: Option<usize>,
351351
tol: Option<f64>,
352352
verbosity: Option<PyVerbosity>,

0 commit comments

Comments
 (0)