49
49
zip (a) = Zip1 (a)
50
50
length (z:: Zip1 ) = length (z. a)
51
51
size (z:: Zip1 ) = size (z. a)
52
+ indices (z:: Zip1 ) = indices (z. a)
52
53
eltype {I} (:: Type{Zip1{I}} ) = Tuple{eltype (I)}
53
54
@inline start (z:: Zip1 ) = start (z. a)
54
55
@inline function next (z:: Zip1 , st)
67
68
zip (a, b) = Zip2 (a, b)
68
69
length (z:: Zip2 ) = _min_length (z. a, z. b, iteratorsize (z. a), iteratorsize (z. b))
69
70
size (z:: Zip2 ) = promote_shape (size (z. a), size (z. b))
71
+ indices (z:: Zip2 ) = promote_shape (indices (z. a), indices (z. b))
70
72
eltype {I1,I2} (:: Type{Zip2{I1,I2}} ) = Tuple{eltype (I1), eltype (I2)}
71
73
@inline start (z:: Zip2 ) = (start (z. a), start (z. b))
72
74
@inline function next (z:: Zip2 , st)
86
88
zip (a, b, c... ) = Zip (a, zip (b, c... ))
87
89
length (z:: Zip ) = _min_length (z. a, z. z, iteratorsize (z. a), iteratorsize (z. z))
88
90
size (z:: Zip ) = promote_shape (size (z. a), size (z. z))
91
+ indices (z:: Zip ) = promote_shape (indices (z. a), indices (z. z))
89
92
tuple_type_cons {S} (:: Type{S} , :: Type{Union{}} ) = Union{}
90
93
function tuple_type_cons {S,T<:Tuple} (:: Type{S} , :: Type{T} )
91
94
@_pure_meta
@@ -308,8 +311,10 @@ iteratoreltype{O}(::Type{Repeated{O}}) = HasEltype()
308
311
abstract AbstractProdIterator
309
312
310
313
length (p:: AbstractProdIterator ) = prod (size (p))
314
+ _length (p:: AbstractProdIterator ) = prod (map (unsafe_length, indices (p)))
311
315
size (p:: AbstractProdIterator ) = _prod_size (p. a, p. b, iteratorsize (p. a), iteratorsize (p. b))
312
- ndims (p:: AbstractProdIterator ) = length (size (p))
316
+ indices (p:: AbstractProdIterator ) = _prod_indices (p. a, p. b, iteratorsize (p. a), iteratorsize (p. b))
317
+ ndims (p:: AbstractProdIterator ) = length (indices (p))
313
318
314
319
# generic methods to handle size of Prod* types
315
320
_prod_size (a, :: HasShape ) = size (a)
@@ -323,6 +328,17 @@ _prod_size(a, b, ::HasShape, ::HasShape) = (size(a)..., size(b)...)
323
328
_prod_size (a, b, A, B) =
324
329
throw (ArgumentError (" Cannot construct size for objects of types $(typeof (a)) and $(typeof (b)) " ))
325
330
331
+ _prod_indices (a, :: HasShape ) = indices (a)
332
+ _prod_indices (a, :: HasLength ) = (OneTo (length (a)), )
333
+ _prod_indices (a, A) =
334
+ throw (ArgumentError (" Cannot compute indices for object of type $(typeof (a)) " ))
335
+ _prod_indices (a, b, :: HasLength , :: HasLength ) = (OneTo (length (a)), OneTo (length (b)))
336
+ _prod_indices (a, b, :: HasLength , :: HasShape ) = (OneTo (length (a)), indices (b)... )
337
+ _prod_indices (a, b, :: HasShape , :: HasLength ) = (indices (a)... , OneTo (length (b)))
338
+ _prod_indices (a, b, :: HasShape , :: HasShape ) = (indices (a)... , indices (b)... )
339
+ _prod_indices (a, b, A, B) =
340
+ throw (ArgumentError (" Cannot construct indices for objects of types $(typeof (a)) and $(typeof (b)) " ))
341
+
326
342
# one iterator
327
343
immutable Prod1{I} <: AbstractProdIterator
328
344
a:: I
@@ -331,6 +347,7 @@ product(a) = Prod1(a)
331
347
332
348
eltype {I} (:: Type{Prod1{I}} ) = Tuple{eltype (I)}
333
349
size (p:: Prod1 ) = _prod_size (p. a, iteratorsize (p. a))
350
+ indices (p:: Prod1 ) = _prod_indices (p. a, iteratorsize (p. a))
334
351
335
352
@inline start (p:: Prod1 ) = start (p. a)
336
353
@inline function next (p:: Prod1 , st)
0 commit comments