'Replace D with a non-canonical equivalent: containing
duplicate elements and explicit zeros'

def spmatrix(self, D, sorted_indices=False, **kwargs):

    construct = super(_NonCanonicalMixin, self).spmatrix
    M = construct(D, **kwargs)
    zero_pos = (M.A == 0).nonzero()
    has_zeros = (zero_pos[0].size > 0)
    if has_zeros:
        k = (zero_pos[0].size // 2)
        with suppress_warnings() as sup:
            sup.filter(SparseEfficiencyWarning, 'Changing    the    sparsity    structure    of    a    cs[cr]_matrix    is    expensive')
            M = self._insert_explicit_zero(M, zero_pos[0][k], zero_pos[1][k])
    arg1 = self._arg1_for_noncanonical(M, sorted_indices)
    if ('shape' not in kwargs):
        kwargs['shape'] = M.shape
    NC = construct(arg1, **kwargs)
    if (NC.dtype in [np.float32, np.complex64]):
        rtol = 1e-05
    else:
        rtol = 1e-07
    assert_allclose(NC.A, M.A, rtol=rtol)
    if has_zeros:
        assert_((NC.data == 0).any())
    return NC
