[NumPy-Tickets] [NumPy] #1192: integer dot product
NumPy Trac
numpy-tickets@scipy....
Mon Feb 28 23:37:13 CST 2011
#1192: integer dot product
----------------------+-----------------------------------------------------
Reporter: jloper | Owner: somebody
Type: defect | Status: closed
Priority: normal | Milestone:
Component: Other | Version: 1.2.1
Resolution: invalid | Keywords: dot int8
----------------------+-----------------------------------------------------
Changes (by rgommers):
* status: new => closed
* resolution: => invalid
Old description:
> the 'dot' function is designed to work ONLY WITH FLOATING POINT NUMBERS,
> but it doesn't raise an exception or even a warning when you feed it
> integer values. This is going to confuse people.
>
> In [239]: a=require(randint(0,2,5000),int8)
> In [240]: b=require(randint(0,2,5000),int8)
> In [241]: dot(a,b); sum(a*b)
> Out[241]: -82
> Out[241]: 1198
>
> Let's just say it is a very rare use-case that people want sum(a*b) mod
> 128.
New description:
the 'dot' function is designed to work ONLY WITH FLOATING POINT NUMBERS,
but it doesn't raise an exception or even a warning when you feed it
integer values. This is going to confuse people.
{{{
In [239]: a=require(randint(0,2,5000),int8)
In [240]: b=require(randint(0,2,5000),int8)
In [241]: dot(a,b); sum(a*b)
Out[241]: -82
Out[241]: 1198
}}}
Let's just say it is a very rare use-case that people want sum(a*b) mod
128.
--
Comment:
Your example works fine with int32, see below, so your assertion it works
only with floats is false. If one uses int8 the expected return values are
also of dtype int8. If you use int8 arrays, it's often *because* you want
to use integer arithmetic with its own rules. So I think this ticket can
be closed.
{{{
In [3]: from numpy.random import randint
In [4]: a = randint(0, 2, 5000).astype(np.int8)
In [5]: a
Out[5]: array([1, 1, 1, ..., 0, 1, 0], dtype=int8)
In [6]: b = randint(0, 2, 5000).astype(np.int8)
In [8]: np.dot(a, b); sum(a*b)
Out[8]: -13
Out[8]: 1267
In [10]: a = randint(0, 2, 5000).astype(np.int32)
In [11]: b = randint(0, 2, 5000).astype(np.int32)
In [12]: np.dot(a, b); sum(a*b)
Out[12]: 1255
Out[12]: 1255
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1192#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list