# argpartsort upcasts 32-bit to 64-bit

11 views

### dbv

Jul 11, 2014, 3:50:02 PM7/11/14
In a 64-bit (linux) OS, if the numpy/scipy arrays are defined as 32-bit objects then the outputs are 32-bit.  However, argpartsort returns a data object of 64-bit indices.

In a 32-bit (windows) OS, argpartsort returns a data object of 32-bit indices which is correct.

### Keith Goodman

Jul 11, 2014, 4:15:59 PM7/11/14
On Fri, Jul 11, 2014 at 12:50 PM, dbv wrote:
In a 64-bit (linux) OS, if the numpy/scipy arrays are defined as 32-bit objects then the outputs are 32-bit.  However, argpartsort returns a data object of 64-bit indices.

In a 32-bit (windows) OS, argpartsort returns a data object of 32-bit indices which is correct.

Yes,

In : a = np.arange(3, dtype=np.int32)
In : bn.argpartsort(a, 2)
Out: array([0, 1, 2])  # 64 bit

but numpy does the same

In : np.argsort(a)
Out: array([0, 1, 2])  # 64 bit

and the goal is to match numpy. BTW the examples above are on 64-bit linux.

### dbv

Jul 11, 2014, 5:45:26 PM7/11/14
See output below from matrix multiplication on 64-bit OS:

>>> import numpy
>>> from scipy import sparse
>>> import bottleneck

>>> row = numpy.array([0,0,1,2,2,2], dtype=numpy.int32)
>>> col = numpy.array([0,2,2,0,1,2], dtype=numpy.int32)
>>> data = numpy.array([1,2,3,4,5,6], dtype=numpy.int32)

>>> A = sparse.csr_matrix((data,(row,col)), shape=(3,3), dtype=numpy.float32)
>>> x = numpy.array([8.0, 4.0, 2.0], dtype=numpy.float32)
>>> b = A * x.T

>>> b
array([ 12.,   6.,  64.], dtype=float32)

>>> c = bottleneck.argpartsort(b, 2)
>>> c
array([1, 0, 2])
>>> type(c)
<type 'numpy.int64'>

>>> d = numpy.argsort(b)
>>> d
array([1, 0, 2])
>>> type(d)
<type 'numpy.int64'>

The output vector 'b' is a float32 as it should be and an argsort should return an int32 otherwise it is a mismatch of data types.  But, argpartsort (and numpy argsort) return int64 which doesn't seem right.  Yes/no?

### Keith Goodman

Jul 11, 2014, 5:52:51 PM7/11/14
The default numpy int type for your system (np.intp) is returned. I don't see why the type of b should change anything. If you disagree ask on the numpy list.

### Dougal Sutherland

Jul 11, 2014, 5:59:14 PM7/11/14
argsort returns indices; it doesn't really make sense (IMO) for the type of the index to depend on the type of the data.

It would be nice to support shorter return types in some cases (since you know the max value beforehand based on the type of the array), but see discussion of that here: https://github.com/numpy/numpy/issues/2989.

--
You received this message because you are subscribed to the Google Groups "bottle-neck" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottle-neck...@googlegroups.com.