https://github.com/mcabbott/slicemap.jl
Same-same but different
https://github.com/mcabbott/slicemap.jl
automatic-differentiation gradient julia
Last synced: about 2 months ago
JSON representation
Same-same but different
- Host: GitHub
- URL: https://github.com/mcabbott/slicemap.jl
- Owner: mcabbott
- License: other
- Created: 2019-06-05T16:33:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-27T00:39:04.000Z (over 2 years ago)
- Last Synced: 2024-10-13T19:28:30.402Z (7 months ago)
- Topics: automatic-differentiation, gradient, julia
- Language: Julia
- Homepage:
- Size: 61.5 KB
- Stars: 31
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SliceMap.jl
[](https://github.com/mcabbott/SliceMap.jl/actions?query=workflow%3ACI)
This package provides some `mapslices`-like functions, with gradients defined for
[Tracker](https://github.com/FluxML/Tracker.jl) and [Zygote](https://github.com/FluxML/Zygote.jl):```julia
mapcols(f, M) ≈ mapreduce(f, hcat, eachcol(M))
MapCols{d}(f, M) # where d=size(M,1), for SVector slices
ThreadMapCols{d}(f, M) # using Threads.@threadsmaprows(f, M) ≈ mapslices(f, M, dims=2)
slicemap(f, A; dims) ≈ mapslices(f, A, dims=dims) # only Zygote
```The capitalised functions differ both in using [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl)
slices, and using [ForwardDiff](https://github.com/JuliaDiff/ForwardDiff.jl) for the gradient of each slice,
instead of the same reverse-mode Tracker/Zygote.
For small slices, this will often be much faster, with or without gradients.The package also defines Zygote gradients for the Slice/Align functions in
[JuliennedArrays](https://github.com/bramtayl/JuliennedArrays.jl),
which is a good way to roll-your-own `mapslices`-like thing (and is exactly
how `slicemap(f, A; dims)` works). Similar gradients are also available in
[TensorCast](https://github.com/mcabbott/TensorCast.jl),
and in [LazyStack](https://github.com/mcabbott/LazyStack.jl).There are more details & examples at [docs/intro.md](docs/intro.md).