Skip to content

Commit a6c0f7c

Browse files
William LeongWilliam Leong
authored andcommitted
Merge remote-tracking branch 'lindemeier/master'
2 parents ef0383f + 7566e3d commit a6c0f7c

File tree

3 files changed

+92
-82
lines changed

3 files changed

+92
-82
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@
3636

3737
# vim temp files
3838
*.sw*
39+
40+
build/*

CMakeLists.txt

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(PACKAGE_NAME matplotlib_cpp)
66
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake)
77

88

9+
option(BUILD_EXAMPLES "Build examples" OFF)
10+
911
# Library target
1012
add_library(matplotlib_cpp INTERFACE)
1113
target_include_directories(matplotlib_cpp
@@ -36,72 +38,73 @@ install(
3638
)
3739

3840

39-
# Examples
40-
add_executable(minimal examples/minimal.cpp)
41-
target_link_libraries(minimal PRIVATE matplotlib_cpp)
42-
set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
43-
44-
add_executable(basic examples/basic.cpp)
45-
target_link_libraries(basic PRIVATE matplotlib_cpp)
46-
set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
47-
48-
add_executable(modern examples/modern.cpp)
49-
target_link_libraries(modern PRIVATE matplotlib_cpp)
50-
set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
51-
52-
add_executable(animation examples/animation.cpp)
53-
target_link_libraries(animation PRIVATE matplotlib_cpp)
54-
set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
55-
56-
add_executable(nonblock examples/nonblock.cpp)
57-
target_link_libraries(nonblock PRIVATE matplotlib_cpp)
58-
set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
59-
60-
add_executable(xkcd examples/xkcd.cpp)
61-
target_link_libraries(xkcd PRIVATE matplotlib_cpp)
62-
set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
63-
64-
add_executable(bar examples/bar.cpp)
65-
target_link_libraries(bar PRIVATE matplotlib_cpp)
66-
set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
67-
68-
add_executable(fill_inbetween examples/fill_inbetween.cpp)
69-
target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
70-
set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
71-
72-
add_executable(fill examples/fill.cpp)
73-
target_link_libraries(fill PRIVATE matplotlib_cpp)
74-
set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
75-
76-
add_executable(update examples/update.cpp)
77-
target_link_libraries(update PRIVATE matplotlib_cpp)
78-
set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
79-
80-
add_executable(subplot2grid examples/subplot2grid.cpp)
81-
target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
82-
set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
83-
84-
add_executable(lines3d examples/lines3d.cpp)
85-
target_link_libraries(lines3d PRIVATE matplotlib_cpp)
86-
set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
87-
88-
if(Python3_NumPy_FOUND)
89-
add_executable(surface examples/surface.cpp)
90-
target_link_libraries(surface PRIVATE matplotlib_cpp)
91-
set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
92-
93-
add_executable(colorbar examples/colorbar.cpp)
94-
target_link_libraries(colorbar PRIVATE matplotlib_cpp)
95-
set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
96-
add_executable(contour examples/contour.cpp)
97-
target_link_libraries(contour PRIVATE matplotlib_cpp)
98-
set_target_properties(contour PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
99-
100-
add_executable(spy examples/spy.cpp)
101-
target_link_libraries(spy PRIVATE matplotlib_cpp)
102-
set_target_properties(spy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
103-
endif()
104-
41+
if(BUILD_EXAMPLES)
42+
# Examples
43+
add_executable(minimal examples/minimal.cpp)
44+
target_link_libraries(minimal PRIVATE matplotlib_cpp)
45+
set_target_properties(minimal PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
46+
47+
add_executable(basic examples/basic.cpp)
48+
target_link_libraries(basic PRIVATE matplotlib_cpp)
49+
set_target_properties(basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
50+
51+
add_executable(modern examples/modern.cpp)
52+
target_link_libraries(modern PRIVATE matplotlib_cpp)
53+
set_target_properties(modern PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
54+
55+
add_executable(animation examples/animation.cpp)
56+
target_link_libraries(animation PRIVATE matplotlib_cpp)
57+
set_target_properties(animation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
58+
59+
add_executable(nonblock examples/nonblock.cpp)
60+
target_link_libraries(nonblock PRIVATE matplotlib_cpp)
61+
set_target_properties(nonblock PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
62+
63+
add_executable(xkcd examples/xkcd.cpp)
64+
target_link_libraries(xkcd PRIVATE matplotlib_cpp)
65+
set_target_properties(xkcd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
66+
67+
add_executable(bar examples/bar.cpp)
68+
target_link_libraries(bar PRIVATE matplotlib_cpp)
69+
set_target_properties(bar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
70+
71+
add_executable(fill_inbetween examples/fill_inbetween.cpp)
72+
target_link_libraries(fill_inbetween PRIVATE matplotlib_cpp)
73+
set_target_properties(fill_inbetween PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
74+
75+
add_executable(fill examples/fill.cpp)
76+
target_link_libraries(fill PRIVATE matplotlib_cpp)
77+
set_target_properties(fill PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
78+
79+
add_executable(update examples/update.cpp)
80+
target_link_libraries(update PRIVATE matplotlib_cpp)
81+
set_target_properties(update PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
82+
83+
add_executable(subplot2grid examples/subplot2grid.cpp)
84+
target_link_libraries(subplot2grid PRIVATE matplotlib_cpp)
85+
set_target_properties(subplot2grid PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
86+
87+
add_executable(lines3d examples/lines3d.cpp)
88+
target_link_libraries(lines3d PRIVATE matplotlib_cpp)
89+
set_target_properties(lines3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
90+
91+
if(Python3_NumPy_FOUND)
92+
add_executable(surface examples/surface.cpp)
93+
target_link_libraries(surface PRIVATE matplotlib_cpp)
94+
set_target_properties(surface PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
95+
96+
add_executable(colorbar examples/colorbar.cpp)
97+
target_link_libraries(colorbar PRIVATE matplotlib_cpp)
98+
set_target_properties(colorbar PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
99+
add_executable(contour examples/contour.cpp)
100+
target_link_libraries(contour PRIVATE matplotlib_cpp)
101+
set_target_properties(contour PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
102+
103+
add_executable(spy examples/spy.cpp)
104+
target_link_libraries(spy PRIVATE matplotlib_cpp)
105+
set_target_properties(spy PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
106+
endif()
107+
endif(BUILD_EXAMPLES)
105108

106109
# Install headers
107110
install(FILES

matplotlibcpp.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,19 @@ template <> struct select_npy_type<uint16_t> { const static NPY_TYPES type = NPY
348348
template <> struct select_npy_type<uint32_t> { const static NPY_TYPES type = NPY_ULONG; };
349349
template <> struct select_npy_type<uint64_t> { const static NPY_TYPES type = NPY_UINT64; };
350350

351-
// Sanity checks; comment them out or change the numpy type below if you're compiling on
352-
// a platform where they don't apply
353-
static_assert(sizeof(long long) == 8);
354-
template <> struct select_npy_type<long long> { const static NPY_TYPES type = NPY_INT64; };
355-
static_assert(sizeof(unsigned long long) == 8);
356-
template <> struct select_npy_type<unsigned long long> { const static NPY_TYPES type = NPY_UINT64; };
357-
351+
#ifndef DISABLE_TYPE_SIZE_SANITY_CHECK
352+
// Sanity checks; comment them out or change the numpy type below if you're
353+
// compiling on a platform where they don't apply
354+
static_assert(sizeof(long long) == 8, "size check failed");
355+
template <> struct select_npy_type<long long> {
356+
const static NPY_TYPES type = NPY_INT64;
357+
};
358+
static_assert(sizeof(unsigned long long) == 8, "size check failed");
359+
template <> struct select_npy_type<unsigned long long> {
360+
const static NPY_TYPES type = NPY_UINT64;
361+
};
362+
#endif
363+
358364
template<typename Numeric>
359365
PyObject* get_array(const std::vector<Numeric>& v)
360366
{
@@ -1057,8 +1063,7 @@ template<typename NumericX, typename NumericY, typename NumericColors>
10571063
if(res) Py_DECREF(res);
10581064

10591065
return res;
1060-
}
1061-
1066+
}
10621067

10631068
template<typename NumericX, typename NumericY, typename NumericZ>
10641069
bool scatter(const std::vector<NumericX>& x,
@@ -1069,9 +1074,9 @@ bool scatter(const std::vector<NumericX>& x,
10691074
const long fig_number=0) {
10701075
detail::_interpreter::get();
10711076

1072-
// Same as with plot_surface: We lazily load the modules here the first time
1073-
// this function is called because I'm not sure that we can assume "matplotlib
1074-
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
1077+
// Same as with plot_surface: We lazily load the modules here the first time
1078+
// this function is called because I'm not sure that we can assume "matplotlib
1079+
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
10751080
// want to require it for people who don't need 3d plots.
10761081
static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
10771082
if (!mpl_toolkitsmod) {
@@ -1468,7 +1473,7 @@ bool quiver(const std::vector<NumericX>& x, const std::vector<NumericY>& y, cons
14681473
Py_DECREF(axis3d);
14691474
if (!axis3dmod) { throw std::runtime_error("Error loading module mpl_toolkits.mplot3d!"); }
14701475
}
1471-
1476+
14721477
//assert sizes match up
14731478
assert(x.size() == y.size() && x.size() == u.size() && u.size() == w.size() && x.size() == z.size() && x.size() == v.size() && u.size() == v.size());
14741479

@@ -1496,7 +1501,7 @@ bool quiver(const std::vector<NumericX>& x, const std::vector<NumericY>& y, cons
14961501
{
14971502
PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
14981503
}
1499-
1504+
15001505
//get figure gca to enable 3d projection
15011506
PyObject *fig =
15021507
PyObject_CallObject(detail::_interpreter::get().s_python_function_figure,
@@ -1516,7 +1521,7 @@ bool quiver(const std::vector<NumericX>& x, const std::vector<NumericY>& y, cons
15161521
Py_INCREF(axis);
15171522
Py_DECREF(gca);
15181523
Py_DECREF(gca_kwargs);
1519-
1524+
15201525
//plot our boys bravely, plot them strongly, plot them with a wink and clap
15211526
PyObject *plot3 = PyObject_GetAttrString(axis, "quiver");
15221527
if (!plot3) throw std::runtime_error("No 3D line plot");
@@ -2655,7 +2660,7 @@ inline void rcparams(const std::map<std::string, std::string>& keywords = {}) {
26552660
PyDict_SetItemString(kwargs, it->first.c_str(), PyLong_FromLong(std::stoi(it->second.c_str())));
26562661
else PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
26572662
}
2658-
2663+
26592664
PyObject * update = PyObject_GetAttrString(detail::_interpreter::get().s_python_function_rcparams, "update");
26602665
PyObject * res = PyObject_Call(update, args, kwargs);
26612666
if(!res) throw std::runtime_error("Call to rcParams.update() failed.");

0 commit comments

Comments
 (0)