69
69
zip (a) = Zip1 (a)
70
70
length (z:: Zip1 ) = length (z. a)
71
71
size (z:: Zip1 ) = size (z. a)
72
+ indices (z:: Zip1 ) = indices (z. a)
72
73
eltype {I} (:: Type{Zip1{I}} ) = Tuple{eltype (I)}
73
74
@inline start (z:: Zip1 ) = start (z. a)
74
75
@inline function next (z:: Zip1 , st)
87
88
zip (a, b) = Zip2 (a, b)
88
89
length (z:: Zip2 ) = _min_length (z. a, z. b, iteratorsize (z. a), iteratorsize (z. b))
89
90
size (z:: Zip2 ) = promote_shape (size (z. a), size (z. b))
91
+ indices (z:: Zip2 ) = promote_shape (indices (z. a), indices (z. b))
90
92
eltype {I1,I2} (:: Type{Zip2{I1,I2}} ) = Tuple{eltype (I1), eltype (I2)}
91
93
@inline start (z:: Zip2 ) = (start (z. a), start (z. b))
92
94
@inline function next (z:: Zip2 , st)
@@ -137,6 +139,7 @@ julia> first(c)
137
139
zip (a, b, c... ) = Zip (a, zip (b, c... ))
138
140
length (z:: Zip ) = _min_length (z. a, z. z, iteratorsize (z. a), iteratorsize (z. z))
139
141
size (z:: Zip ) = promote_shape (size (z. a), size (z. z))
142
+ indices (z:: Zip ) = promote_shape (indices (z. a), indices (z. z))
140
143
tuple_type_cons {S} (:: Type{S} , :: Type{Union{}} ) = Union{}
141
144
function tuple_type_cons {S,T<:Tuple} (:: Type{S} , :: Type{T} )
142
145
@_pure_meta
@@ -430,8 +433,10 @@ iteratoreltype{O}(::Type{Repeated{O}}) = HasEltype()
430
433
abstract AbstractProdIterator
431
434
432
435
length (p:: AbstractProdIterator ) = prod (size (p))
436
+ _length (p:: AbstractProdIterator ) = prod (map (unsafe_length, indices (p)))
433
437
size (p:: AbstractProdIterator ) = _prod_size (p. a, p. b, iteratorsize (p. a), iteratorsize (p. b))
434
- ndims (p:: AbstractProdIterator ) = length (size (p))
438
+ indices (p:: AbstractProdIterator ) = _prod_indices (p. a, p. b, iteratorsize (p. a), iteratorsize (p. b))
439
+ ndims (p:: AbstractProdIterator ) = length (indices (p))
435
440
436
441
# generic methods to handle size of Prod* types
437
442
_prod_size (a, :: HasShape ) = size (a)
@@ -445,6 +450,17 @@ _prod_size(a, b, ::HasShape, ::HasShape) = (size(a)..., size(b)...)
445
450
_prod_size (a, b, A, B) =
446
451
throw (ArgumentError (" Cannot construct size for objects of types $(typeof (a)) and $(typeof (b)) " ))
447
452
453
+ _prod_indices (a, :: HasShape ) = indices (a)
454
+ _prod_indices (a, :: HasLength ) = (OneTo (length (a)), )
455
+ _prod_indices (a, A) =
456
+ throw (ArgumentError (" Cannot compute indices for object of type $(typeof (a)) " ))
457
+ _prod_indices (a, b, :: HasLength , :: HasLength ) = (OneTo (length (a)), OneTo (length (b)))
458
+ _prod_indices (a, b, :: HasLength , :: HasShape ) = (OneTo (length (a)), indices (b)... )
459
+ _prod_indices (a, b, :: HasShape , :: HasLength ) = (indices (a)... , OneTo (length (b)))
460
+ _prod_indices (a, b, :: HasShape , :: HasShape ) = (indices (a)... , indices (b)... )
461
+ _prod_indices (a, b, A, B) =
462
+ throw (ArgumentError (" Cannot construct indices for objects of types $(typeof (a)) and $(typeof (b)) " ))
463
+
448
464
# one iterator
449
465
immutable Prod1{I} <: AbstractProdIterator
450
466
a:: I
@@ -453,6 +469,7 @@ product(a) = Prod1(a)
453
469
454
470
eltype {I} (:: Type{Prod1{I}} ) = Tuple{eltype (I)}
455
471
size (p:: Prod1 ) = _prod_size (p. a, iteratorsize (p. a))
472
+ indices (p:: Prod1 ) = _prod_indices (p. a, iteratorsize (p. a))
456
473
457
474
@inline start (p:: Prod1 ) = start (p. a)
458
475
@inline function next (p:: Prod1 , st)
0 commit comments