Ticket #1308 (closed enhancement: fixed)

Opened 9 months ago

Last modified 7 months ago

Make np.dot and np.inner fast for read-only arrays.

Reported by: hansres Owned by: somebody
Priority: normal Milestone: 2.0.0
Component: numpy.core Version:
Keywords: Cc:

Description

Currently np.dot/np.inner are much slower (~3x) for read-only arrays than for writeable arrays.

In [1]: a = randn(1e6)

In [2]: %timeit dot(a, a)
100 loops, best of 3: 5.42 ms per loop

In [3]: a.setflags(write=False)

In [4]: %timeit dot(a, a)
100 loops, best of 3: 15.9 ms per loop.

This slowdown for read-only inputs is caused by the creation of array copies: dot/inner call PyArray_FromAny and require the WRITABLE flag. Instead, because read-only input arrays are fine, the WRITEABLE flag should not be is not required; and the ALIGNED flag should be sufficient.

Attachments

fast_dot_inner.patch (1.3 KB) - added by hansres 9 months ago.
Don’t require the WRITEABLE flag (change BEHAVED == ALIGNED|WRITEABLE --> ALIGNED).

Change History

Changed 9 months ago by hansres

Don’t require the WRITEABLE flag (change BEHAVED == ALIGNED|WRITEABLE --> ALIGNED).

Changed 8 months ago by hansres

  • status changed from new to needs_review

Changed 7 months ago by cdavid

  • status changed from needs_review to closed
  • type changed from defect to enhancement
  • resolution set to fixed
  • milestone set to 1.5.0

Fixed in r8082

Note: See TracTickets for help on using tickets.