aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/contourpy/src/output_array.h
diff options
context:
space:
mode:
authorshumkovnd <shumkovnd@yandex-team.com>2023-11-10 14:39:34 +0300
committershumkovnd <shumkovnd@yandex-team.com>2023-11-10 16:42:24 +0300
commit77eb2d3fdcec5c978c64e025ced2764c57c00285 (patch)
treec51edb0748ca8d4a08d7c7323312c27ba1a8b79a /contrib/python/contourpy/src/output_array.h
parentdd6d20cadb65582270ac23f4b3b14ae189704b9d (diff)
downloadydb-77eb2d3fdcec5c978c64e025ced2764c57c00285.tar.gz
KIKIMR-19287: add task_stats_drawing script
Diffstat (limited to 'contrib/python/contourpy/src/output_array.h')
-rw-r--r--contrib/python/contourpy/src/output_array.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/contrib/python/contourpy/src/output_array.h b/contrib/python/contourpy/src/output_array.h
new file mode 100644
index 0000000000..ce6be00d37
--- /dev/null
+++ b/contrib/python/contourpy/src/output_array.h
@@ -0,0 +1,70 @@
+#ifndef CONTOURPY_OUTPUT_ARRAY_H
+#define CONTOURPY_OUTPUT_ARRAY_H
+
+#include "common.h"
+#include <vector>
+
+namespace contourpy {
+
+// A reusable array that is output from C++ to Python. Depending on the chosen line or fill type,
+// it can either be created as a NumPy array that will be directly returned to the Python caller,
+// or as a C++ vector that will be further manipulated (such as split up) before being converted to
+// NumPy array(s) for returning. BaseContourGenerator's marching does not care which form it is as
+// it just writes values to either array using an incrementing pointer.
+template <typename T>
+class OutputArray
+{
+public:
+ OutputArray()
+ : size(0), start(nullptr), current(nullptr)
+ {}
+
+ void clear()
+ {
+ vector.clear();
+ size = 0;
+ start = current = nullptr;
+ }
+
+ void create_cpp(count_t new_size)
+ {
+ assert(new_size > 0);
+ size = new_size;
+ vector.resize(size);
+ start = current = vector.data();
+ }
+
+ py::array_t<T> create_python(count_t new_size)
+ {
+ assert(new_size > 0);
+ size = new_size;
+ py::array_t<T> py_array(size);
+ start = current = py_array.mutable_data();
+ return py_array;
+ }
+
+ py::array_t<T> create_python(count_t shape0, count_t shape1)
+ {
+ assert(shape0 > 0 && shape1 > 0);
+ size = shape0*shape1;
+ py::array_t<T> py_array({shape0, shape1});
+ start = current = py_array.mutable_data();
+ return py_array;
+ }
+
+ // Non-copyable and non-moveable.
+ OutputArray(const OutputArray& other) = delete;
+ OutputArray(const OutputArray&& other) = delete;
+ OutputArray& operator=(const OutputArray& other) = delete;
+ OutputArray& operator=(const OutputArray&& other) = delete;
+
+
+ std::vector<T> vector;
+ count_t size;
+ T* start; // Start of array, whether C++ or Python.
+ T* current; // Where to write next value to before incrementing.
+};
+
+} // namespace contourpy
+
+#endif // CONTOURPY_OUTPUT_ARRAY_H