@classmethod<EOL><INDENT>def from_data(cls, m, title="<STR_LIT>", key="<STR_LIT:0>", mxtype=None, fmt=None):<DEDENT>
pointer = m.indptr<EOL>indices = m.indices<EOL>values = m.data<EOL>nrows, ncols = m.shape<EOL>nnon_zeros = m.nnz<EOL>if fmt is None:<EOL><INDENT>pointer_fmt = IntFormat.from_number(np.max(pointer+<NUM_LIT:1>))<EOL>indices_fmt = IntFormat.from_number(np.max(indices+<NUM_LIT:1>))<EOL>if values.dtype.kind in np.typecodes["<STR_LIT>"]:<EOL><INDENT>values_fmt = ExpFormat.from_number(-np.max(np.abs(values)))<EOL><DEDENT>elif values.dtype.kind in np.typecodes["<STR_LIT>"]:<EOL><INDENT>values_fmt = IntFormat.from_number(-np.max(np.abs(values)))<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>" % values.dtype.kind)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>if mxtype is None:<EOL><INDENT>if not np.isrealobj(values):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if values.dtype.kind in np.typecodes["<STR_LIT>"]:<EOL><INDENT>tp = "<STR_LIT>"<EOL><DEDENT>elif values.dtype.kind in np.typecodes["<STR_LIT>"]:<EOL><INDENT>tp = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>"<EOL>% values.dtype)<EOL><DEDENT>mxtype = HBMatrixType(tp, "<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def _nlines(fmt, size):<EOL><INDENT>nlines = size // fmt.repeat<EOL>if nlines * fmt.repeat != size:<EOL><INDENT>nlines += <NUM_LIT:1><EOL><DEDENT>return nlines<EOL><DEDENT>pointer_nlines = _nlines(pointer_fmt, pointer.size)<EOL>indices_nlines = _nlines(indices_fmt, indices.size)<EOL>values_nlines = _nlines(values_fmt, values.size)<EOL>total_nlines = pointer_nlines + indices_nlines + values_nlines<EOL>return cls(title, key,<EOL>total_nlines, pointer_nlines, indices_nlines, values_nlines,<EOL>mxtype, nrows, ncols, nnon_zeros,<EOL>pointer_fmt.fortran_format, indices_fmt.fortran_format,<EOL>values_fmt.fortran_format)<EOL>
Create a HBInfo instance from an existing sparse matrix.

        Parameters
        ----------
        m : sparse matrix
            the HBInfo instance will derive its parameters from m
        title : str
            Title to put in the HB header
        key : str
            Key
        mxtype : HBMatrixType
            type of the input matrix
        fmt : dict
            not implemented

        Returns
        -------
        hb_info : HBInfo instance