Example #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
Example #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
Example #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
Example #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
Example #5
0
def bare_array(dims, mxclass=mx.DOUBLE):
    return mx.create_numeric_array(dims, mxclass, wrap=False)