An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# SliceMap.jl

[![Build Status](https://github.com/mcabbott/SliceMap.jl/workflows/CI/badge.svg)](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.@threads

maprows(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).