summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorSergei Lebedev <slebedev@google.com>2019-04-24 14:04:18 +0100
committerSergei Lebedev <slebedev@google.com>2019-05-19 20:05:55 +0100
commit71fc59d587016d6f36007ba06e074d4d4a6b483d (patch)
tree17c6e5435c3a28ed6eaae928d1ee7da5223de8a9 /benchmarks
parentf91b033aa35b929610c0db12f16b1b0c1ddc08e6 (diff)
downloadnumpy-71fc59d587016d6f36007ba06e074d4d4a6b483d.tar.gz
ENH: Improved performance of PyArray_FromAny for sequences of array-like
Prior to this commit np.array([array_like]) would recursively copy each element of array_like. This is due to the fact that setArrayFromSequence only special-cased lists of NumPy arrays, any other object was treated as a sequence even if it supported buffer or __array*__ interfaces. See tensorflow/tensorflow#27692 for details. The commit generalizes the special-case in setArrayFromSequence to any array-like, i.e. a buffer or an object with __array__, __array_interface__ __array_struct__.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmarks/bench_core.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_core.py b/benchmarks/benchmarks/bench_core.py
index 194ce3218..628600408 100644
--- a/benchmarks/benchmarks/bench_core.py
+++ b/benchmarks/benchmarks/bench_core.py
@@ -10,6 +10,7 @@ class Core(Benchmark):
self.l100 = range(100)
self.l50 = range(50)
self.l = [np.arange(1000), np.arange(1000)]
+ self.l_view = [memoryview(a) for a in self.l]
self.l10x10 = np.ones((10, 10))
def time_array_1(self):
@@ -27,6 +28,9 @@ class Core(Benchmark):
def time_array_l(self):
np.array(self.l)
+ def time_array_l_view(self):
+ np.array(self.l_view)
+
def time_vstack_l(self):
np.vstack(self.l)