# Function argument Array{Array{ComplexF64,2},1} seems to be ignored

**URL:** <https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269>\
**Category:** New to Julia\
**Created:** [March 20, 2020, 4:43pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269 "2020-03-20T16:43:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 20, 2020, 4:43pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/1 "2020-03-20T16:43:12Z")

</div>

I have a function definition:

```julia
function simBiquad(xin::Array{ComplexF64,1}, A::Array{Array{Complex{Float64},2},1},
                    B::Array{Array{Complex{Float64},2},1},
                    C::Array{Array{Complex{Float64},2},1},
                    D::Array{Array{Complex{Float64},2},1})

```

I call the function in the REPL using:

```julia
@enter simBiquad(xin,A,B,C,D);

```

and get the error message:

```julia
ERROR: MethodError: no method matching simBiquad(::Array{Complex{Float64},1}, ::Array{Array{Complex{Float64},2},1}, ::Array{Array{Complex{Float64},2},1}, ::Array{Array{Complex{Float64},2},1}, ::Array{Array{Complex{Float64},2},1})
Closest candidates are:
  simBiquad(::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}) at /home/martin/Dropbox/Matlab/Complex/KM_ComplexFilterToolbox/juliaFiles/LpFlt.jl:39

```

As you can see the first argument has type ::Array{Complex{Float64},1} which matches, and the other arguments (A,B,C, and D) have the types ::Array{Array{Complex{Float64},2},1} which matches the function declaration line, but the error message states that types ::Array{Complex{Float64},1} are expected even though the function declaration states Arrays of Arrays are expected. I can’t see what I am doing wrong; if someone else sees what my error is, any help would be appreciated. I’m hoping this might be something of general interest as I’m guessing it’s a scenario that will be common in realizing filter simulations. Thank you.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 20, 2020, 5:02pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/2 "2020-03-20T17:02:18Z")

</div>

Sounds like you edited your function definition and didn’t re-evaluate it?

PS. Your function seems over-typed — making the function signature so specific has no performance benefits whatsoever, but makes your code much less generic.

---

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 20, 2020, 5:23pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/3 "2020-03-20T17:23:21Z")

</div>

stevengj, can you explain how to force a function to be re-evaluated. I currently have the file at the top level, and the function is in a module. Do I have to quit julia and restart it every time I change the function during debug.  
I might also mention that my algorithm for running the filter (it’s a complex cascade filter where each section can be a first or second-order state-space realization does require the A,B,C, and D arrays to be as specified; if they don’t have this form, the filter will not function correctly.

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [March 20, 2020, 5:27pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/4 "2020-03-20T17:27:46Z")

</div>

You can define as many versions of the function as you want in a single julia session. To see all versions of your function, you can use

```julia
methods(function_name)

```

---

<div class="post-metadata">

**Author:** ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)\
**Post date:** [March 20, 2020, 5:39pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/5 "2020-03-20T17:39:29Z")

</div>

Also you really want to be using Revise.jl. This will let you pick up and reevaluate any changes that you make in development.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 20, 2020, 5:52pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/6 "2020-03-20T17:52:39Z")

</div>

Follow the instructions here: [Configuration · Revise.jl](https://timholy.github.io/Revise.jl/stable/config/#Using-Revise-by-default-1)  
Revise.jl is your ticket to bliss.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 20, 2020, 9:01pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/7 "2020-03-20T21:01:46Z")

</div>

