Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default arguments do not work with only 1 argument #175

Closed
seanmor5 opened this issue Jan 27, 2021 · 1 comment
Closed

Default arguments do not work with only 1 argument #175

seanmor5 opened this issue Jan 27, 2021 · 1 comment
Labels
kind:bug Something isn't working

Comments

@seanmor5
Copy link
Collaborator

As an example, this does not compile:

  defn uniform(opts \\ []) do
    shape = transform(opts, &Keyword.fetch!(&1, :shape))
    opts = keyword!(opts, type: {:f, 32}, shape: {}, scale: 1.0e-2)
    Nx.random_uniform(shape, type: opts[:type]) * opts[:scale]
  end

But this does:

  defn uniform(_t, opts \\ []) do
    shape = transform(opts, &Keyword.fetch!(&1, :shape))
    opts = keyword!(opts, type: {:f, 32}, shape: {}, scale: 1.0e-2)
    Nx.random_uniform(shape, type: opts[:type]) * opts[:scale]
  end

Even though t is unused.

@seanmor5 seanmor5 added the kind:bug Something isn't working label Jan 27, 2021
@josevalim
Copy link
Collaborator

Nice catch, I will fix it soon.

Btw, if you want to validate a key but not give it a default value., you can write it like this:

opts = keyword!(opts, [:shape, type: {:f, 32}, scale: 1.0e-2])

But the current way is fine given you assert for the shape first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants