# Problem with type mismatch -- MethodError: no method matching

**URL:** <https://discourse.julialang.org/t/problem-with-type-mismatch-methoderror-no-method-matching/20725>\
**Category:** New to Julia\
**Created:** [February 12, 2019, 9:33pm UTC](https://discourse.julialang.org/t/problem-with-type-mismatch-methoderror-no-method-matching/20725 "2019-02-12T21:33:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumarbalachandran](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kumarbalachandran](https://discourse.julialang.org/u/kumarbalachandran)\
**Post date:** [February 12, 2019, 9:33pm UTC](https://discourse.julialang.org/t/problem-with-type-mismatch-methoderror-no-method-matching/20725/1 "2019-02-12T21:33:37Z")

</div>

I have a script that has two functions with the following relationship:

> function optimize(w::Array{Float64,2}, b::Float64, X::Array{Float64,2}, Y::Array{Int64,2};  
> num\_iterations::Int64=2000, learning\_rate::Float64=0.5, print\_cost::Bool=false)
> 
> …  
> end

and

> # GRADED FUNCTION: model
> 
> function model(X\_train::Array{Float64,2}, Y\_train::Array{Int64,2}, X\_test::Array{Float64,2}, Y\_test::Array{Int64,2};  
> num\_iterations::Int64 = 2000, learning\_rate::Float64 = 0.5, print\_cost::Bool = false)  
> “”"  
> Builds the logistic regression model by calling the function you’ve implemented previously
> 
> ```
> Arguments:
> X_train -- training set represented by a numpy array of shape (num_px * num_px * 3, m_train)
> Y_train -- training labels represented by a numpy array (vector) of shape (1, m_train)
> X_test -- test set represented by a numpy array of shape (num_px * num_px * 3, m_test)
> Y_test -- test labels represented by a numpy array (vector) of shape (1, m_test)
> num_iterations -- hyperparameter representing the number of iterations to optimize the parameters
> learning_rate -- hyperparameter representing the learning rate used in the update rule of optimize()
> print_cost -- Set to true to print the cost every 100 iterations
> 
> Returns:
> d -- dictionary containing information about the model.
> """
> 
> ### START CODE HERE ###
> 
> # initialize parameters with zeros (≈ 1 line of code)
> w,b = initialize_with_zeros(size(X_train)[1])
> 
> # Gradient descent (≈ 1 line of code)
> println(typeof(w))
> println(typeof(b))
> println(typeof(X_train))
> println(typeof(Y_train))
> println(typeof(num_iterations))
> println(typeof(learning_rate))
> println(typeof(print_cost))
> parameters, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)
> 
> ```
> 
> …  
> end

```julia

I then call

> d = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=true) 
to get the intermediate output and crash
> Array{Float64,2}
> Float64
> Array{Float64,2}
> Array{Int64,2}
> Int64
> Float64
> Bool
> MethodError: no method matching optimize(::Array{Float64,2}, ::Float64, ::Array{Float64,2}, ::Array{Int64,2}, ::Int64, ::Float64, ::Bool)
> Closest candidates are:
> optimize(::Array{Float64,2}, ::Float64, ::Array{Float64,2}, ::Array{Int64,2}; num_iterations, learning_rate, print_cost) at In[24]:5
> 
> Stacktrace:
> [1] #model#8(::Int64, ::Float64, ::Bool, ::Function, ::Array{Float64,2}, ::Array{Int64,2}, ::Array{Float64,2}, ::Array{Int64,2}) at .\In[28]:34
> [2] (::getfield(Main, Symbol("#kw##model")))(::NamedTuple{(:num_iterations, :learning_rate, :print_cost),Tuple{Int64,Float64,Bool}}, ::typeof(model), ::Array{Float64,2}, ::Array{Int64,2}, ::Array{Float64,2}, ::Array{Int64,2}) at .\none:0
> [3] top-level scope at In[29]:1

Can someone help me understand why the types match and the function template is not recognized?
```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [February 12, 2019, 10:03pm UTC](https://discourse.julialang.org/t/problem-with-type-mismatch-methoderror-no-method-matching/20725/2 "2019-02-12T22:03:49Z")

</div>

When you declare a function with keyword arguments like this:

```julia-auto
function foo(x; y = 10)
end

```

then you _must_ provide the keywords when you call the function:

```julia-auto
foo(1, y = 2) # NOT: foo(1, 2)

```

By the way, it will be easier to read your code (and help you) if you format it correctly with backticks:

> [@PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530):
>
> This is a short post on how to use backticks (` and ```) to quote code, so it is easy to read. This post can be linked to new users who are confused by this feature. Why By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This makes it easier to read your code and help you. Displayed code looks like this: function displayed\_code(x::Int, y::Int) if x \< y println("x is smaller") else println("or not") end end Inline…

---

<div class="post-metadata">

**Author:** ![nicoleepp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicoleepp/32/5840_2.png) [@nicoleepp](https://discourse.julialang.org/u/nicoleepp)\
**Post date:** [February 12, 2019, 10:04pm UTC](https://discourse.julialang.org/t/problem-with-type-mismatch-methoderror-no-method-matching/20725/3 "2019-02-12T22:04:32Z")

</div>

> [@kumarbalachandran](#):
>
> optimize(w, b, X\_train, Y\_train, num\_iterations, learning\_rate, print\_cost)

Should be

```julia
optimize(w, b, X_train, Y_train; num_iterations=num_iterations, learning_rate=learning_rate, print_cost =print_cost)

```

Since you declared those as keyword arguments in the definition of the function `optimize`.
