'Assign val to self, where val can be a scalar or a CUDAMatrix
with the same dimensions as self.'

def assign(self, val):

    if isinstance(val, CUDAMatrix):
        err_code = _cudamat.copy_on_device(val.p_mat, self.p_mat)
    elif isinstance(val, (int, float)):
        err_code = _cudamat.assign_scalar(self.p_mat, ct.c_float(val))
    else:
        raise ValueError, 'Assigned    value    must    be    of    type    CUDAMatrix,    int,    or    float.'
    if err_code:
        raise generate_exception(err_code)
    return self
