void dd_MLWriteAmatrix(dd_Amatrix A, long rowmax, long colmax) { long i,j; double a; if (A==NULL){ rowmax=0; colmax=0; } MLPutFunction(stdlink,"List",rowmax); for (i=0; i < rowmax; i++) { MLPutFunction(stdlink,"List",colmax); for (j=0; j < colmax; j++) { a=dd_get_d(A[i][j]); MLPutDouble(stdlink, a); } } }
void dd_MLWriteAmatrix(dd_Amatrix A, long rowmax, long colmax) { long i,j; double a; char *str=NULL; if (A==NULL){ rowmax=0; colmax=0; } MLPutFunction(stdlink,"List",rowmax); for (i=0; i < rowmax; i++) { MLPutFunction(stdlink,"List",colmax); for (j=0; j < colmax; j++) { #if defined GMPRATIONAL str=dd_MLGetStrForNumber(A[i][j]); MLPutString(stdlink, str); if (str!=NULL) free(str); #else a=dd_get_d(A[i][j]); MLPutDouble(stdlink, a); #endif } } }
void python_to_mathematica_object(PyObject *obj) { if(PyBool_Check(obj)) { if(obj==Py_True) MLPutSymbol(stdlink, "True"); else MLPutSymbol(stdlink, "False"); return; } if(PyInt_Check(obj)) { MLPutLongInteger(stdlink, PyInt_AsLong(obj)); return; } if(PyLong_Check(obj)) { #ifdef PYTHON25 Py_ssize_t length; #else int length; #endif char *str, *mat_expr; PyObject *long_as_str; long_as_str = PyObject_CallMethod(obj, "__str__", NULL); PyString_AsStringAndSize(long_as_str, &str, &length); MLPutFunction(stdlink, "ToExpression", 1); MLPutString(stdlink, str); Py_DECREF(long_as_str); return; } if(obj==Py_None) { MLPutSymbol(stdlink, "Null"); return; } if(PyFloat_Check(obj)) { MLPutDouble(stdlink, (double)PyFloat_AsDouble(obj)); return; } if(PyComplex_Check(obj)) { MLPutFunction(stdlink, "Complex", 2); MLPutDouble(stdlink, (double)PyComplex_RealAsDouble(obj)); MLPutDouble(stdlink, (double)PyComplex_ImagAsDouble(obj)); return; } if(PyString_Check(obj)) { char *str; #ifdef PYTHON25 Py_ssize_t length; #else int length; #endif PyString_AsStringAndSize(obj, &str, &length); MLPutByteString(stdlink, (unsigned char *)str, length); return; } if(PyUnicode_Check(obj)) { MLPutUnicodeString(stdlink, PyUnicode_AsUnicode(obj), PyUnicode_GetSize(obj) ); return; } if(PyTuple_Check(obj)) { mat_process_iterable_object(obj, "Can't get iterator for 'tuple'"); return; } if(PyList_Check(obj)) { mat_process_iterable_object(obj, "Can't get iterator for 'list'"); return; } #ifndef PYTHON23 if(PyObject_TypeCheck(obj, &PySet_Type)) { mat_process_iterable_object(obj, "Can't get iterator for 'set'"); return; } #endif if(PyDict_Check(obj)) { PyObject *items; items = PyDict_Items(obj); python_to_mathematica_object(items); Py_DECREF(items); return; } // This should ideally print info, like type of the object, that // can't be converted. MLPutString(stdlink, "Object type can't be converted!"); }