Sounds fine to me.  Yeah, I don't feel strongly about this; I was just
curious what distinguished this usage of assert from the one you previously
contested, and I'm satisfied with your explanation, thanks for the
information!


On Tue, Feb 11, 2014 at 1:09 PM, Jorge Cañardo Alastuey <
notifications@github.com> wrote:

> In bipy/maths/stats/ordination/correspondence_analysis.py:
>
> > +        # Let's store them since they're needed to compute scores
> > +        self.column_marginals = column_marginals
> > +        self.row_marginals = row_marginals
> > +
> > +        # Formula 9.32 in Lagrange & Lagrange (1998). Notice that it's
> > +        # an scaled version of the contribution of each cell towards
> > +        # Pearson chi-square statistic.
> > +        expected = np.outer(row_marginals, column_marginals)
> > +        Q_bar = (Q - expected) / np.sqrt(expected)  # Eq. 9.32
> > +
> > +        # Step 2 (Singular Value Decomposition)
> > +        U_hat, W, Ut = np.linalg.svd(Q_bar, full_matrices=False)
> > +        # Due to the centering, there are at most min(r, c) - 1 non-zero
> > +        # eigenvalues (which are all positive)
> > +        rank = svd_rank(Q_bar.shape, W)
> > +        assert rank <= min(r, c) - 1
>
> Exactly, that's the point of asserts: checking things that have no reason
> for not being true. A long read on why this is reasonable can be found
> here<https://mail.python.org/pipermail/python-list/2013-November/660401.html>.
> Anecdotally, this answer <http://stackoverflow.com/a/945135/1191119>begins with "Asserts should be used to test conditions that *should
> never happen*."
>
> At any rate, I didn't expect this detail to spark a lively discussion ;)
> Thanks everybody!
>
> The gist of these checks is that in a world without floating point
> inaccuracies, they would never fail. In real life, they shouldn't because
> ranks are found in a numerically sound way. If we want to keep the checks
> (they're cheap, potentially useful, and helpful if someone had to go
> through the theory again), I thought an assertion was precisely the right
> error to raise (but incorporating currently-missing error messages!). After
> thinking about making them runtime warnings, they doesn't seem strong
> enough (it'd be so odd if it ever happened that it would be worth
> investigating). Thoughts?
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/biocore/bipy/pull/90/files#r9641053>
> .
>