From 5f06919385b409423e02cd605c93971669617481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20J=C3=A4ger?= Date: Fri, 26 Jun 2020 14:00:57 +0200 Subject: [PATCH 1/2] minor changes to work with EigenIterator, hotfixes, not stable --- CMakeLists.txt | 14 ++++++++++++++ matplotlibcpp.h | 25 +++++++++++++++++++------ matplotlibcpp.pc.in | 11 +++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 matplotlibcpp.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..7c53383b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.0.0) +project(matplotlibcpp VERSION 0.1 LANGUAGES CXX) + +find_package(Python3 COMPONENTS Development NumPy REQUIRED) +set(MATPLOTLIB_CPP_INCLUDE_DIRS ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) +set(MATPLOTLIB_CPP_DEPS Python3::Python Python3::NumPy) +set(MATPLOTLIB_CPP_DEST_DIR "${CMAKE_INSTALL_PREFIX}") +set(MATPLOTLIB_CPP_VERSION ${PROJECT_VERSION}) +set(MATPLOTLIB_CPP_CFLAGS) + +CONFIGURE_FILE("matplotlibcpp.pc.in" "matplotlibcpp.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matplotlibcpp.pc DESTINATION share/pkgconfig) +install(FILES matplotlibcpp.h DESTINATION include/matplotlibcpp) + diff --git a/matplotlibcpp.h b/matplotlibcpp.h index 67700740..c63ce69c 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -2321,18 +2321,23 @@ struct plot_impl using std::begin; using std::end; + detail::_interpreter::get(); + auto xs = distance(begin(x), end(x)); auto ys = distance(begin(y), end(y)); assert(xs == ys && "x and y data must have the same number of elements!"); - PyObject* xlist = PyList_New(xs); - PyObject* ylist = PyList_New(ys); + PyObject* xlist = PyList_New(static_cast(xs)); + PyObject* ylist = PyList_New(static_cast(ys)); PyObject* pystring = PyString_FromString(format.c_str()); auto itx = begin(x), ity = begin(y); for(size_t i = 0; i < xs; ++i) { - PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx++)); - PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity++)); + PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx)); + PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity)); + + ++itx; + ++ity; } PyObject* plot_args = PyTuple_New(3); @@ -2355,12 +2360,14 @@ struct plot_impl template bool operator()(const Iterable& ticks, const Callable& f, const std::string& format) { - if(begin(ticks) == end(ticks)) return true; + using std::cbegin; + using std::cend; + if(cbegin(ticks) == cend(ticks)) return true; // We could use additional meta-programming to deduce the correct element type of y, // but all values have to be convertible to double anyways std::vector y; - for(auto x : ticks) y.push_back(f(x)); + for(auto x = cbegin(ticks); x != cend(ticks); ++x) y.push_back(f(*x)); return plot_impl()(ticks,y,format); } }; @@ -2377,6 +2384,12 @@ bool plot(const A& a, const B& b, const std::string& format, Args... args) return detail::plot_impl::type>()(a,b,format) && plot(args...); } +template +bool plot_not_callable(const A& a, const B& b, const std::string& format, Args... args) +{ + return detail::plot_impl()(a,b,format) && plot(args...); +} + /* * This group of plot() functions is needed to support initializer lists, i.e. calling * plot( {1,2,3,4} ) diff --git a/matplotlibcpp.pc.in b/matplotlibcpp.pc.in new file mode 100644 index 00000000..59b06ad6 --- /dev/null +++ b/matplotlibcpp.pc.in @@ -0,0 +1,11 @@ +prefix=@MATPLOTLIB_CPP_DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: matplotlib-cpp +Description: Library for plotting in C++ using Python and Matplotlib +Version: @MATPLOTLIB_CPP_VERSION@ + +Libs: -L${libdir} @MATPLOTLIB_CPP_DEPS@ +Cflags: -I${includedir} @MATPLOTLIB_CPP_CFLAGS@ From f03ee78750180ed53d1602dbf7c03a1aed90f5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20J=C3=A4ger?= Date: Tue, 25 May 2021 13:11:27 +0200 Subject: [PATCH 2/2] removing incorrectly written dependency --- CMakeLists.txt | 8 +++++--- matplotlibcpp.pc.in | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c53383b..54b36848 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,15 @@ cmake_minimum_required(VERSION 3.0.0) project(matplotlibcpp VERSION 0.1 LANGUAGES CXX) -find_package(Python3 COMPONENTS Development NumPy REQUIRED) -set(MATPLOTLIB_CPP_INCLUDE_DIRS ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS}) -set(MATPLOTLIB_CPP_DEPS Python3::Python Python3::NumPy) + +set(MATPLOTLIB_CPP_DEPS "") set(MATPLOTLIB_CPP_DEST_DIR "${CMAKE_INSTALL_PREFIX}") set(MATPLOTLIB_CPP_VERSION ${PROJECT_VERSION}) set(MATPLOTLIB_CPP_CFLAGS) +string(REPLACE ";" " -l" MATPLOTLIB_CPP_DEPS_STR "${MATPLOTLIB_CPP_DEPS}") +string(REPLACE ";" " " MATPLOTLIB_CPP_CFLAGS_STR "${MATPLOTLIB_CPP_CFLAGS}") + CONFIGURE_FILE("matplotlibcpp.pc.in" "matplotlibcpp.pc" @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matplotlibcpp.pc DESTINATION share/pkgconfig) install(FILES matplotlibcpp.h DESTINATION include/matplotlibcpp) diff --git a/matplotlibcpp.pc.in b/matplotlibcpp.pc.in index 59b06ad6..4570085b 100644 --- a/matplotlibcpp.pc.in +++ b/matplotlibcpp.pc.in @@ -7,5 +7,5 @@ Name: matplotlib-cpp Description: Library for plotting in C++ using Python and Matplotlib Version: @MATPLOTLIB_CPP_VERSION@ -Libs: -L${libdir} @MATPLOTLIB_CPP_DEPS@ -Cflags: -I${includedir} @MATPLOTLIB_CPP_CFLAGS@ +Libs: -L${libdir} @MATPLOTLIB_CPP_DEPS_STR@ +Cflags: -I${includedir} @MATPLOTLIB_CPP_CFLAGS_STR@