Closed pseeth closed 4 years ago
Per offline discussion with @pseeth, we need to make sure the fix is backwards compatible with scipy 1.4, i.e. if truncnorm.rvs
returns a scalar, the code should still work.
Updated proposed solution: cast to array and then back to scalar
return np.array(scipy.stats.truncnorm.rvs(a, b, mu, sigma, random_state=random_state)).item()
The linked issue remarks that there may be a speed hit in Scipy 1.5.1. So I just ran the test suite locally and checked the speed.
1.5.1 -> ran in 150.55 seconds
1.4.0 -> ran in 145.13 seconds
Nothing remarkable there. Just logging it here for posterity.
Updated locally with coercing to array and then back to scalar. Passes tests in 1.4.0 as well as 1.5.1.
.item()
exists back to at least numpy 1.13: https://numpy.org/doc/1.13/reference/generated/numpy.ndarray.item.html?highlight=item#numpy.ndarray.item. So we're good there.
Making the PR!
Closed by #108
In the latest Scipy version, Scaper is broken due to an underlying change in the type returned by
scipy.stats.truncnorm.rvs
. This used to return a float and now returns an array for some reason. Here is a quick example:This causes a lot of downstream errors in formatting in Sox, in the tests that check if things are a real number, etc. Great test suite! The fix should be simple. Convert the output of
_sample_trunc_norm
in Scaper to return a scalar. I believe this was caused by vectorizing the truncnorm function, though as far as I can tell, the change in return type is somewhat undocumented...https://github.com/scipy/scipy/issues/11299
I believe the fix should look like this:
.item
coerces the array to a scalar. This works locally for me.