Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use array ([T; N]) in python #51

Open
PigeonF opened this issue Apr 18, 2022 · 1 comment
Open

Cannot use array ([T; N]) in python #51

PigeonF opened this issue Apr 18, 2022 · 1 comment

Comments

@PigeonF
Copy link

PigeonF commented Apr 18, 2022

Hi!

First, thanks for the awesome project, it is very useful for plotting 馃憤 .

I am trying to use an array in inline_python, but it cannot be converted, because [T; N] does not implement ToPyObject.

let array = [0.0f64; 64];
inline_python::python! {
    a = 'array
};
Error Message
error[E0277]: the trait bound `[f64; 64]: ToPyObject` is not satisfied
   --> src\main.rs:69:13
    |
68  | /     inline_python::python! {
69  | |         a = 'array
    | |             ^^^^^^ the trait `ToPyObject` is not implemented for `[f64; 64]`
70  | |     };
    | |_____- required by a bound introduced by this call

One solution is to convert the array to a slice, but I think supporting to an array should still be supported.

While searching, I found https://github.com/PyO3/pyo3/blob/main/src/conversions/array.rs, which allows for conversion between arrays and python objects, but as far as I can tell, this is not picked up because it only implements IntoPy<PyObject> for [T; N], not ToPyObject.

Thus, I do not know if this is an issue with inline_python, or with PyO3. Since I am directly depending on inline_python I decided to open an issue here.

Maybe related: #10

@de-vri-es
Copy link
Contributor

de-vri-es commented Apr 18, 2022

Hey! Thanks for reporting the issue.

In this case, it can only be fixed by pyo3. We can not implement the ToPyObject trait for arrays in this crate.

It sounds like pyo3 is simply missing a impl ToPyObject for [T; N]. At a first glance, I don't see a reason why that trait wouldn't be possible to implement for arrays. It's probably just missing because nobody thought to add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants