[SciPy-dev] Inconsisten return type from discrete dists.

eric jones eric at enthought.com
Sun Jan 26 15:28:32 CST 2003

Hey Otto,

Thanks for the help.  Unit tests are sorely needed in a number of
locations.  I'm actually amazed at how many SciPy has (800+ when weave
is included), but I find the quantity still needed daunting.

> I started looking on writing some unit tests anyway. While doing that
> discovered that the return type from discrete distributions where
> inconsistent or rather they all seems to return floats except for
> randint. Further, some of them also returns a array of length 1 when
> called without size argument while others return a simple number.
> For the first issue I feel that it is more natural for them to return
> ints, the attached patch, return_ints.pathc, fixes that.

So you're saying that everything continues to return floats except for
randint which returns ints?  If so, then I agree.

> For the second issue I think that it is more convenient if they always
> returns an array. I have no patch for that, but I can fix it if that
> the consensus.

Yes, this sounds appropriate.

> While I wrote the unit tests I also found more bugs. There seem to be
> missing function in rv.py, namley _check_shape. By the look of how
> used  it should do something like this:
> def _check_shape(size):
>     if isinstance(size, tuple):
>         Ns = reduce(operator.mul, size)
>     else:
>         Ns = size
>     return (size, Ns)
> Attached patch, missing_check_shape.patch, fixes that.
> I also have a couple of question on coding guide lines.
> 1 - What is the correct way to check if a array is of integer type?
> 2 - What is the correct way to call things from Numeric? i.e.
> scipy.shape(a) or Numeric.shape(a)?

Pretty much the entire code base assumes that Numeric (scipy_base
actually) is part of the standard set of functions needed for scientific
work.  So, the following is used: 

	from scipy_base import *

It may occasionally show up as

	from Numeric import *
	from scipy_base.fastumath import *

I think we should standardize on the first.  You can use shape() without
qualifying it with a module.

Otto, if you would like CVS access to add your tests, let me know.  


More information about the Scipy-dev mailing list