Julia Package Flux

using Flux

f(x) = 3x + 2

df(x) = gradient(f,x)[1]

df(2)

when I am running this code, I am getting an error - LoadError: UndefVarError: gradient not defined.

However, if I change gradient by Flux.gradient, it works fine.
Can anybody tell me why this is happening?

Unexported functions need to be qualified with the package name.

1 Like

gradient should be exported by default when you use Flux. You may be on a very old version, so check your packages with ] st at the REPL.

2 Likes

I amgetting following error

v1.6) pkg> add Flux@0.12.4
Resolving package versions…
ERROR: Unsatisfiable requirements detected for package Distributions [31c24e10]:
Distributions [31c24e10] log:
├─possible versions are: 0.16.0-0.25.6 or uninstalled
├─restricted by compatibility requirements with HardSphereDynamics [2cbf6e9d] to versions: 0.21.0-0.21.12
│ └─HardSphereDynamics [2cbf6e9d] log:
│ ├─possible versions are: 0.1.0-0.1.1 or uninstalled
│ └─restricted to versions * by an explicit requirement, leaving only versions 0.1.0-0.1.1
└─restricted by compatibility requirements with StatsBase [2913bbd2] to versions: 0.23.2-0.25.6 or uninstalled — no versions left
└─StatsBase [2913bbd2] log:
├─possible versions are: 0.24.0-0.33.8 or uninstalled
├─restricted to versions * by an explicit requirement, leaving only versions 0.24.0-0.33.8
└─restricted by compatibility requirements with Flux [587475ba] to versions: 0.33.0-0.33.8
└─Flux [587475ba] log:
├─possible versions are: 0.4.1-0.12.4 or uninstalled
└─restricted to versions 0.12.4 by an explicit requirement, leaving only versions 0.1