| 25 | |
| 26 | |
| 27 | Parameter* PythonDictToParameter(PyObject* dict, Edt tp) { |
| 28 | if (!PyDict_Check(dict)) throw EssentiaException("map parameter not a python dictionary"); |
| 29 | |
| 30 | PyObject *key, *value; |
| 31 | Py_ssize_t pos = 0; |
| 32 | |
| 33 | switch (tp) { |
| 34 | case MAP_VECTOR_REAL: { |
| 35 | map<string, vector<Real> > mapVecReal; |
| 36 | while (PyDict_Next(dict, &pos, &key, &value)) { |
| 37 | if (!PyString_Check(key)) throw EssentiaException("all keys in the dict should be strings"); |
| 38 | |
| 39 | string skey = PyString_AS_STRING(key); |
| 40 | RogueVector<Real>* rv = (RogueVector<Real>*)VectorReal::fromPythonRef(value); |
| 41 | mapVecReal[skey] = *((vector<Real>*)rv); |
| 42 | delete rv; |
| 43 | } |
| 44 | return new Parameter(mapVecReal); |
| 45 | } |
| 46 | |
| 47 | case MAP_VECTOR_STRING: { |
| 48 | map<string, vector<string> > mapVecString; |
| 49 | while (PyDict_Next(dict, &pos, &key, &value)) { |
| 50 | if (!PyString_Check(key)) throw EssentiaException("all keys in the dict should be strings"); |
| 51 | |
| 52 | string skey = PyString_AS_STRING(key); |
| 53 | mapVecString[skey] = *((vector<string>*)VectorString::fromPythonCopy(value)); |
| 54 | } |
| 55 | return new Parameter(mapVecString); |
| 56 | } |
| 57 | |
| 58 | default: |
| 59 | throw EssentiaException("map type not supported"); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void parseParameters(ParameterMap* pm, PyObject* args, PyObject* keywds) { |
| 64 | Py_ssize_t pos = 0; |
no test coverage detected