From 43f6aa6846c776ec092ccb1b03086978a4875039 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 12 Oct 2016 23:34:06 +0200 Subject: [PATCH] added numpy test (minor): check that 'strides' is respected even when creating new arrays - This actually works with no changes, I just wasn't 100% convinced and decided to write a test to see if it's true. --- tests/test_numpy_array.cpp | 8 ++++++++ tests/test_numpy_array.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/test_numpy_array.cpp b/tests/test_numpy_array.cpp index 0614f5717..37a898367 100644 --- a/tests/test_numpy_array.cpp +++ b/tests/test_numpy_array.cpp @@ -91,4 +91,12 @@ test_initializer numpy_array([](py::module &m) { def_index_fn(mutate_data_t, arr_t&); def_index_fn(at_t, const arr_t&); def_index_fn(mutate_at_t, arr_t&); + + sm.def("make_f_array", [] { + return py::array_t({ 2, 2 }, { 4, 8 }); + }); + + sm.def("make_c_array", [] { + return py::array_t({ 2, 2 }, { 8, 4 }); + }); }); diff --git a/tests/test_numpy_array.py b/tests/test_numpy_array.py index 4a6af5ef6..85775e4f3 100644 --- a/tests/test_numpy_array.py +++ b/tests/test_numpy_array.py @@ -148,3 +148,13 @@ def test_bounds_check(arr): with pytest.raises(IndexError) as excinfo: index_at(arr, 0, 4) assert str(excinfo.value) == 'index 4 is out of bounds for axis 1 with size 3' + +@pytest.requires_numpy +def test_make_c_f_array(): + from pybind11_tests.array import ( + make_c_array, make_f_array + ) + assert make_c_array().flags.c_contiguous + assert not make_c_array().flags.f_contiguous + assert make_f_array().flags.f_contiguous + assert not make_f_array().flags.c_contiguous