Skip to content

Commit ebd92dd

Browse files
committed
various spacing and outline changes, some @inlines removed
1 parent 8cb25b8 commit ebd92dd

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

src/TupleTools.jl

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,51 @@ function deleteat(t::Tuple, I::Tuple{Int, Int, Vararg{Int}})
8282
any(i->!(1 <= i <= length(t)), I) && throw(BoundsError(t, I))
8383
_deleteat(t, sort(I, rev = true))
8484
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))
8687
@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))
8889

8990
@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
9193

9294
"""
9395
insertat(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
9496
95-
9697
Insert the elements of tuple `t2` at location `i` in `t`, i.e. the output tuple will
9798
look as (t[1:i-1]..., t2..., t[i+1:end]). Note that element `t[i]` is deleted. Use
9899
`setindex` for setting a single value at position `i`, or `insertafter(t, i, t2)` to
99100
insert the contents of `t2` in between element `i` and `i+1` in `t`.
100101
"""
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)...)
103106
@inline _insertat(t::Tuple{}, i::Int, t2::Tuple) = throw(BoundsError(t, i))
104107

105108
"""
106109
insertafter(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
107110
108-
109111
Insert the elements of tuple `t2` after location `i` in `t`, i.e. the output tuple will
110112
look as (t[1:i]..., t2..., t[i+1:end]). Use index `i=0` or just `(t2..., t...)` to insert
111113
`t2` in front of `t`; also see `insertat` to overwrite the element at position `i`.
112114
"""
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))
116121

117122
"""
118123
sum(t::Tuple)
119124
120125
Returns the sum of the element of a tuple, or `0` for an empty tuple.
121126
"""
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))
125130

126131
"""
127132
cumsum(t::Tuple)
@@ -140,9 +145,9 @@ cumsum(t::Tuple{}) = t
140145
141146
Returns the product of the elements of a tuple, or `1` for an empty tuple.
142147
"""
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))
146151

147152
"""
148153
cumprod(t::Tuple)
@@ -151,7 +156,7 @@ Returns the cumulative product of the elements of a tuple, or `()` for an empty
151156
"""
152157
function cumprod(t::Tuple)
153158
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)...))...)
155160
end
156161
cumprod(t::Tuple{Any}) = t
157162
cumprod(t::Tuple{}) = t
@@ -161,17 +166,16 @@ cumprod(t::Tuple{}) = t
161166
162167
Returns the smallest element of a tuple
163168
"""
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)))
166171

167172
"""
168173
maximum(t::Tuple)
169174
170175
Returns the largest element of a tuple
171176
"""
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)))
175179

176180
"""
177181
argmin(t::Tuple)
@@ -181,7 +185,6 @@ minimal elements, then the first one will be returned.
181185
"""
182186
argmin(t::Tuple) = findmin(t)[2]
183187

184-
185188
"""
186189
argmax(t::Tuple)
187190
@@ -198,7 +201,7 @@ minimal elements, then the first one will be returned.
198201
"""
199202
findmin(t::Tuple{Any}) = (t[1], 1)
200203
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)
202205
@inline function _findmin(t::Tuple, s, v, i)
203206
if t[1] < v
204207
_findmin(tail(t), s+1, t[1], s)
@@ -215,7 +218,7 @@ maximal elements, then the first one will be returned.
215218
"""
216219
findmax(::Tuple{Any}) = (t[1], 1)
217220
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)
219222
@inline function _findmax(t::Tuple, s, v, i)
220223
if t[1] > v
221224
_findmax(tail(t), s+1, t[1], s)
@@ -224,8 +227,6 @@ findmax(t::Tuple) = _findmax(tail(t),2,t[1],1)
224227
end
225228
end
226229

227-
228-
229230
"""
230231
sort(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple
231232
@@ -273,19 +274,23 @@ end
273274
274275
Get the indices `t[i] for i in I`, again as tuple.
275276
"""
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{}) = ()
278280

279281
"""
280282
permute(t::Tuple, p) -> ::Tuple
281283
282284
Permute the elements of tuple `t` according to the permutation in `p`.
283285
"""
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"))
286291

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))
289294

290295
"""
291296
isperm(p) -> ::Bool
@@ -308,7 +313,7 @@ end
308313
309314
Inverse permutation of a permutation `p`.
310315
"""
311-
invperm(p::Tuple{Vararg{Int}}) = sortperm(p)
316+
invperm(p::Tuple{Vararg{Int}}) = _sortperm(p)
312317

313318
"""
314319
diff(v::Tuple) -> Tuple

0 commit comments

Comments
 (0)