Skip to content

Commit 5f06919

Browse files
author
Georg Jäger
committed
minor changes to work with EigenIterator, hotfixes, not stable
1 parent 7d0e695 commit 5f06919

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
project(matplotlibcpp VERSION 0.1 LANGUAGES CXX)
3+
4+
find_package(Python3 COMPONENTS Development NumPy REQUIRED)
5+
set(MATPLOTLIB_CPP_INCLUDE_DIRS ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})
6+
set(MATPLOTLIB_CPP_DEPS Python3::Python Python3::NumPy)
7+
set(MATPLOTLIB_CPP_DEST_DIR "${CMAKE_INSTALL_PREFIX}")
8+
set(MATPLOTLIB_CPP_VERSION ${PROJECT_VERSION})
9+
set(MATPLOTLIB_CPP_CFLAGS)
10+
11+
CONFIGURE_FILE("matplotlibcpp.pc.in" "matplotlibcpp.pc" @ONLY)
12+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matplotlibcpp.pc DESTINATION share/pkgconfig)
13+
install(FILES matplotlibcpp.h DESTINATION include/matplotlibcpp)
14+

matplotlibcpp.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,18 +2321,23 @@ struct plot_impl<std::false_type>
23212321
using std::begin;
23222322
using std::end;
23232323

2324+
detail::_interpreter::get();
2325+
23242326
auto xs = distance(begin(x), end(x));
23252327
auto ys = distance(begin(y), end(y));
23262328
assert(xs == ys && "x and y data must have the same number of elements!");
23272329

2328-
PyObject* xlist = PyList_New(xs);
2329-
PyObject* ylist = PyList_New(ys);
2330+
PyObject* xlist = PyList_New(static_cast<Py_ssize_t>(xs));
2331+
PyObject* ylist = PyList_New(static_cast<Py_ssize_t>(ys));
23302332
PyObject* pystring = PyString_FromString(format.c_str());
23312333

23322334
auto itx = begin(x), ity = begin(y);
23332335
for(size_t i = 0; i < xs; ++i) {
2334-
PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx++));
2335-
PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity++));
2336+
PyList_SetItem(xlist, i, PyFloat_FromDouble(*itx));
2337+
PyList_SetItem(ylist, i, PyFloat_FromDouble(*ity));
2338+
2339+
++itx;
2340+
++ity;
23362341
}
23372342

23382343
PyObject* plot_args = PyTuple_New(3);
@@ -2355,12 +2360,14 @@ struct plot_impl<std::true_type>
23552360
template<typename Iterable, typename Callable>
23562361
bool operator()(const Iterable& ticks, const Callable& f, const std::string& format)
23572362
{
2358-
if(begin(ticks) == end(ticks)) return true;
2363+
using std::cbegin;
2364+
using std::cend;
2365+
if(cbegin(ticks) == cend(ticks)) return true;
23592366

23602367
// We could use additional meta-programming to deduce the correct element type of y,
23612368
// but all values have to be convertible to double anyways
23622369
std::vector<double> y;
2363-
for(auto x : ticks) y.push_back(f(x));
2370+
for(auto x = cbegin(ticks); x != cend(ticks); ++x) y.push_back(f(*x));
23642371
return plot_impl<std::false_type>()(ticks,y,format);
23652372
}
23662373
};
@@ -2377,6 +2384,12 @@ bool plot(const A& a, const B& b, const std::string& format, Args... args)
23772384
return detail::plot_impl<typename detail::is_callable<B>::type>()(a,b,format) && plot(args...);
23782385
}
23792386

2387+
template<typename A, typename B, typename... Args>
2388+
bool plot_not_callable(const A& a, const B& b, const std::string& format, Args... args)
2389+
{
2390+
return detail::plot_impl<std::false_type>()(a,b,format) && plot(args...);
2391+
}
2392+
23802393
/*
23812394
* This group of plot() functions is needed to support initializer lists, i.e. calling
23822395
* plot( {1,2,3,4} )

matplotlibcpp.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@MATPLOTLIB_CPP_DEST_DIR@
2+
exec_prefix=${prefix}
3+
libdir=${prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: matplotlib-cpp
7+
Description: Library for plotting in C++ using Python and Matplotlib
8+
Version: @MATPLOTLIB_CPP_VERSION@
9+
10+
Libs: -L${libdir} @MATPLOTLIB_CPP_DEPS@
11+
Cflags: -I${includedir} @MATPLOTLIB_CPP_CFLAGS@

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy