'Write `arr` to stream at top and sub levels
Parameters
arr : array_like
array-like object to create writer for'

def write(self, arr):

    mat_tag_pos = self.file_stream.tell()
    if scipy.sparse.issparse(arr):
        self.write_sparse(arr)
        self.update_matrix_tag(mat_tag_pos)
        return
    narr = to_writeable(arr)
    if (narr is None):
        raise TypeError(('Could    not    convert    %s    (type    %s)    to    array' % (arr, type(arr))))
    if isinstance(narr, MatlabObject):
        self.write_object(narr)
    elif isinstance(narr, MatlabFunction):
        raise MatWriteError('Cannot    write    matlab    functions')
    elif (narr is EmptyStructMarker):
        self.write_empty_struct()
    elif narr.dtype.fields:
        self.write_struct(narr)
    elif narr.dtype.hasobject:
        self.write_cells(narr)
    elif (narr.dtype.kind in ('U', 'S')):
        if self.unicode_strings:
            codec = 'UTF8'
        else:
            codec = 'ascii'
        self.write_char(narr, codec)
    else:
        self.write_numeric(narr)
    self.update_matrix_tag(mat_tag_pos)
