Exemple #1
0
static jl_value_t *from_td_val(td_val_t *v)
{
    td_tag_t tag = td_typeof(v);
    switch (tag) {
    case TD_INT8:
        return jl_box_int8(td_int8(v));
    case TD_UINT8:
        return jl_box_uint8(td_uint8(v));
    case TD_INT16:
        return jl_box_int16(td_int16(v));
    case TD_UINT16:
        return jl_box_uint16(td_uint16(v));
    case TD_INT32:
        return jl_box_int32(td_int32(v));
    case TD_UINT32:
        return jl_box_uint32(td_uint32(v));
    case TD_INT64:
        return jl_box_int64(td_int64(v));
    case TD_UINT64:
        return jl_box_uint64(td_uint64(v));
    case TD_FLOAT:
        return jl_box_float32(td_float(v));
    case TD_DOUBLE:
        return jl_box_float64(td_double(v));
    case TD_UTF8:
        return jl_pchar_to_string(td_dataptr(v), td_length(v));
    case TD_ARRAY:
        return (jl_value_t*)
               jl_ptr_to_array_1d((jl_value_t*)jl_apply_array_type((jl_datatype_t*)td_type_to_jl(td_eltype(v)), 1),
                                  td_dataptr(v), td_length(v), 0);
    default:
        return jl_nothing;
    }
}
Exemple #2
0
static PyObject *from_td_val(td_val_t *v)
{
    PyObject *pVal = NULL;
    td_tag_t tag = td_typeof(v);
    switch (tag) {
    case TD_INT8:
        return PyInt_FromLong(td_int8(v));
    case TD_UINT8:
        return PyInt_FromLong(td_uint8(v));
    case TD_INT16:
        return PyInt_FromLong(td_int16(v));
    case TD_UINT16:
        return PyInt_FromLong(td_uint16(v));
    case TD_INT32:
        return PyInt_FromLong(td_int32(v));
    case TD_UINT32:
        return PyLong_FromUnsignedLong(td_uint32(v));
    case TD_INT64:
        return PyLong_FromLongLong(td_int64(v));
    case TD_UINT64:
        return PyLong_FromUnsignedLongLong(td_uint64(v));
    case TD_FLOAT:
        return PyFloat_FromDouble(td_float(v));
    case TD_DOUBLE:
        return PyFloat_FromDouble(td_double(v));
    case TD_UTF8:
        return PyUnicode_DecodeUTF8(td_dataptr(v), td_length(v), "strict");
    case TD_ARRAY:
        return pyarray_from_td_val(v);
    default:
        td_error("Cannot convert td type to Python.\n");
        return pVal;
    }
}
Exemple #3
0
static PyObject *pyarray_from_td_val(td_val_t *v){
    td_array_t *arr;
    arr = (td_array_t *) td_dataptr(v);
    npy_intp arr_shape[arr->ndims];
    for (size_t i=0; i<arr->ndims; ++i) arr_shape[i] = arr->length;

    return PyArray_SimpleNewFromData(arr->ndims,
                                     arr_shape,
                                     NPY_FLOAT,
                                     arr->data);
}