# Multiple Dispatch seems to be acting odd on AbstractSparseMatrixCSC

**URL:** <https://discourse.julialang.org/t/multiple-dispatch-seems-to-be-acting-odd-on-abstractsparsematrixcsc/40070>\
**Category:** Internals & Design\
**Created:** [May 24, 2020, 12:02pm UTC](https://discourse.julialang.org/t/multiple-dispatch-seems-to-be-acting-odd-on-abstractsparsematrixcsc/40070 "2020-05-24T12:02:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![irhum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/irhum/32/25000_2.png) [@irhum](https://discourse.julialang.org/u/irhum)\
**Post date:** [May 24, 2020, 12:02pm UTC](https://discourse.julialang.org/t/multiple-dispatch-seems-to-be-acting-odd-on-abstractsparsematrixcsc/40070/1 "2020-05-24T12:02:34Z")

</div>

If I recall correctly, multiple dispatch is supposed to select the most specific method available when calling a function.

In this case, when the Array type is specified as AbstractSparseMatrix, the specialization based on the value types works, but fails when using AbstractSparseMatrixCSC. Does anyone know if this is a bug or intended behavior?

```julia
using SparseArrays 

M = [sprand(rand(15:50), rand(15:50), 0.02) for i in 1:2500] #result of type Vector{SparseMatrixCSC{Float64, Int64}}
N = [i % 2 == 0 ? SparseMatrixCSC{Float32, Int32}(sprand(rand(15:50), rand(15:50), 0.02)) : sprand(rand(15:50), rand(15:50), 0.02) for i in 1:2500] #result of type Vector{SparseMatrixCSC}

funcA(X::SparseArrays.AbstractSparseMatrix...) = "generic"
funcA(X::SparseArrays.AbstractSparseMatrix{Tv, Ti}...) where {Tv, Ti} = "specific"

funcB(X::SparseArrays.AbstractSparseMatrixCSC...) = "generic"
funcB(X::SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}...) where {Tv, Ti} = "specific"

funcA(M...) # returns specific
funcA(N...) # returns generic

funcB(M...) # returns generic, which is incorrect
funcB(N...) # returns generic

```

---

<div class="post-metadata">

**Author:** ![irhum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/irhum/32/25000_2.png) [@irhum](https://discourse.julialang.org/u/irhum)\
**Post date:** [May 24, 2020, 12:22pm UTC](https://discourse.julialang.org/t/multiple-dispatch-seems-to-be-acting-odd-on-abstractsparsematrixcsc/40070/2 "2020-05-24T12:22:12Z")

</div>

It appears I didn’t specify type parameters correctly, in this case using

```julia
funcB(X::SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}...) where {Tv, Ti <: Integer} = "specific"

```

instead of

```julia
funcB(X::SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}...) where {Tv, Ti} = "specific"

```

fixed it, dispatch is working correctly on all 4 cases

```julia
funcA(M...) # returns specific
funcA(N...) # returns generic

funcB(M...) # returns specific
funcB(N...) # returns generic

```
