SparseMatrixCSC definition in function

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.

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

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!

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.

1 Like

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

1 Like

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)

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.

1 Like

That’s totally right! Thanks you so much!