Tue, 07 Dec 2021 11:41:07 +0200
New logger and iteration interface
| 0 | 1 | ######################### |
| 2 | # Some utility functions | |
| 3 | ######################### | |
| 4 | ||
|
4
59fd17a3cea0
Add __precompile__() for what it is worth
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
5 | __precompile__() |
|
59fd17a3cea0
Add __precompile__() for what it is worth
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
6 | |
| 0 | 7 | module Util |
| 8 | ||
| 9 | ############## | |
| 10 | # Our exports | |
| 11 | ############## | |
| 12 | ||
| 13 | export map_first_slice!, | |
| 14 | reduce_first_slice, | |
|
33
a60d2f12ef93
Split FunctionalProgramming.jl, VectorMath.jl, and ThreadUtil.jl out of Util.jl.
Tuomo Valkonen <tuomov@iki.fi>
parents:
29
diff
changeset
|
15 | ⬿ |
| 0 | 16 | |
| 17 | ############################### | |
| 18 | # For working with NamedTuples | |
| 19 | ############################### | |
| 20 | ||
| 21 | ⬿ = merge | |
| 22 | ||
| 23 | ###### | |
| 24 | # map | |
| 25 | ###### | |
| 26 | ||
| 27 | @inline function map_first_slice!(f!, y) | |
| 28 | for i in CartesianIndices(size(y)[2:end]) | |
| 29 | @inbounds f!(@view(y[:, i])) | |
| 30 | end | |
| 31 | end | |
| 32 | ||
| 33 | @inline function map_first_slice!(x, f!, y) | |
| 34 | for i in CartesianIndices(size(y)[2:end]) | |
| 35 | @inbounds f!(@view(x[:, i]), @view(y[:, i])) | |
| 36 | end | |
| 37 | end | |
| 38 | ||
| 39 | @inline function reduce_first_slice(f, y; init=0.0) | |
| 40 | accum=init | |
| 41 | for i in CartesianIndices(size(y)[2:end]) | |
| 42 | @inbounds accum=f(accum, @view(y[:, i])) | |
| 43 | end | |
| 44 | return accum | |
| 45 | end | |
| 46 | ||
| 47 | end # Module | |
| 48 |