Exemplo n.º 1
0
 def _scalar_unpy(self):
     byteval = struct.pack(fmt, self)
     scalar = mx.create_numeric_array(dims=(1,1), mxclass=mxclass, wrap=True)
     assert len(byteval) == scalar._get_element_size(), (
         "Datatype size mismatch")
     scalar._set_element(byteval)
     return scalar
Exemplo n.º 2
0
 def _scalar_unpy(self):
     byteval = struct.pack(fmt, self)
     scalar = mx.create_numeric_array(dims=(1, 1),
                                      mxclass=mxclass,
                                      wrap=True)
     assert len(byteval) == scalar._get_element_size(), (
         "Datatype size mismatch")
     scalar._set_element(byteval)
     return scalar
Exemplo n.º 3
0
 def numpy_ndarray_unpy(self):
     '''
     Converts a numpy array to an mxArray. An appropriate
     data type is selected using select_mxclass_by_dtype.
     Fattens the array or scalar out to 2d if necessary. 
     See Issue #5
     '''
     self = np.atleast_2d(self)
     mxclass = select_mxclass_by_dtype(self.dtype.type)
     cobj = mx.create_numeric_array(mxclass=mxclass, dims=self.shape)
     wrapper = mx.wrap_pycobject(cobj)
     wrap_array = np.asarray(wrapper)
     wrap_array[...] = self
     return wrapper
Exemplo n.º 4
0
 def numpy_ndarray_unpy(self):
     '''
     Converts a numpy array to an mxArray. An appropriate
     data type is selected using select_mxclass_by_dtype.
     Fattens the array or scalar out to 2d if necessary. 
     See Issue #5
     '''
     self = np.atleast_2d(self)
     mxclass = select_mxclass_by_dtype(self.dtype.type)    
     cobj = mx.create_numeric_array(mxclass = mxclass,
                                    dims = self.shape)
     wrapper = mx.wrap_pycobject(cobj)
     wrap_array = np.asarray(wrapper)
     wrap_array[...] = self
     return wrapper
Exemplo n.º 5
0
def bare_array(dims, mxclass=mx.DOUBLE):
    return mx.create_numeric_array(dims, mxclass, wrap=False)