Skip to content

Commit d15221a

Browse files
committed
Better comments for apply.jl and applyreduce.jl
1 parent 1c0a0e4 commit d15221a

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

GeometryOpsCore/src/apply.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ Functions like [`flip`](@ref), [`reproject`](@ref), [`transform`](@ref), even [`
3030
using the `apply` framework. Similarly, [`centroid`](@ref), [`area`](@ref) and [`distance`](@ref) have been implemented using the
3131
[`applyreduce`](@ref) framework.
3232
33-
## Docstrings
34-
35-
### Functions
36-
3733
```@docs; collapse=true, canonical=false
3834
apply
39-
applyreduce
4035
```
4136
42-
=#
4337
44-
#=
4538
## What is `apply`?
4639
4740
`apply` applies some function to every geometry matching the `Target`
@@ -69,7 +62,7 @@ Be careful making a union across "levels" of nesting, e.g.
6962
`Union{FeatureTrait,PolygonTrait}`, as `_apply` will just never reach
7063
`PolygonTrait` when all the polygons are wrapped in a `FeatureTrait` object.
7164
72-
## Embedding:
65+
### Embedding
7366
7467
`extent` and `crs` can be embedded in all geometries, features, and
7568
feature collections as part of `apply`. Geometries deeper than `Target`
@@ -78,14 +71,30 @@ will of course not have new `extent` or `crs` embedded.
7871
- `calc_extent` signals to recalculate an `Extent` and embed it.
7972
- `crs` will be embedded as-is
8073
81-
## Threading
74+
### Threading
8275
8376
Threading is used at the outermost level possible - over
8477
an array, feature collection, or e.g. a MultiPolygonTrait where
8578
each `PolygonTrait` sub-geometry may be calculated on a different thread.
8679
8780
Currently, threading defaults to `false` for all objects, but can be turned on
8881
by passing the keyword argument `threaded=true` to `apply`.
82+
83+
Threading uses [StableTasks.jl](https://github.com/JuliaFolds2/StableTasks.jl) to provide
84+
type-stable tasks (base Julia `Threads.@spawn` is not type stable). This is completely cost-free
85+
and saves some allocations when running multithreaded.
86+
87+
The current strategy is to launch 2 tasks for each CPU thread, to provide load balancing. We
88+
assume Julia will manage these tasks efficiently, and we don't want to run too many tasks
89+
since each task does have some overhead when it's created. This may need revisiting in the future,
90+
but it's a pretty easy heuristic to use.
91+
92+
## Implementation
93+
94+
Literate.jl source code is below.
95+
96+
***
97+
8998
=#
9099

91100
"""

GeometryOpsCore/src/applyreduce.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ and perform some operation on it.
1818
1919
[`centroid`](@ref), [`area`](@ref) and [`distance`](@ref) have been implemented using the
2020
[`applyreduce`](@ref) framework.
21+
22+
```@docs
23+
applyreduce
24+
```
25+
26+
27+
### Threading
28+
29+
Threading is used at the outermost level possible - over
30+
an array, feature collection, or e.g. a MultiPolygonTrait where
31+
each `PolygonTrait` sub-geometry may be calculated on a different thread.
32+
33+
Currently, threading defaults to `false` for all objects, but can be turned on
34+
by passing the keyword argument `threaded=true` to `apply`.
35+
36+
Threading uses [StableTasks.jl](https://github.com/JuliaFolds2/StableTasks.jl) to provide
37+
type-stable tasks (base Julia `Threads.@spawn` is not type stable). This is completely cost-free
38+
and saves some allocations when running multithreaded.
39+
40+
The current strategy is to launch 2 tasks for each CPU thread, to provide load balancing. We
41+
assume Julia will manage these tasks efficiently, and we don't want to run too many tasks
42+
since each task does have some overhead when it's created. This may need revisiting in the future,
43+
but it's a pretty easy heuristic to use.
44+
45+
## Implementation
46+
47+
Literate.jl source code is below.
48+
49+
***
50+
2151
=#
2252

2353
"""

0 commit comments

Comments
 (0)