> [@kw\_martin](#):
>
> I might also mention that my algorithm […] does require the A,B,C, and D arrays to be as specified; if they don’t have this form, the filter will not function correctly.

They have to be double-precision complex? (They can’t be any other number type, e.g. single-precision complex, or [unitful values](https://github.com/PainterQubits/Unitful.jl)?) You can’t use any other array type, only the built-in `Array` type?

A major advantage of using Julia is code that can be generic over many different number and container types. Even if you require arrays of arrays of numbers, there are still many different choices.

---

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 21, 2020, 1:44pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/8 "2020-03-21T13:44:46Z")

</div>

Stevengj, I guess there are always many different ways of doing things. I am new to Julia (hence the reason for posting in First Steps), so currently I am just trying whatever I can to get things working. I am slowly trying to figure out how to get julia to re-compile when I make changes, but this is challenging for me. For example, I did make a package and am trying to use Revise, but I still found that a number of times, I needed to do a \>git commit -am “” in a terminal to get julia to see the changes. I also am trying to not have to make a new package every time I try something different, and to use includet(), and this seems to work a lot, but many times I need to quit julia and restart. I still have not been able to come up with a clean work flow that I understand; again probably because I am new to Julia, and perhaps my incompetence. It is not due to not reading the documentation as much as possible and going back time and time again.  
The application I am looking at is using a 1024 channel Filter bank running on a Pi4 to analyze ECG signals. This project is mostly a hobby, although I am working on getting some 4’th year students interested in the application as a project next year. The filter architecture I am looking at is based on using OFDM filters. The current architecture is equivalent to first taking 4096 point FFT’s and then adding 7 adjacent channels with appropriate coefficients (with a bit more complication involved as I’m using Frame processing and I also differentiate the signal which I can get for free with the filter-bank approach). This inherently needs array multiplications. I’m not sure what other array type I could use besides the built-in Array type; mayhbe you could be more specific? The stop bands have a lot of attenation (over 100dB as one gets away from a particular channel). I also have some low-pass filtering using a cascade state-space approach, and if I want to use the same code for both first and second-order complex stages; I do need matrix multiplications. I am guessing ComplexF32 could cause some degradation but I’m not sure. I developed the Filters using Matlab, so for now I want to match my Matlab results before optimizing (I have enough complication as it is, and matching the Matlab results makes debugging easier). As long as the speed is say 4 times faster than a person’s heart rate, then I currently think the processing speed is not an issue. Anyways, in summary, yes there are better ways, but right now, I’m just trying to get things working.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 21, 2020, 2:16pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/9 "2020-03-21T14:16:16Z")

</div>

> [@kw\_martin](#):
>
> I did make a package and am trying to use Revise, but I still found that a number of times, I needed to do a \>git commit -am “” in a terminal to get julia to see the changes

This should not be necessary.

I would suggest that you get Revise working first. It is an indispensable tool for practical work in Julia.

> [@kw\_martin](#):
>
> I’m not sure what other array type I could use besides the built-in Array type

I think the suggestion is just about not specifying a narrow type unless it is necessary. Generic Julia code should work with any kind of array.

Unless you are implementing various versions of `simBiquad` which do different things (in the sense of requiring different Julia code) for various types, I would just go with `AbstractVector` etc, or even no explicit types, and not bother about figuring out types at this stage.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 21, 2020, 2:50pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/10 "2020-03-21T14:50:25Z")

</div>

> [@kw\_martin](#):
>
> ```julia
> function simBiquad(xin::Array{ComplexF64,1}, A::Array{Array{Complex{Float64},2},1}, B::Array{Array{Complex{Float64},2},1}, C::Array{Array{Complex{Float64},2},1}, D::Array{Array{Complex{Float64},2},1})
> 
> ```

If your code will only work for arrays of arrays, just specify the function signature like this:

```julia
function simBiquad(xin, A, B, C, D)

```

There’s no need to mess with type specs unless you need to control dispatch, or you really need this for error checking.

Refusing to allow other types of arrays ruins all the fun 😉

BTW, it’s much easier to read and less error prone to use `Vector{Matrix{ComplexF64}}` rather than `Array{Array{Complex{Float64},2},1}`

---

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 21, 2020, 3:01pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/11 "2020-03-21T15:01:26Z")

</div>

Tamas, thank you for the suggestions. I have taken your (and others) suggestions to use Revise; currently for initial debug of a new module with the file in the same directory, and using

```julia
julia> includet("LpFlt.jl")
julia> using .LpFlt

```

When I get the module mostly working than I plan on making it a Pkg. One thing I have not been able to understand from looking at the documentation for Pkg is how to deal with multiple files. Do they all go in the same directory (./LpFlt/src) and then use “include” statements, or should there be a separate package (and therefore directory) for each file, and then inside the main file, we have “using” statements?  
Regarding you suggestion for using AbstractVector. For a cascade filter, I need A,B,C, and D arrays? for each stage. For example, if a stage is a complex biquad, then A is 2x2 complex, B is 2x1 complex, C is 1x2 complex, and D is 1x1 complex. So I have been using an Nx1 array for the cascade filter, with nxn array for the A,B,C, and D matrices of each stage. For A, I have used

```julia
A = Array{Array{ComplexF64,2}}(undef,N)

```

I don’t think I can use an AbstractVector, as my understanding is a vector is always nx1 or 1xn? If I understand correctly, you are suggesting that instead of

```julia
function simBiquad(xi::Array{ComplexF64,1}, A::Array{Array{Complex{Float64},2},1},
                    B::Array{Array{Complex{Float64},2},1},
                    C::Array{Array{Complex{Float64},2},1},
                    D::Array{Array{Complex{Float64},2},1})

```

I use something like?

```julia
function simBiquad(xi::AbstractArray, 
                    A::AbstractArray{AbstractArray},
                    B::AbstractArray{AbstractArray},
                    C::AbstractArray{AbstractArray},
                    D::AbstractArray{AbstractArray})

```

The array of array stuff is not easy for me. For example, in order to initialize the value of D[i] which I have as an Array{ComplexF64,2}, the only way I could figure out was to use:

```julia
D[i] = fill(parse(ComplexF64, filt["sections"][i]["d"]), (1,1))

```

Note: the value is coming from a Yaml file I read in, which puts the A,B,C, and D matrices into an array of Dicts. Anyways, I couldn’t figure out a better way of specifying the value of a 1x1 array without using fill(); this is messy to me.

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [March 21, 2020, 3:14pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/12 "2020-03-21T15:14:23Z")

</div>

> [@kw\_martin](#):
>
> function simBiquad(xi::AbstractArray, A::AbstractArray{AbstractArray}, B::AbstractArray{AbstractArray}, C::AbstractArray{AbstractArray}, D::AbstractArray{AbstractArray})

I believe the suggestion is to use

```julia
function simBiquad(xi::T, 
                    A::F,
                    B::F,
                    C::F,
                    D::F) where {T<:AbstractArray, F<:AbstractArray}

```

This is what is meant by “generic” code. You are allowing the flexibility for the type of the argument to be any subtype of `AbstractArray`. Below is an example of what a code similar to the above would do:

```julia
julia> A
1-element Array{Array{Float64,1},1}:
 [1.0, 2.0]

julia> B
2-element Array{Float64,1}:
 1.0
 2.0

julia> function test(g::T, h::F) where {T<:AbstractArray, F<:AbstractArray}
       println(1)
       end
test (generic function with 1 method)

julia> test(A, B)
1

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 21, 2020, 3:41pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/13 "2020-03-21T15:41:28Z")

</div>

> [@kw\_martin](#):
>
> For a cascade filter, I need A,B,C, and D arrays? for each stage. For example, if a stage is a complex biquad, then A is 2x2 complex, B is 2x1 complex, C is 1x2 complex, and D is 1x1 complex.

This is a very good reason to allow `AbstractArray` and not just `Array`. For those filters StaticArrays would be _much_ more efficient than an ordinary Matrix

> [@kw\_martin](#):
>
> my understanding is a vector is always nx1 or 1xn?

No, a vector is never nx1 or 1xn, only matrices are nx1 or 1xn, as they have two dimensions. A vector is ‘length-n’ or size (n,), since it has only one single dimension.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 21, 2020, 3:42pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/14 "2020-03-21T15:42:14Z")

</div>

> [@kw\_martin](#):
>
> Do they all go in the same directory (./LpFlt/src) and then use “include” statements

Yes, that’s a common way to organize packages. Just look at some existing Julia packages, or use a template generator (search for suggestions on this forum).

> [@kw\_martin](#):
>
> then A is 2x2 complex, B is 2x1 complex, C is 1x2 complex, and D is 1x1 complex

I think you might benefit a lot from

> **[GitHub - JuliaArrays/StaticArrays.jl: Statically sized arrays for Julia](https://github.com/JuliaArrays/StaticArrays.jl)**
>
> Statically sized arrays for Julia. Contribute to JuliaArrays/StaticArrays.jl development by creating an account on GitHub.

Don’t use

```julia
A::AbstractArray{AbstractArray}

```

as it does not do what you think it does. Again, I would not parametrize these at all unless necessary.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 21, 2020, 3:53pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/15 "2020-03-21T15:53:44Z")

</div>

> [@Tamas\_Papp](#):
>
> I would just go with `AbstractVector` etc, or even no explicit types, and not bother about figuring out types at this stage.

I would just go with specifying no types at all (i.e. [duck typing](https://en.wikipedia.org/wiki/Duck_typing)). As a beginner, it’s too easy to get type specifications wrong, especially for nested types. There is generally _no performance benefit_ to specifying a type in a function call.

Later on, you can narrow the type declaration without changing anything else. The reasons to do this are (1) as filters for dispatch (i.e. doing different things for different types), (2) as a form of documentation, and (3) using type checks to give clearer errors for usage bugs. (But if you pass the wrong type you will typically get an error from elsewhere in the function call anyway.)

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 21, 2020, 4:25pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/16 "2020-03-21T16:25:34Z")

</div>

> [@kw\_martin](#):
>
> and D is 1x1 complex.

BTW, why use an array here at all, instead of a scalar?

> [@kw\_martin](#):
>
> Anyways, I couldn’t figure out a better way of specifying the value of a 1x1 array without using fill(); this is messy to me.

You are needlessly forcing yourself to awkwardly create a 1x1 matrix instead of just using a scalar.

---

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 21, 2020, 5:03pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/17 "2020-03-21T17:03:37Z")

</div>

DNF, I still don’t understand as my A matrices for a biquad must be 2x2 so they can’t be vectors? I haven’t heard of StaticArrays previously; I am looking into it and they look interesting. Thank you.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 21, 2020, 5:07pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/18 "2020-03-21T17:07:26Z")

</div>

What are you replying to, specifically?

---

<div class="post-metadata">

**Author:** ![kw\_martin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kw_martin/32/48868_2.png) [@kw\_martin](https://discourse.julialang.org/u/kw_martin)\
**Post date:** [March 21, 2020, 5:15pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/19 "2020-03-21T17:15:43Z")

</div>

Sorry, I should have included it; this has to do with not understanding:  
“No, a vector is never nx1 or 1xn, only matrices are nx1 or 1xn, as they have two dimensions. A vector is ‘length-n’ or size (n,), since it has only one single dimension.”  
As far as I understand, I need to use matries (i.e. arrays and not vectors), but again, my background is Matlab and I am very new to Julian hoping to get faster performance so it’s hard to get familiar with a lot of the concepts.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 21, 2020, 5:20pm UTC](https://discourse.julialang.org/t/function-argument-array-array-complexf64-2-1-seems-to-be-ignored/36269/20 "2020-03-21T17:20:41Z")

</div>

A 2x2 array is a matrix, but a nx1 array is not a vector. I was just correcting or answering that statement/question, not saying anything about `A`.

**Edit** : this is what I was addressing.

> [@kw\_martin](#):
>
> my understanding is a vector is always nx1 or 1xn?
