Example #1
0
  PyObject * array2numpy(const ArrayBase & a)
  {
    initNumpy();

    npy_intp dims[1];
    dims[0] = npy_intp(a.getCount());

    NTA_BasicType t = a.getType();
    int dtype;
    switch (t)
    {
    case NTA_BasicType_Byte: 
      dtype = NPY_INT8;
      break;      
    case NTA_BasicType_Int16: 
      dtype = NPY_INT16;
      break;      
    case NTA_BasicType_UInt16: 
      dtype = NPY_UINT16;
      break;      
    case NTA_BasicType_Int32: 
      dtype = NPY_INT32;
      break;      
    case NTA_BasicType_UInt32: 
      dtype = NPY_UINT32;
      break;      
    case NTA_BasicType_Int64: 
      dtype = NPY_INT64;
      break;      
    case NTA_BasicType_UInt64: 
      dtype = NPY_UINT64;
      break;      
    case NTA_BasicType_Real32: 
      dtype = NPY_FLOAT32;
      break;      
    case NTA_BasicType_Real64: 
      dtype = NPY_FLOAT64;
      break;
    case NTA_BasicType_Bool:
      dtype = NPY_BOOL;
      break;
    default:
      NTA_THROW << "Unknown basic type: " << t;
    };

    return (PyObject *)PyArray_SimpleNewFromData(1,
                                                 dims,
                                                 dtype,
                                                 a.getBuffer());
  }
Example #2
0
int initLuaToPython(lua_State* L) {
  initNumpy(L);
  initStorage(L);
  return 0;
}