From 71fc59d587016d6f36007ba06e074d4d4a6b483d Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Wed, 24 Apr 2019 14:04:18 +0100 Subject: 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__. --- benchmarks/benchmarks/bench_core.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'benchmarks') 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) -- cgit v1.2.1