Skip to content

PyArray::to_owned_array() panics for reversed array #151

Closed
@hombit

Description

@hombit
use numpy;
use pyo3::types::IntoPyDict;

fn main() {
    let gil = pyo3::Python::acquire_gil();
    let py = gil.python();
    let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py);
    let not_contiguous: &numpy::PyArray1<f32> = py
        .eval("np.zeros(2)[::-1]", Some(locals), None)
        .unwrap()
        .downcast()
        .unwrap();
    let _owned = not_contiguous.to_owned_array();
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ShapeError/Overflow: arithmetic overflow', /Users/hombit/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.13.1/src/impl_raw_views.rs:75:13
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::option::expect_none_failed
   9: core::result::Result<T,E>::unwrap
  10: ndarray::impl_raw_views::<impl ndarray::ArrayBase<ndarray::RawViewRepr<*const A>,D>>::from_shape_ptr
  11: ndarray::impl_views::constructors::<impl ndarray::ArrayBase<ndarray::ViewRepr<&A>,D>>::from_shape_ptr
  12: numpy::array::PyArray<T,D>::as_array
  13: numpy::array::PyArray<T,D>::to_owned_array
  14: pyo3_panics::main
  15: std::rt::lang_start::{{closure}}
  16: std::rt::lang_start_internal
  17: std::rt::lang_start
  18: main

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions