2

Compared to the Python documentation, I find that Julia documentation are much harder to read.

For example, the rand function:

rand([rng=GLOBAL_RNG], [S], [dims...])

How should I interpret this? What do the brackets mean? Which parameters are optional, and which are not?

Also, in Flux's documentation for Dense:

Dense(in, out, σ=identity; bias=true, init=glorot_uniform)

Why are some parameters separated by commas and others by semicolons?

1 Answer 1

2

The parameters is square brackets [] are optional - this is a convention for documentation across many programming languages - this is not a part of language syntax though. Hence all parameters for rand are optional and you can do just rand.

Actually it is a good idea to try to type methods(rand) in the console to see the huge number of methods required to cover all such use cases:

julia> methods(rand)
# 80 methods for generic function "rand":
[1] rand() in Random at c:\Julia-1.7.2\share\julia\stdlib\v1.7\Random\src\Random.jl:257
.....

Semicolon is a part of syntax used for separating positional parameters from named parameters in Julia functions. As an example consider a function:

function foo(a, b=4; c, d=8)
   return a+b+c+d
end

Than you could do:

julia> foo(1,c=100)
113
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.