changeset 74:e7d03f88ef43 vampyhost

Float vector conversion
author Chris Cannam
date Mon, 24 Nov 2014 16:22:41 +0000
parents 76355b91cd92
children 2a9fb03458d7
files PyTypeConversions.cpp PyTypeConversions.h
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/PyTypeConversions.cpp	Mon Nov 24 11:02:20 2014 +0000
+++ b/PyTypeConversions.cpp	Mon Nov 24 16:22:41 2014 +0000
@@ -739,6 +739,19 @@
 			return Output;
 	}
 }
+
+PyObject *
+PyTypeConversions::FloatVector_To_PyArray(const vector<float> &v) const
+{
+	npy_intp ndims[1];
+	ndims[0] = (int)v.size();
+	PyObject *arr = PyArray_SimpleNew(1, ndims, dtype_float32);
+	float *data = (float *)PyArray_DATA((PyArrayObject *)arr);
+	for (int i = 0; i < ndims[0]; ++i) {
+		data[i] = v[i];
+	}
+	return arr;
+}
 #endif
 
 PyObject *
--- a/PyTypeConversions.h	Mon Nov 24 11:02:20 2014 +0000
+++ b/PyTypeConversions.h	Mon Nov 24 16:22:41 2014 +0000
@@ -103,6 +103,7 @@
 	// Numpy types
 #ifdef HAVE_NUMPY
 	std::vector<float> PyArray_To_FloatVector (PyObject *pyValue) const;
+	PyObject *FloatVector_To_PyArray(const std::vector<float> &) const; // Copying the data
 #endif
 
 	/// Convert DTYPE type 1D NumpyArray to std::vector<RET>