|
3 | 3 | [](https://travis-ci.org/tkoolen/TypeSortedCollections.jl)
|
4 | 4 | [](http://codecov.io/github/tkoolen/TypeSortedCollections.jl?branch=master)
|
5 | 5 |
|
6 |
| -TypeSortedCollections provides the `TypeSortedCollection` type, which can be used to store type-heterogeneous data in a way that allows operations on the data to be performed in a type-stable manner. It does so by sorting a type-heterogeneous input collection by type upon construction, and storing these elements in a `Tuple` of concretely typed `Vector`s, one for each type. TypeSortedCollections provides type stable methods for `map!`, `foreach`, and `mapreduce` that take at least one `TypeSortedCollection`. |
| 6 | +TypeSortedCollections provides the `TypeSortedCollection` type, which can be used to store type-heterogeneous data in a way that allows operations on the data to be performed in a type-stable manner. It does so by sorting a type-heterogeneous input collection by type upon construction, and storing these elements in a `Tuple` of concretely typed `Vector`s, one for each type. TypeSortedCollections provides type stable methods for `map!`, `foreach`, `broadcast!`, and `mapreduce` that take at least one `TypeSortedCollection`. |
7 | 7 |
|
8 | 8 | An example:
|
9 | 9 | ```julia
|
@@ -40,7 +40,7 @@ Note that construction of a `TypeSortedCollection` is of course not type stable,
|
40 | 40 | See also [FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl) for a solution to the related problem of storing and calling multiple callables in a type-stable manner, and [Unrolled.jl](https://github.com/cstjean/Unrolled.jl) for a macro-based solution.
|
41 | 41 |
|
42 | 42 | # Iteration order
|
43 |
| -By default, `TypeSortedCollection`s do not preserve iteration order, in the sense that the order in which elements are processed in `map!`, `foreach`, and `mapreduce` will not be the same as if these functions were called on the original type-heterogeneous vector: |
| 43 | +By default, `TypeSortedCollection`s do not preserve iteration order, in the sense that the order in which elements are processed in `map!`, `foreach`, `broadcast!`, and `mapreduce` will not be the same as if these functions were called on the original type-heterogeneous vector: |
44 | 44 | ```julia
|
45 | 45 | julia> xs = Number[1.; 2; 3.];
|
46 | 46 |
|
@@ -75,7 +75,7 @@ julia> results = similar(xs);
|
75 | 75 | julia> map!(identity, results, sortedxs) # results of applying `identity` end up in the right location
|
76 | 76 | 3-element Array{Number,1}:
|
77 | 77 | 1.0
|
78 |
| - 2 |
| 78 | + 2 |
79 | 79 | 3.0
|
80 | 80 | ```
|
81 | 81 |
|
@@ -105,3 +105,24 @@ julia> map!(*, results, sortedxs, sortedys)
|
105 | 105 | 9.0
|
106 | 106 | 16.0
|
107 | 107 | ```
|
| 108 | + |
| 109 | +# Broadcasting |
| 110 | +Broadcasting (in place) is implemented for `AbstractVector` return types: |
| 111 | +```julia |
| 112 | +julia> x = 4; |
| 113 | + |
| 114 | +julia> ys = Number[1.; 2; 3]; |
| 115 | + |
| 116 | +julia> sortedys = TypeSortedCollection(ys); |
| 117 | + |
| 118 | +julia> results = similar(ys, Float64); |
| 119 | + |
| 120 | +julia> results .= x .* sortedys |
| 121 | +3-element Array{Float64,1}: |
| 122 | + 4.0 |
| 123 | + 8.0 |
| 124 | + 12.0 |
| 125 | + |
| 126 | +julia> @allocated results .= x .* sortedys |
| 127 | +0 |
| 128 | +``` |
0 commit comments