# SparseMatrixCSC definition in function

**URL:** <https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766>\
**Category:** General Usage\
**Tags:** type, module, function, sparse\
**Created:** [September 17, 2020, 9:32am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766 "2020-09-17T09:32:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmurga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmurga/32/15944_2.png) [@jmurga](https://discourse.julialang.org/u/jmurga)\
**Post date:** [September 17, 2020, 9:32am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766/1 "2020-09-17T09:32:48Z")

</div>

Hi everyone!

I’m developing a module within several functions. I found some troubles with the type definition at some inputs functions. I don’t know why but I cannot use _SparseMatrixCSC_ type as the input type. After build and compile the module I have the following error:

_ERROR: LoadError: LoadError: UndefVarError: SparseMatrixCSC not defined_

I included the SparseMatrixCSC at the module, so I do not understand what is happening

Here are the module load and the functions.

```julia
module Analytical

	include("parameters.jl")
	include("fixations.jl")
	include("polymorphism.jl")
	include("summaryStatistics.jl")
	include("inferTools.jl")
	include("readFasta.jl")

	using Parameters, NLsolve, SpecialFunctions, Distributions, Roots, ArbNumerics, StatsBase, LsqFit, PoissonRandom, SparseArrays

	import CSV: read
	import CSV: write
	import DataFrames: DataFrame
	import GZip: open
	import Parsers: parse
	import OrderedCollections: OrderedDict
	import FastaIO: readfasta
	import SparseArrays: SparseMatrixCSC

end

```

```julia
function DiscSFSNeutDown(param::parameters,binom::SparseMatrixCSC{Float64,Int64})

	NN2 = convert(Int64,ceil(param.NN*param.B))
	# Allocating variables

	neutralSfs(i::Int64) = 1.0/(i)

	x = collect(0:NN2)
	solvedNeutralSfs = neutralSfs.(x)
	replace!(solvedNeutralSfs, Inf => 0.0)
	
	# subsetDict = get(param.bn,param.B,1)
	# subsetDict = binom
	out = param.B*(param.theta_mid_neutral)*0.255*(binom*solvedNeutralSfs)
	# out = @view out[2:end-1,:]
	return out[2:end-1,:]
end

```

Does anyone know how to deal with it?

Thanks in advance, Jesús!

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 17, 2020, 9:54am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766/2 "2020-09-17T09:54:50Z")

</div>

If your function is not inside the module, then you’ll have to using the SparseArray in the module where that function is defined as well.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 17, 2020, 10:19am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766/3 "2020-09-17T10:19:44Z")

</div>

If your function _is_ in the module, try moving all the includes to be after `using` and `import`, which should always come first.

---

<div class="post-metadata">

**Author:** ![jmurga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmurga/32/15944_2.png) [@jmurga](https://discourse.julialang.org/u/jmurga)\
**Post date:** [September 17, 2020, 10:20am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766/4 "2020-09-17T10:20:23Z")

</div>

Thanks so much Mauro! It works properly but I found another way to do it. You can import just once the required modules changing the order at the file where the module is created. So I import first the required modules and then the scripts (which makes sense)

```julia
module Analytical

#First import the required modules
    	using Parameters, NLsolve, SpecialFunctions, Distributions, Roots, ArbNumerics, StatsBase, LsqFit, PoissonRandom, SparseArrays

	import CSV: read
	import CSV: write
	import DataFrames: DataFrame
	import GZip: open
	import Parsers: parse
	import OrderedCollections: OrderedDict
	import FastaIO: readfasta
	import SparseArrays: SparseMatrixCSC

#Second import your scripts
	include("parameters.jl")
	include("fixations.jl")
	include("polymorphism.jl")
	include("summaryStatistics.jl")
	include("inferTools.jl")
	include("readFasta.jl")
end

```

Jesús.

---

<div class="post-metadata">

**Author:** ![jmurga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmurga/32/15944_2.png) [@jmurga](https://discourse.julialang.org/u/jmurga)\
**Post date:** [September 17, 2020, 10:20am UTC](https://discourse.julialang.org/t/sparsematrixcsc-definition-in-function/46766/5 "2020-09-17T10:20:56Z")

</div>

That’s totally right! Thanks you so much!
