Skip to content

Commit 7f7b852

Browse files
committed
Fix numpy detection and provide some functions even when numpy is not available
1 parent 41477fc commit 7f7b852

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ LDFLAGS += $(shell $(PYTHON_CONFIG) --libs)
1010

1111
# Either finds numpy or set -DWITHOUT_NUMPY
1212
EXTRA_FLAGS += $(shell $(PYTHON_BIN) $(CURDIR)/numpy_flags.py)
13-
WITHOUT_NUMPY := $(findstring $(CXXFLAGS), WITHOUT_NUMPY)
13+
WITHOUT_NUMPY := $(findstring $(EXTRA_FLAGS), WITHOUT_NUMPY)
1414

1515
# Examples requiring numpy support to compile
16-
EXAMPLES_NUMPY := surface
16+
EXAMPLES_NUMPY := surface colorbar
1717
EXAMPLES := minimal basic modern animation nonblock xkcd quiver bar \
18-
fill_inbetween fill update subplot2grid colorbar lines3d \
19-
$(if WITHOUT_NUMPY,,$(EXAMPLES_NUMPY))
18+
fill_inbetween fill update subplot2grid lines3d \
19+
$(if $(WITHOUT_NUMPY),,$(EXAMPLES_NUMPY))
2020

2121
# Prefix every example with 'examples/build/'
2222
EXAMPLE_TARGETS := $(patsubst %,examples/build/%,$(EXAMPLES))

matplotlibcpp.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,20 @@ PyObject* get_2darray(const std::vector<::std::vector<Numeric>>& v)
340340
return reinterpret_cast<PyObject *>(varray);
341341
}
342342

343+
#else // fallback if we don't have numpy: copy every element of the given vector
344+
345+
template<typename Numeric>
346+
PyObject* get_array(const std::vector<Numeric>& v)
347+
{
348+
PyObject* list = PyList_New(v.size());
349+
for(size_t i = 0; i < v.size(); ++i) {
350+
PyList_SetItem(list, i, PyFloat_FromDouble(v.at(i)));
351+
}
352+
return list;
353+
}
354+
355+
#endif // WITHOUT_NUMPY
356+
343357
// sometimes, for labels and such, we need string arrays
344358
PyObject * get_array(const std::vector<std::string>& strings)
345359
{
@@ -361,20 +375,6 @@ PyObject* get_listlist(const std::vector<std::vector<Numeric>>& ll)
361375
return listlist;
362376
}
363377

364-
#else // fallback if we don't have numpy: copy every element of the given vector
365-
366-
template<typename Numeric>
367-
PyObject* get_array(const std::vector<Numeric>& v)
368-
{
369-
PyObject* list = PyList_New(v.size());
370-
for(size_t i = 0; i < v.size(); ++i) {
371-
PyList_SetItem(list, i, PyFloat_FromDouble(v.at(i)));
372-
}
373-
return list;
374-
}
375-
376-
#endif // WITHOUT_NUMPY
377-
378378
} // namespace detail
379379

380380
/// Plot a line through the given x and y data points..

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