Mercurial > hg > vampy-host
comparison VectorConversion.cpp @ 43:36cc53aad853
Test output values a bit; fix input conversion from int
author | Chris Cannam |
---|---|
date | Wed, 03 Dec 2014 08:25:05 +0000 |
parents | 55fcd0e3e513 |
children | 0e0e18629917 |
comparison
equal
deleted
inserted
replaced
42:9dd449a19004 | 43:36cc53aad853 |
---|---|
60 /// floating point numbers (TODO: check numpy.float128) | 60 /// floating point numbers (TODO: check numpy.float128) |
61 float | 61 float |
62 VectorConversion::PyValue_To_Float(PyObject* pyValue) const | 62 VectorConversion::PyValue_To_Float(PyObject* pyValue) const |
63 { | 63 { |
64 // convert float | 64 // convert float |
65 if (pyValue && PyFloat_Check(pyValue)) | 65 if (pyValue && PyFloat_Check(pyValue)) { |
66 //TODO: check for limits here (same on most systems) | |
67 return (float) PyFloat_AS_DOUBLE(pyValue); | 66 return (float) PyFloat_AS_DOUBLE(pyValue); |
68 | 67 } |
69 if (pyValue == NULL) | 68 |
70 { | 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) { | |
71 setValueError("Error while converting object " + PyValue_Get_TypeName(pyValue) + " to float. "); | 80 setValueError("Error while converting object " + PyValue_Get_TypeName(pyValue) + " to float. "); |
72 return 0.0; | 81 return 0.0; |
73 } | 82 } |
74 | 83 |
75 setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float."); | 84 setValueError("Conversion error: object" + PyValue_Get_TypeName(pyValue) +" is not float, int, or long."); |
76 return 0.0; | 85 return 0.0; |
77 } | 86 } |
78 | 87 |
79 vector<float> | 88 vector<float> |
80 VectorConversion::PyValue_To_FloatVector (PyObject *pyValue) const | 89 VectorConversion::PyValue_To_FloatVector (PyObject *pyValue) const |