ENH: replace GIL of random module with a per state lock

The random module currently relies on the GIL for the state
synchronization which hampers threading performance.
Instead add a lock to the RandomState object and take it for all
operations calling into randomkit while releasing the GIL.
This allows parallizing random number generation using multiple states
or asynchronous generation in a worker thread.

Note that with a large number of threads the standard mersenne twister
used may exhibit overlap if the number of parallel streams is large
compared to the size of the state space, though due to the limited
scalability of Python in regards to threads this is likely not a big
issue.
ENH: added functionality nanmedian to numpy

Implemented a nanmedian and associated tests as an
extension of np.median to complement the other
nanfunctions

Added negative values to the unit tests

Cleaned up documentation of nanmedian
MAINT: Refactor numpy/polynomial/_polybase.py

1) Clean up the code and move repeated snippet to a method.
2) Remove use of has_sametype, has_samewindow, has_samedomain. I would
   like to deprecate those methods.
3) Fix error in __truediv__, and make it only allow non-boolean numbers
   for the denominator.

Closes #4631.
BUG: Fix __truediv__ bug in polytemplate.py file.

The use of polytemplate is deprecated, this fix is only for a backport
if needed.
TST: Add tests for the polynomial classes true division.
DOC/FIX: Fix error in documentation

Remove misleading note about equivalency betwen column_stack and
np.vstack(tup).T.

Fixes #3488
BUG: Fix use of setuptools.command.install._install.

This private variable has disappeared in later versions of setuptools.
In older versions of setuptools it is the same as
distutils.command.install.install, so use that instead.

Closes #4664.
Merge pull request #4667 from charris/fix-numpy-distutils

BUG: Fix use of setuptools.command.install._install.
Merge pull request #4633 from charris/fix-polynomial-true-division

Fix polynomial true division
Merge pull request #4666 from ElDeveloper/issue-3488

DOC/FIX: Fix error in documentation
FIX: Make object comparison ufuncs not include identity check

The issue here is that PyObject_RichCompareBool does an identity
check before doing any other checks. This is good, and is the
way for example list comparisons are handled. However in numpy
comparisons are elementwise, so that the identitycheck should
not be expected. The example for this is as follows:
obj_array = np.arange(3)
a = np.array([obj_array, 0], dtype=object)
np.equal(a, a)
If an identity check is done, this returns [True, True]. But
obj_array == obj_array itself cannot be cast to a bool.

While this is slightly slower, not doing the identity check seems
more logical in the light of elementwise operations.

Closes gh-2117.
DEP: Deprecate that comparisons ignore errors.

This means that for example broadcasting errors get raised.

The array_equiv function is changed to explicitely test
if broadcasting is possible. It may be nice to do this
test differently, but I am not sure if that is possible.

Create a FutureWarning for comparisons to None, which
should result in areal elementwise (object) comparisons.

Slightly adepted a wrong test.

Poly changes: Some changes in the polycode was necessary,
the one is probably a bug fix, the other needs to be
thought over, since len check is not perfect maybe, since
it is more liekly to raise raise an error.

Closes gh-3759 and gh-1608
DOC: Add (object) equality changes and error raising to release notes
DEP: Deprecate identity check in comparisons (not just removing)

Instead of just removing it, raise Deprecation/Future warnings
when the comparison object ufunc and the identity check do not
coincide.
Merge pull request #4609 from juliantaylor/random-gil

ENH: replace GIL of random module with a per state lock
MAINT: Comparison deprecation followup fixes

Makes the identity check `a = np.array([np.nan], dtype=object)`
`a == a`, etc. a deprecation/futurewarning instead of just
changing it.
Also fixes some smaller things.
Merge pull request #3514 from seberg/object_comparison

FIX: Make object comparison ufuncs not include identity check
ENH: add small memory chunk cache

Add very simplistic caching of small memory blocks (< 1024 bytes)
This improves the performance of small array operations by about 15%-20%:

without cache:
In [1]: d = np.array([1,1])
In [2]: %timeit d*d*d*d
1000000 loops, best of 3: 2.1 µs per loop

with cache:
In [1]: d = np.array([1,1])
In [2]: %timeit d*d*d*d
1000000 loops, best of 3: 1.7 µs per loop

The cache is a simple list of buckets of pointers, one for each size up
to 1023 bytes.
Two caches are required one for array data one one for
dimensinos/strides as they use different allocators.
All pointers can still be deleted with their matching deallocator but
this implies the size of the block must be known at the time of the free
in order to place the pointer in the right bucket. This should not be an
issue for well behaved numpy users.

Technically the ABI is broken in this change as the size of the
dimension memory block has been decreased from 3 * nd to 2 * nd, the
increase to 3 was a relic from the NA branch and is not needed anymore.
It should be unlikely someone relies on this size.
ENH: release GIL for callocs

useful for programs that block operations to avoid hitting the memory
bandwidth wall.
ENH: Break out early of loop in argmin/max for bool, fixes #4659

Break out early of loop if the min (max) found is `False` (`True`) when
`argmin` (`argmax`) is called on an array of type `bool`.