Przeglądaj źródła

Fix numpy detection and provide some functions even when numpy is not available

Benno Evers 5 lat temu
rodzic
commit
7f7b8528b4
2 zmienionych plików z 18 dodań i 18 usunięć
  1. 4 4
      Makefile
  2. 14 14
      matplotlibcpp.h

+ 4 - 4
Makefile

@@ -10,13 +10,13 @@ LDFLAGS        += $(shell $(PYTHON_CONFIG) --libs)
 
 # Either finds numpy or set -DWITHOUT_NUMPY
 EXTRA_FLAGS     += $(shell $(PYTHON_BIN) $(CURDIR)/numpy_flags.py)
-WITHOUT_NUMPY   := $(findstring $(CXXFLAGS), WITHOUT_NUMPY)
+WITHOUT_NUMPY   := $(findstring $(EXTRA_FLAGS), WITHOUT_NUMPY)
 
 # Examples requiring numpy support to compile
-EXAMPLES_NUMPY  := surface
+EXAMPLES_NUMPY  := surface colorbar
 EXAMPLES        := minimal basic modern animation nonblock xkcd quiver bar \
-	           fill_inbetween fill update subplot2grid colorbar lines3d \
-                   $(if WITHOUT_NUMPY,,$(EXAMPLES_NUMPY))
+	           fill_inbetween fill update subplot2grid lines3d \
+                   $(if $(WITHOUT_NUMPY),,$(EXAMPLES_NUMPY))
 
 # Prefix every example with 'examples/build/'
 EXAMPLE_TARGETS := $(patsubst %,examples/build/%,$(EXAMPLES))

+ 14 - 14
matplotlibcpp.h

@@ -340,6 +340,20 @@ PyObject* get_2darray(const std::vector<::std::vector<Numeric>>& v)
     return reinterpret_cast<PyObject *>(varray);
 }
 
+#else // fallback if we don't have numpy: copy every element of the given vector
+
+template<typename Numeric>
+PyObject* get_array(const std::vector<Numeric>& v)
+{
+    PyObject* list = PyList_New(v.size());
+    for(size_t i = 0; i < v.size(); ++i) {
+        PyList_SetItem(list, i, PyFloat_FromDouble(v.at(i)));
+    }
+    return list;
+}
+
+#endif // WITHOUT_NUMPY
+
 // sometimes, for labels and such, we need string arrays
 PyObject * get_array(const std::vector<std::string>& strings)
 {
@@ -361,20 +375,6 @@ PyObject* get_listlist(const std::vector<std::vector<Numeric>>& ll)
   return listlist;
 }
 
-#else // fallback if we don't have numpy: copy every element of the given vector
-
-template<typename Numeric>
-PyObject* get_array(const std::vector<Numeric>& v)
-{
-    PyObject* list = PyList_New(v.size());
-    for(size_t i = 0; i < v.size(); ++i) {
-        PyList_SetItem(list, i, PyFloat_FromDouble(v.at(i)));
-    }
-    return list;
-}
-
-#endif // WITHOUT_NUMPY
-
 } // namespace detail
 
 /// Plot a line through the given x and y data points..