Skip to content

Commit

Permalink
Merge pull request #3767 from Icxolu/complex
Browse files Browse the repository at this point in the history
implement `PyComplexMethods`
  • Loading branch information
davidhewitt committed Jan 27, 2024
2 parents 796e419 + 37e2a4d commit ed7263f
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 78 deletions.
8 changes: 4 additions & 4 deletions guide/src/class/numeric.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ impl Number {
self.0 as f64
}

fn __complex__<'py>(&self, py: Python<'py>) -> &'py PyComplex {
PyComplex::from_doubles(py, self.0 as f64, 0.0)
fn __complex__<'py>(&self, py: Python<'py>) -> Bound<'py, PyComplex> {
PyComplex::from_doubles_bound(py, self.0 as f64, 0.0)
}
}
```
Expand Down Expand Up @@ -321,8 +321,8 @@ impl Number {
self.0 as f64
}

fn __complex__<'py>(&self, py: Python<'py>) -> &'py PyComplex {
PyComplex::from_doubles(py, self.0 as f64, 0.0)
fn __complex__<'py>(&self, py: Python<'py>) -> Bound<'py, PyComplex> {
PyComplex::from_doubles_bound(py, self.0 as f64, 0.0)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/conversions/num_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
//! #
//! # module.add_function(wrap_pyfunction!(get_eigenvalues, module)?)?;
//! #
//! # let m11 = PyComplex::from_doubles(py, 0_f64, -1_f64);
//! # let m12 = PyComplex::from_doubles(py, 1_f64, 0_f64);
//! # let m21 = PyComplex::from_doubles(py, 2_f64, -1_f64);
//! # let m22 = PyComplex::from_doubles(py, -1_f64, 0_f64);
//! # let m11 = PyComplex::from_doubles_bound(py, 0_f64, -1_f64);
//! # let m12 = PyComplex::from_doubles_bound(py, 1_f64, 0_f64);
//! # let m21 = PyComplex::from_doubles_bound(py, 2_f64, -1_f64);
//! # let m22 = PyComplex::from_doubles_bound(py, -1_f64, 0_f64);
//! #
//! # let result = module
//! # .getattr("get_eigenvalues")?
Expand Down
14 changes: 10 additions & 4 deletions src/tests/hygiene/pymethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ impl Dummy {
slf
}

fn __complex__<'py>(&self, py: crate::Python<'py>) -> &'py crate::types::PyComplex {
crate::types::PyComplex::from_doubles(py, 0.0, 0.0)
fn __complex__<'py>(
&self,
py: crate::Python<'py>,
) -> crate::Bound<'py, crate::types::PyComplex> {
crate::types::PyComplex::from_doubles_bound(py, 0.0, 0.0)
}

fn __int__(&self) -> u32 {
Expand Down Expand Up @@ -673,8 +676,11 @@ impl Dummy {
slf
}

fn __complex__<'py>(&self, py: crate::Python<'py>) -> &'py crate::types::PyComplex {
crate::types::PyComplex::from_doubles(py, 0.0, 0.0)
fn __complex__<'py>(
&self,
py: crate::Python<'py>,
) -> crate::Bound<'py, crate::types::PyComplex> {
crate::types::PyComplex::from_doubles_bound(py, 0.0, 0.0)
}

fn __int__(&self) -> u32 {
Expand Down

0 comments on commit ed7263f

Please sign in to comment.