Skip to content

Commit bda0668

Browse files
committed
some updates, new method insertafter
1 parent a898092 commit bda0668

File tree

4 files changed

+163
-35
lines changed

4 files changed

+163
-35
lines changed

README.md

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
[![Build Status](https://travis-ci.org/Jutho/TupleTools.jl.svg?branch=master)](https://travis-ci.org/Jutho/TupleTools.jl) [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md) [![Coverage Status](https://coveralls.io/repos/Jutho/TupleTools.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/Jutho/TupleTools.jl?branch=master) [![codecov.io](http://codecov.io/github/Jutho/TupleTools.jl/coverage.svg?branch=master)](http://codecov.io/github/Jutho/TupleTools.jl?branch=master)
88

99

10-
A bunch of tools for using tuples (mostly homogeneous tuples `NTuple{N}`) as a collection and performing a number of operations with an inferrable result, typically also an `NTuple{M}` with inferrable length `M`. Type inference breaks down if some of the final or intermediate tuples exceed `MAX_TUPLETYPE_LEN`, meaning inference typically works up to output tuples of length `13` or `14`. Chosen implementations are typically faster than the corresponding functions in base for those small tuple lengths, but can be slower for larger tuples. Inference also breaks down for most functions in case of inhomogeneous tuples.
10+
A bunch of tools for using tuples (mostly homogeneous tuples `NTuple{N}`) as a collection and performing a number of operations with an inferrable result, typically also an `NTuple{M}` with inferable length `M`. Type inference breaks down if some of the final or intermediate tuples exceed `MAX_TUPLETYPE_LEN`, meaning inference typically works up to output tuples of length `13` or `14`. Chosen implementations are typically faster than the corresponding functions in base for those small tuple lengths, but can be slower for larger tuples. Inference also breaks down for most functions in case of inhomogeneous tuples. Some algorithms also provide reasonable defaults assuming that they are used for tuples of `Int`s, i.e. `TupleTools.sum(()) = 0` or `TupleTools.prod(()) = 1` (whereas the corresponding Base functions would error). This originates from the assumption that these methods are used to operate on tuples of e.g. sizes, indices or strides of multidimensional arrays.
1111

1212

13-
Note that none of the following functions are exported, since their name often collides with the equivalent from `Base`.
13+
Note that none of the following functions are exported, since their name often collides with the equivalent functions (with different implementations) in `Base`.
1414

1515

1616
<a id='Types-1'></a>
@@ -39,6 +39,9 @@ StaticLength(N₁) - StaticLength(N₂) == StaticLength(max(0, N₁-N₂))
3939
```
4040

4141

42+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L8-L22' class='documenter-source'>source</a><br>
43+
44+
4245
<a id='Functions-1'></a>
4346

4447
## Functions
@@ -54,6 +57,9 @@ tail2(t::Tuple) -> ::Tuple
5457

5558
Returns a tuple with the first two elements stripped, equivalent to `tail(tail(t))`
5659

60+
61+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L37-L41' class='documenter-source'>source</a><br>
62+
5763
<a id='TupleTools.unsafe_tail' href='#TupleTools.unsafe_tail'>#</a>
5864
**`TupleTools.unsafe_tail`** &mdash; *Function*.
5965

@@ -65,6 +71,9 @@ unsafe_tail(t::Tuple) -> ::Tuple
6571

6672
Returns a tuple with the first element stripped, similar to `tail(t)`, but does not error on an empty tuple (instead returning an empty tuple again). An empty tuple is thus the fixed point of this function.
6773

74+
75+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L44-L50' class='documenter-source'>source</a><br>
76+
6877
<a id='TupleTools.unsafe_front' href='#TupleTools.unsafe_front'>#</a>
6978
**`TupleTools.unsafe_front`** &mdash; *Function*.
7079

@@ -76,6 +85,9 @@ unsafe_front(t::Tuple) -> ::Tuple
7685

7786
Returns a tuple with the last element stripped, similar to `front(t)`, but does not error on an empty tuple (instead returning an empty tuple again). An empty tuple is thus the fixed point of this function.
7887

88+
89+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L54-L60' class='documenter-source'>source</a><br>
90+
7991
<a id='TupleTools.getindices' href='#TupleTools.getindices'>#</a>
8092
**`TupleTools.getindices`** &mdash; *Function*.
8193

@@ -87,6 +99,9 @@ getindices(t::Tuple, I::Tuple{Vararg{Int}}) -> ::Tuple
8799

88100
Get the indices `t[i] for i in I`, again as tuple.
89101

102+
103+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L288-L292' class='documenter-source'>source</a><br>
104+
90105
<a id='TupleTools.deleteat' href='#TupleTools.deleteat'>#</a>
91106
**`TupleTools.deleteat`** &mdash; *Function*.
92107

@@ -99,6 +114,9 @@ deleteat(t::Tuple, I::Tuple{Vararg{Int}}) -> ::Tuple
99114

100115
Delete the element at location `i` in `t`; if a list `I` of indices is specified (again as a tuple), the elements of these different positions are deleted.
101116

117+
118+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L76-L82' class='documenter-source'>source</a><br>
119+
102120
<a id='TupleTools.insertat' href='#TupleTools.insertat'>#</a>
103121
**`TupleTools.insertat`** &mdash; *Function*.
104122

@@ -108,7 +126,24 @@ Delete the element at location `i` in `t`; if a list `I` of indices is specified
108126
insertat(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
109127
```
110128

111-
Insert the elements of tuple t2 at location `i` in `t`, i.e. the output tuple will look as (t[1:i-1]..., t2..., t[i+1:end]). Note that element `t[i]` is deleted. Use `setindex` for setting a single value at position `i`.
129+
Insert the elements of tuple `t2` at location `i` in `t`, i.e. the output tuple will look as (t[1:i-1]..., t2..., t[i+1:end]). Note that element `t[i]` is deleted. Use `setindex` for setting a single value at position `i`, or `insertafter(t, i, t2)` to insert the contents of `t2` in between element `i` and `i+1` in `t`.
130+
131+
132+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L97-L105' class='documenter-source'>source</a><br>
133+
134+
<a id='TupleTools.insertafter' href='#TupleTools.insertafter'>#</a>
135+
**`TupleTools.insertafter`** &mdash; *Function*.
136+
137+
138+
139+
```
140+
insertafter(t::Tuple, i::Int, t2::Tuple) -> ::Tuple
141+
```
142+
143+
Insert the elements of tuple `t2` after location `i` in `t`, i.e. the output tuple will look as (t[1:i]..., t2..., t[i+1:end]). Use index `i=0` or just `(t2..., t...)` to insert `t2` in front of `t`; also see `insertat` to overwrite the element at position `i`.
144+
145+
146+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L110-L117' class='documenter-source'>source</a><br>
112147

113148
<a id='TupleTools.vcat' href='#TupleTools.vcat'>#</a>
114149
**`TupleTools.vcat`** &mdash; *Function*.
@@ -121,6 +156,9 @@ vcat(args...) -> ::Tuple
121156

122157
Like `vcat` for tuples, concatenates a combination of tuple arguments and non-tuple arguments into a single tuple. Only works one level deep, i.e. tuples in tuples are not expanded.
123158

159+
160+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L64-L70' class='documenter-source'>source</a><br>
161+
124162
<a id='TupleTools.sum' href='#TupleTools.sum'>#</a>
125163
**`TupleTools.sum`** &mdash; *Function*.
126164

@@ -132,6 +170,23 @@ sum(t::Tuple)
132170

133171
Returns the sum of the element of a tuple, or `0` for an empty tuple.
134172

173+
174+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L122-L126' class='documenter-source'>source</a><br>
175+
176+
<a id='Base.cumsum' href='#Base.cumsum'>#</a>
177+
**`Base.cumsum`** &mdash; *Function*.
178+
179+
180+
181+
```
182+
cumsum(t::Tuple)
183+
```
184+
185+
Returns the cumulative sum of the elements of a tuple, or `()` for an empty tuple.
186+
187+
188+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L131-L135' class='documenter-source'>source</a><br>
189+
135190
<a id='TupleTools.prod' href='#TupleTools.prod'>#</a>
136191
**`TupleTools.prod`** &mdash; *Function*.
137192

@@ -143,6 +198,23 @@ prod(t::Tuple)
143198

144199
Returns the product of the elements of a tuple, or `1` for an empty tuple.
145200

201+
202+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L143-L147' class='documenter-source'>source</a><br>
203+
204+
<a id='Base.cumprod' href='#Base.cumprod'>#</a>
205+
**`Base.cumprod`** &mdash; *Function*.
206+
207+
208+
209+
```
210+
cumprod(t::Tuple)
211+
```
212+
213+
Returns the cumulative product of the elements of a tuple, or `()` for an empty tuple.
214+
215+
216+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L152-L156' class='documenter-source'>source</a><br>
217+
146218
<a id='TupleTools.minimum' href='#TupleTools.minimum'>#</a>
147219
**`TupleTools.minimum`** &mdash; *Function*.
148220

@@ -154,6 +226,9 @@ minimum(t::Tuple)
154226

155227
Returns the smallest element of a tuple
156228

229+
230+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L164-L168' class='documenter-source'>source</a><br>
231+
157232
<a id='TupleTools.maximum' href='#TupleTools.maximum'>#</a>
158233
**`TupleTools.maximum`** &mdash; *Function*.
159234

@@ -165,6 +240,9 @@ maximum(t::Tuple)
165240

166241
Returns the largest element of a tuple
167242

243+
244+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L172-L176' class='documenter-source'>source</a><br>
245+
168246
<a id='TupleTools.findmin' href='#TupleTools.findmin'>#</a>
169247
**`TupleTools.findmin`** &mdash; *Function*.
170248

@@ -176,6 +254,9 @@ findmin(t::Tuple)
176254

177255
Returns the value and index of the minimum element in a tuple. If there are multiple minimal elements, then the first one will be returned.
178256

257+
258+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L198-L203' class='documenter-source'>source</a><br>
259+
179260
<a id='TupleTools.findmax' href='#TupleTools.findmax'>#</a>
180261
**`TupleTools.findmax`** &mdash; *Function*.
181262

@@ -187,28 +268,37 @@ findmax(t::Tuple)
187268

188269
Returns the value and index of the maximum element in a tuple. If there are multiple maximal elements, then the first one will be returned.
189270

190-
<a id='TupleTools.indmin' href='#TupleTools.indmin'>#</a>
191-
**`TupleTools.indmin`** &mdash; *Function*.
271+
272+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L215-L220' class='documenter-source'>source</a><br>
273+
274+
<a id='TupleTools.argmin' href='#TupleTools.argmin'>#</a>
275+
**`TupleTools.argmin`** &mdash; *Function*.
192276

193277

194278

195279
```
196-
indmin(t::Tuple)
280+
argmin(t::Tuple)
197281
```
198282

199283
Returns the index of the minimum element in a tuple. If there are multiple minimal elements, then the first one will be returned.
200284

201-
<a id='TupleTools.indmax' href='#TupleTools.indmax'>#</a>
202-
**`TupleTools.indmax`** &mdash; *Function*.
285+
286+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L181-L186' class='documenter-source'>source</a><br>
287+
288+
<a id='TupleTools.argmax' href='#TupleTools.argmax'>#</a>
289+
**`TupleTools.argmax`** &mdash; *Function*.
203290

204291

205292

206293
```
207-
indmax(t::Tuple)
294+
argmax(t::Tuple)
208295
```
209296

210297
Returns the index of the maximum element in a tuple. If there are multiple minimal elements, then the first one will be returned.
211298

299+
300+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L190-L195' class='documenter-source'>source</a><br>
301+
212302
<a id='TupleTools.sort' href='#TupleTools.sort'>#</a>
213303
**`TupleTools.sort`** &mdash; *Function*.
214304

@@ -220,6 +310,9 @@ sort(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple
220310

221311
Sorts the tuple `t`.
222312

313+
314+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L234-L238' class='documenter-source'>source</a><br>
315+
223316
<a id='TupleTools.sortperm' href='#TupleTools.sortperm'>#</a>
224317
**`TupleTools.sortperm`** &mdash; *Function*.
225318

@@ -231,6 +324,23 @@ sortperm(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple
231324

232325
Computes a tuple that contains the permutation required to sort `t`.
233326

327+
328+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L260-L265' class='documenter-source'>source</a><br>
329+
330+
<a id='TupleTools.isperm' href='#TupleTools.isperm'>#</a>
331+
**`TupleTools.isperm`** &mdash; *Function*.
332+
333+
334+
335+
```
336+
isperm(p) -> ::Bool
337+
```
338+
339+
A non-allocating alternative to Base.isperm(p) that is much faster for small permutations.
340+
341+
342+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L307-L311' class='documenter-source'>source</a><br>
343+
234344
<a id='TupleTools.invperm' href='#TupleTools.invperm'>#</a>
235345
**`TupleTools.invperm`** &mdash; *Function*.
236346

@@ -242,6 +352,9 @@ invperm(p::NTuple{N,Int}) -> ::NTuple{N,Int}
242352

243353
Inverse permutation of a permutation `p`.
244354

355+
356+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L323-L327' class='documenter-source'>source</a><br>
357+
245358
<a id='TupleTools.permute' href='#TupleTools.permute'>#</a>
246359
**`TupleTools.permute`** &mdash; *Function*.
247360

@@ -252,3 +365,7 @@ permute(t::Tuple, p) -> ::Tuple
252365
```
253366

254367
Permute the elements of tuple `t` according to the permutation in `p`.
368+
369+
370+
<a target='_blank' href='https://github.com/Jutho/TupleTools.jl/blob/a898092ea5bed41dd20e64ef8e6d7010b2e12d64/src/TupleTools.jl#L296-L300' class='documenter-source'>source</a><br>
371+

docs/src/index.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# TupleTools.jl
22

3-
[![Build Status](https://travis-ci.org/Jutho/TupleTools.jl.svg?branch=master)](https://travis-ci.org/Jutho/TupleTools.jl)
4-
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
5-
[![Coverage Status](https://coveralls.io/repos/Jutho/TupleTools.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/Jutho/TupleTools.jl?branch=master)
6-
[![codecov.io](http://codecov.io/github/Jutho/TupleTools.jl/coverage.svg?branch=master)](http://codecov.io/github/Jutho/TupleTools.jl?branch=master)
3+
[![Build Status](https://travis-ci.org/Jutho/TupleTools.jl.svg?branch=master)](https://travis-ci.org/Jutho/TupleTools.jl) [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md) [![Coverage Status](https://coveralls.io/repos/Jutho/TupleTools.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/Jutho/TupleTools.jl?branch=master) [![codecov.io](http://codecov.io/github/Jutho/TupleTools.jl/coverage.svg?branch=master)](http://codecov.io/github/Jutho/TupleTools.jl?branch=master)
74

8-
A bunch of tools for using tuples (mostly homogeneous tuples `NTuple{N}`) as a collection
9-
and performing a number of operations with an inferrable result, typically also an `NTuple{M}`
10-
with inferrable length `M`. Type inference breaks down if some of the final or intermediate tuples
11-
exceed `MAX_TUPLETYPE_LEN`, meaning inference typically works up to output tuples of
12-
length `13` or `14`. Chosen implementations are typically faster than the corresponding functions
13-
in base for those small tuple lengths, but can be slower for larger tuples. Inference also breaks
14-
down for most functions in case of inhomogeneous tuples.
155

16-
Note that none of the following functions are exported, since their name often collides with the equivalent from `Base`.
6+
A bunch of tools for using tuples (mostly homogeneous tuples `NTuple{N}`) as a collection and performing a number of operations with an inferrable result, typically also an `NTuple{M}` with inferable length `M`. Type inference breaks down if some of the final or intermediate tuples exceed `MAX_TUPLETYPE_LEN`, meaning inference typically works up to output tuples of length `13` or `14`. Chosen implementations are typically faster than the corresponding functions in base for those small tuple lengths, but can be slower for larger tuples. Inference also breaks down for most functions in case of inhomogeneous tuples. Some algorithms
7+
also provide reasonable defaults assuming that they are used for tuples of `Int`s, i.e. `TupleTools.sum(()) = 0` or `TupleTools.prod(()) = 1` (whereas the corresponding Base functions would error). This originates from the assumption that these methods are used to
8+
operate on tuples of e.g. sizes, indices or strides of multidimensional arrays.
9+
10+
Note that none of the following functions are exported, since their name often collides with the equivalent functions (with different implementations) in `Base`.
1711

1812
## Types
1913

@@ -36,8 +30,10 @@ TupleTools.getindices
3630
```@docs
3731
TupleTools.deleteat
3832
TupleTools.insertat
33+
TupleTools.insertafter
3934
TupleTools.vcat
4035
```
36+
4137
```@docs
4238
TupleTools.sum
4339
TupleTools.cumsum
@@ -50,16 +46,14 @@ TupleTools.minimum
5046
TupleTools.maximum
5147
TupleTools.findmin
5248
TupleTools.findmax
53-
TupleTools.indmin
54-
TupleTools.indmax
49+
TupleTools.argmin
50+
TupleTools.argmax
5551
```
5652

5753
```@docs
5854
TupleTools.sort
5955
TupleTools.sortperm
60-
```
61-
62-
```@docs
56+
TupleTools.isperm
6357
TupleTools.invperm
6458
TupleTools.permute
6559
```

0 commit comments

Comments
 (0)