comparison VectorConversion.cpp @ 48:0e0e18629917

Set parameters in bulk
author Chris Cannam
date Tue, 13 Jan 2015 11:57:06 +0000
parents 36cc53aad853
children
comparison
equal deleted inserted replaced
47:1cb0ed230b71 48:0e0e18629917
35 authorization. 35 authorization.
36 */ 36 */
37 37
38 #include <Python.h> 38 #include <Python.h>
39 39
40 #include "FloatConversion.h"
40 #include "VectorConversion.h" 41 #include "VectorConversion.h"
41 42
42 #include <math.h> 43 #include <math.h>
43 #include <float.h> 44 #include <float.h>
44 45
59 60
60 /// floating point numbers (TODO: check numpy.float128) 61 /// floating point numbers (TODO: check numpy.float128)
61 float 62 float
62 VectorConversion::PyValue_To_Float(PyObject* pyValue) const 63 VectorConversion::PyValue_To_Float(PyObject* pyValue) const
63 { 64 {
64 // convert float 65 if (FloatConversion::check(pyValue)) {
65 if (pyValue && PyFloat_Check(pyValue)) { 66 return FloatConversion::convert(pyValue);
66 return (float) PyFloat_AS_DOUBLE(pyValue); 67 }
67 } 68
68
69 // convert long
70 if (pyValue && PyLong_Check(pyValue)) {
71 return (float) PyLong_AsDouble(pyValue);
72 }
73
74 // convert int
75 if (pyValue && PyInt_Check(pyValue)) {
76 return (float) PyInt_AsLong(pyValue);
77 }
78
79 if (pyValue == NULL) {
80 setValueError("Error while converting object " + PyValue_Get_TypeName(pyValue) + " to float. ");
81 return 0.0;
82 }
83
84 setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float, int, or long."); 69 setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float, int, or long.");
85 return 0.0; 70 return 0.0;
86 } 71 }
87 72
88 vector<float> 73 vector<float>