@@ -96,32 +96,23 @@ Base.isassigned(a::FixedSizeArray, i::Int) = isassigned(a.mem, i)
96
96
97
97
# safe product of a tuple of integers, for calculating dimensions size
98
98
99
- checked_dims_impl (a:: Int , :: Tuple{} , have_overflow:: Bool ) = (a, have_overflow)
100
- function checked_dims_impl (a:: Int , t:: Tuple{Int,Vararg{Int,N}} , have_overflow:: Bool ) where {N}
101
- b = first (t)
102
- (m, o) = Base. Checked. mul_with_overflow (a, b)
103
- r = Base. tail (t):: NTuple{N,Int}
104
- checked_dims_impl (m, r, have_overflow | o):: Tuple{Int,Bool}
105
- end
106
-
107
99
checked_dims (:: Tuple{} ) = 1
108
100
function checked_dims (t:: Tuple{Int,Vararg{Int,N}} ) where {N}
109
- any_is_zero = any (iszero, t) :: Bool
110
- any_is_negative = any ((x -> x < false ), t) :: Bool
111
- any_is_typemax = any ((x -> x == typemax (x)), t) :: Bool
112
- a = first (t)
113
- r = Base . tail (t) :: NTuple{N,Int}
114
- (product, have_overflow) = checked_dims_impl (a, r, false ) :: Tuple{Int,Bool}
115
- if any_is_negative
116
- throw ( ArgumentError ( " array dimension size can't be negative " ))
117
- end
118
- if any_is_typemax
119
- throw ( ArgumentError ( " array dimension size can't be the maximum representable value " ))
120
- end
121
- if have_overflow & ! any_is_zero
122
- throw (ArgumentError (" array dimensions too great, can't represent length " ))
101
+ product = checked_size_product (t)
102
+ if product isa Int
103
+ product
104
+ else
105
+ if product . any_is_negative
106
+ throw ( ArgumentError ( " array dimension size can't be negative " ))
107
+ end
108
+ if product . any_is_typemax
109
+ throw ( ArgumentError ( " array dimension size can't be the maximum representable value " ))
110
+ end
111
+ if product . is_not_representable
112
+ throw ( ArgumentError ( " array dimensions too great, can't represent length " ))
113
+ end
114
+ throw (ArgumentError (" unexpected " ))
123
115
end
124
- product
125
116
end
126
117
127
118
# broadcasting
0 commit comments