FluxML / Zygote.jl

21st century AD
https://fluxml.ai/Zygote.jl/
Other
1.48k stars 210 forks source link

TL;DR of Supported Operations for Docs #83

Open jessebett opened 5 years ago

jessebett commented 5 years ago

When writing the docs, it would be nice to follow jax's lead and include a TL;DR of what sorts of operations are supported. From their docs:

TLDR Do use

    Functional programming
    Many of NumPy’s functions (help us add more!)
    Some SciPy functions
    Indexing and slicing of arrays like x = A[[5, 1, 7], :, 2:4]
    Explicit array creation from lists like A = np.array([x, y])

Don’t use

    Assignment into arrays like A[0, 0] = x
    Implicit casting to arrays like np.sum([x, y]) (use np.sum(np.array([x, y]) instead)
    A.dot(B) method syntax for functions of more than one argument (use np.dot(A, B) instead)
    Side-effects like mutation of arguments or mutation of global variables
    The out argument of NumPy functions
    Dtype casting like np.float64(x) (use x.astype('float64') or x.astype(np.float64) instead).

For jit functions, also don’t use

    Control flow based on dynamic values if x > 0: .... Control flow based on shapes is fine: if x.shape[0] > 2: ... and for subarr in array.
    Slicing A[i:i+5] for dynamic index i (use lax.dynamic_slice instead) or boolean indexing A[bool_ind] for traced values bool_ind.
MikeInnes commented 5 years ago

This should be pretty easy for us since the only thing you can't do is assignment into arrays (yet – #75). Some general docs and usage tips are definitely a good idea though.

baggepinnen commented 5 years ago

This should be pretty easy for us since the only thing you can't do is assignment into arrays (yet – #75). Some general docs and usage tips are definitely a good idea though.

How about try/catch blocks? https://github.com/FluxML/Zygote.jl/issues/47#issuecomment-470053165

MikeInnes commented 5 years ago

Yup, just remembered that when investigating that issue :) I'm hoping that's an easy fix though, whereas the mutation restriction will probably be part of a stable release.