test_buffers.cpp (11986:c12e4625ab56) | test_buffers.cpp (12037:d28054ac6ec9) |
---|---|
1/* 2 tests/test_buffers.cpp -- supporting Pythons' buffer protocol 3 4 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> 5 6 All rights reserved. Use of this source code is governed by a 7 BSD-style license that can be found in the LICENSE file. 8*/ --- 61 unchanged lines hidden (view full) --- 70 size_t cols() const { return m_cols; } 71private: 72 size_t m_rows; 73 size_t m_cols; 74 float *m_data; 75}; 76 77test_initializer buffers([](py::module &m) { | 1/* 2 tests/test_buffers.cpp -- supporting Pythons' buffer protocol 3 4 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> 5 6 All rights reserved. Use of this source code is governed by a 7 BSD-style license that can be found in the LICENSE file. 8*/ --- 61 unchanged lines hidden (view full) --- 70 size_t cols() const { return m_cols; } 71private: 72 size_t m_rows; 73 size_t m_cols; 74 float *m_data; 75}; 76 77test_initializer buffers([](py::module &m) { |
78 py::class_ | 78 py::class_<Matrix> mtx(m, "Matrix", py::buffer_protocol()); |
79 80 mtx.def(py::init<size_t, size_t>()) 81 /// Construct from a buffer 82 .def("__init__", [](Matrix &v, py::buffer b) { 83 py::buffer_info info = b.request(); 84 if (info.format != py::format_descriptor<float>::format() || info.ndim != 2) 85 throw std::runtime_error("Incompatible buffer format!"); 86 new (&v) Matrix(info.shape[0], info.shape[1]); --- 31 unchanged lines hidden --- | 79 80 mtx.def(py::init<size_t, size_t>()) 81 /// Construct from a buffer 82 .def("__init__", [](Matrix &v, py::buffer b) { 83 py::buffer_info info = b.request(); 84 if (info.format != py::format_descriptor<float>::format() || info.ndim != 2) 85 throw std::runtime_error("Incompatible buffer format!"); 86 new (&v) Matrix(info.shape[0], info.shape[1]); --- 31 unchanged lines hidden --- |