def _numpy_to_xmatrix(m):
  xm = jsgd_wrap.x_matrix_t()
  xm.n, xm.d = m.shape
  if not hasattr(m, 'indptr'): # dense
    _check_row_float32(m)  
    xm.encoding = jsgd_wrap.JSGD_X_FULL
    xm.data = jsgd_wrap.numpy_to_fvec_ref(m)
  else:     # sparse    
    if m.format != 'csr': 
      raise TypeError('expected sparse CSR matrix')
    xm.encoding = jsgd_wrap.JSGD_X_SPARSE
    xm.sparse_data = jsgd_wrap.numpy_to_fvec_ref(m.data)
    xm.indptr = jsgd_wrap.numpy_to_ivec_ref(m.indptr)
    xm.indices = jsgd_wrap.numpy_to_ivec_ref(m.indices)
  return xm
Example #2
0
def _numpy_to_xmatrix(m):
  xm = jsgd_wrap.x_matrix_t()
  xm.n, xm.d = m.shape
  if not hasattr(m, 'indptr'): # dense
    _check_row_float32(m)  
    xm.encoding = jsgd_wrap.JSGD_X_FULL
    xm.data = jsgd_wrap.numpy_to_fvec_ref(m)
  else:     # sparse    
    if m.format != 'csr': 
      raise TypeError('expected sparse CSR matrix')
    xm.encoding = jsgd_wrap.JSGD_X_SPARSE
    xm.sparse_data = jsgd_wrap.numpy_to_fvec_ref(m.data)
    xm.indptr = jsgd_wrap.numpy_to_ivec_ref(m.indptr)
    xm.indices = jsgd_wrap.numpy_to_ivec_ref(m.indices)
  return xm
def _get_ptr(m):
  if m.dtype == numpy.int32: return jsgd_wrap.numpy_to_ivec_ref(m)
  if m.dtype == numpy.float32: return jsgd_wrap.numpy_to_fvec_ref(m)
  if m.dtype == numpy.float64: return jsgd_wrap.numpy_to_dvec_ref(m)
  raise TypeError('type %s not handled' % m.dtype)
Example #4
0
def _get_ptr(m):
  if m.dtype == numpy.int32: return jsgd_wrap.numpy_to_ivec_ref(m)
  if m.dtype == numpy.float32: return jsgd_wrap.numpy_to_fvec_ref(m)
  if m.dtype == numpy.float64: return jsgd_wrap.numpy_to_dvec_ref(m)
  raise TypeError('type %s not handled' % m.dtype)