@@ -82,46 +82,51 @@ function deleteat(t::Tuple, I::Tuple{Int, Int, Vararg{Int}})
82
82
any (i-> ! (1 <= i <= length (t)), I) && throw (BoundsError (t, I))
83
83
_deleteat (t, sort (I, rev = true ))
84
84
end
85
- deleteat (t:: Tuple , i:: Int ) = 1 <= i <= length (t) ? _deleteat (t, i) : throw (BoundsError (t, i))
85
+ deleteat (t:: Tuple , i:: Int ) =
86
+ 1 <= i <= length (t) ? _deleteat (t, i) : throw (BoundsError (t, i))
86
87
@inline _deleteat (t:: Tuple , i:: Int ) = i == 1 ? tail (t) : (t[1 ], _deleteat (tail (t), i- 1 )... )
87
- @inline _deleteat (t:: Tuple{} , i:: Int ) = throw (BoundsError (t, i))
88
+ # @inline _deleteat(t::Tuple{}, i::Int) = throw(BoundsError(t, i))
88
89
89
90
@inline _deleteat (t:: Tuple , I:: Tuple{Int} ) = _deleteat (t, I[1 ])
90
- @inline _deleteat (t:: Tuple , I:: Tuple{Int,Int,Vararg{Int}} ) = _deleteat (_deleteat (t, I[1 ]), tail (I)) # assumes sorted from big to small
91
+ @inline _deleteat (t:: Tuple , I:: Tuple{Int,Int,Vararg{Int}} ) =
92
+ _deleteat (_deleteat (t, I[1 ]), tail (I)) # assumes sorted from big to small
91
93
92
94
"""
93
95
insertat(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
94
96
95
-
96
97
Insert the elements of tuple `t2` at location `i` in `t`, i.e. the output tuple will
97
98
look as (t[1:i-1]..., t2..., t[i+1:end]). Note that element `t[i]` is deleted. Use
98
99
`setindex` for setting a single value at position `i`, or `insertafter(t, i, t2)` to
99
100
insert the contents of `t2` in between element `i` and `i+1` in `t`.
100
101
"""
101
- @inline insertat (t:: Tuple , i:: Int , t2:: Tuple ) = 1 <= i <= length (t) ? _insertat (t, i, t2) : throw (BoundsError (t, i))
102
- @inline _insertat (t:: Tuple , i:: Int , t2:: Tuple ) = i == 1 ? (t2... , tail (t)... ) : (t[1 ], _insertat (tail (t), i- 1 , t2)... )
102
+ insertat (t:: Tuple , i:: Int , t2:: Tuple ) =
103
+ 1 <= i <= length (t) ? _insertat (t, i, t2) : throw (BoundsError (t, i))
104
+ @inline _insertat (t:: Tuple , i:: Int , t2:: Tuple ) =
105
+ i == 1 ? (t2... , tail (t)... ) : (t[1 ], _insertat (tail (t), i- 1 , t2)... )
103
106
@inline _insertat (t:: Tuple{} , i:: Int , t2:: Tuple ) = throw (BoundsError (t, i))
104
107
105
108
"""
106
109
insertafter(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
107
110
108
-
109
111
Insert the elements of tuple `t2` after location `i` in `t`, i.e. the output tuple will
110
112
look as (t[1:i]..., t2..., t[i+1:end]). Use index `i=0` or just `(t2..., t...)` to insert
111
113
`t2` in front of `t`; also see `insertat` to overwrite the element at position `i`.
112
114
"""
113
- @inline insertafter (t:: Tuple , i:: Int , t2:: Tuple ) = 0 <= i <= length (t) ? _insertafter (t, i, t2) : throw (BoundsError (t, i))
114
- @inline _insertafter (t:: Tuple , i:: Int , t2:: Tuple ) = i == 0 ? (t2... , t... ) : (t[1 ], _insertafter (tail (t), i- 1 , t2)... )
115
- @inline _insertafter (t:: Tuple{} , i:: Int , t2:: Tuple ) = i == 0 ? t2 : throw (BoundsError (t, i))
115
+ insertafter (t:: Tuple , i:: Int , t2:: Tuple ) =
116
+ 0 <= i <= length (t) ? _insertafter (t, i, t2) : throw (BoundsError (t, i))
117
+ @inline _insertafter (t:: Tuple , i:: Int , t2:: Tuple ) =
118
+ i == 0 ? (t2... , t... ) : (t[1 ], _insertafter (tail (t), i- 1 , t2)... )
119
+ @inline _insertafter (t:: Tuple{} , i:: Int , t2:: Tuple ) =
120
+ i == 0 ? t2 : throw (BoundsError (t, i))
116
121
117
122
"""
118
123
sum(t::Tuple)
119
124
120
125
Returns the sum of the element of a tuple, or `0` for an empty tuple.
121
126
"""
122
- @inline sum (t:: Tuple{} ) = 0
123
- @inline sum (t:: Tuple{Any} ) = t[1 ]
124
- @inline sum (t:: Tuple ) = t[1 ]+ sum (tail (t))
127
+ sum (t:: Tuple{} ) = 0
128
+ sum (t:: Tuple{Any} ) = t[1 ]
129
+ sum (t:: Tuple ) = t[1 ]+ sum (tail (t))
125
130
126
131
"""
127
132
cumsum(t::Tuple)
@@ -140,9 +145,9 @@ cumsum(t::Tuple{}) = t
140
145
141
146
Returns the product of the elements of a tuple, or `1` for an empty tuple.
142
147
"""
143
- @inline prod (t:: Tuple{} ) = 1
144
- @inline prod (t:: Tuple{Any} ) = t[1 ]
145
- @inline prod (t:: Tuple ) = t[1 ]* prod (tail (t))
148
+ prod (t:: Tuple{} ) = 1
149
+ prod (t:: Tuple{Any} ) = t[1 ]
150
+ prod (t:: Tuple ) = t[1 ]* prod (tail (t))
146
151
147
152
"""
148
153
cumprod(t::Tuple)
@@ -151,7 +156,7 @@ Returns the cumulative product of the elements of a tuple, or `()` for an empty
151
156
"""
152
157
function cumprod (t:: Tuple )
153
158
t_1, t_tail = first (t), tail (t)
154
- return (t_1,cumprod ((t_1* first (t_tail),tail (t_tail)... ))... )
159
+ return (t_1, cumprod ((t_1* first (t_tail), tail (t_tail)... ))... )
155
160
end
156
161
cumprod (t:: Tuple{Any} ) = t
157
162
cumprod (t:: Tuple{} ) = t
@@ -161,17 +166,16 @@ cumprod(t::Tuple{}) = t
161
166
162
167
Returns the smallest element of a tuple
163
168
"""
164
- @inline minimum (t:: Tuple{Any} ) = t[1 ]
165
- @inline minimum (t:: Tuple ) = min (t[1 ], minimum (tail (t)))
169
+ minimum (t:: Tuple{Any} ) = t[1 ]
170
+ minimum (t:: Tuple ) = min (t[1 ], minimum (tail (t)))
166
171
167
172
"""
168
173
maximum(t::Tuple)
169
174
170
175
Returns the largest element of a tuple
171
176
"""
172
- @inline maximum (t:: Tuple{Any} ) = t[1 ]
173
- @inline maximum (t:: Tuple ) = max (t[1 ], maximum (tail (t)))
174
-
177
+ maximum (t:: Tuple{Any} ) = t[1 ]
178
+ maximum (t:: Tuple ) = max (t[1 ], maximum (tail (t)))
175
179
176
180
"""
177
181
argmin(t::Tuple)
@@ -181,7 +185,6 @@ minimal elements, then the first one will be returned.
181
185
"""
182
186
argmin (t:: Tuple ) = findmin (t)[2 ]
183
187
184
-
185
188
"""
186
189
argmax(t::Tuple)
187
190
@@ -198,7 +201,7 @@ minimal elements, then the first one will be returned.
198
201
"""
199
202
findmin (t:: Tuple{Any} ) = (t[1 ], 1 )
200
203
findmin (t:: Tuple ) = _findmin (tail (t),2 ,t[1 ],1 )
201
- @inline _findmin (t:: Tuple{} , s, v, i) = (v, i)
204
+ _findmin (t:: Tuple{} , s, v, i) = (v, i)
202
205
@inline function _findmin (t:: Tuple , s, v, i)
203
206
if t[1 ] < v
204
207
_findmin (tail (t), s+ 1 , t[1 ], s)
@@ -215,7 +218,7 @@ maximal elements, then the first one will be returned.
215
218
"""
216
219
findmax (:: Tuple{Any} ) = (t[1 ], 1 )
217
220
findmax (t:: Tuple ) = _findmax (tail (t),2 ,t[1 ],1 )
218
- @inline _findmax (t:: Tuple{} , s, v, i) = (v, i)
221
+ _findmax (t:: Tuple{} , s, v, i) = (v, i)
219
222
@inline function _findmax (t:: Tuple , s, v, i)
220
223
if t[1 ] > v
221
224
_findmax (tail (t), s+ 1 , t[1 ], s)
@@ -224,8 +227,6 @@ findmax(t::Tuple) = _findmax(tail(t),2,t[1],1)
224
227
end
225
228
end
226
229
227
-
228
-
229
230
"""
230
231
sort(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple
231
232
@@ -273,19 +274,23 @@ end
273
274
274
275
Get the indices `t[i] for i in I`, again as tuple.
275
276
"""
276
- @inline getindices (t:: Tuple , ind:: Tuple{Vararg{Int}} ) = (t[ind[1 ]], getindices (t, tail (ind))... )
277
- @inline getindices (t:: Tuple , ind:: Tuple{} ) = ()
277
+ getindices (t:: Tuple , ind:: Tuple{Vararg{Int}} ) =
278
+ (t[ind[1 ]], getindices (t, tail (ind))... )
279
+ getindices (t:: Tuple , ind:: Tuple{} ) = ()
278
280
279
281
"""
280
282
permute(t::Tuple, p) -> ::Tuple
281
283
282
284
Permute the elements of tuple `t` according to the permutation in `p`.
283
285
"""
284
- @inline permute (t:: NTuple{N,Any} , p:: NTuple{N,Int} ) where {N} = isperm (p) ? _permute (t, p) : throw (ArgumentError (" not a valid permutation: $p " ))
285
- @inline permute (t:: NTuple{N,Any} , p) where {N} = isperm (p) && length (p) == N ? _permute (t,p) : throw (ArgumentError (" not a valid permutation: $p " ))
286
+ permute (t:: NTuple{N,Any} , p:: NTuple{N,Int} ) where {N} =
287
+ isperm (p) ? _permute (t, p) : throw (ArgumentError (" not a valid permutation: $p " ))
288
+ permute (t:: NTuple{N,Any} , p) where {N} =
289
+ isperm (p) && length (p) == N ? _permute (t, p) :
290
+ throw (ArgumentError (" not a valid permutation: $p " ))
286
291
287
- @inline _permute (t:: NTuple{N,Any} , p:: NTuple{N,Int} ) where {N} = getindices (t, p)
288
- @inline _permute (t:: NTuple{N,Any} , p) where {N} = ntuple (n-> t[p[n]], StaticLength (N))
292
+ _permute (t:: NTuple{N,Any} , p:: NTuple{N,Int} ) where {N} = getindices (t, p)
293
+ _permute (t:: NTuple{N,Any} , p) where {N} = ntuple (n-> t[p[n]], StaticLength (N))
289
294
290
295
"""
291
296
isperm(p) -> ::Bool
308
313
309
314
Inverse permutation of a permutation `p`.
310
315
"""
311
- invperm (p:: Tuple{Vararg{Int}} ) = sortperm (p)
316
+ invperm (p:: Tuple{Vararg{Int}} ) = _sortperm (p)
312
317
313
318
"""
314
319
diff(v::Tuple) -> Tuple
0 commit comments