From 9cac07540c10d6027c9fc28211f806c3615d13ed Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Sat, 13 Mar 2021 14:31:58 +0530 Subject: [PATCH 1/4] rm dead checks --- src/build_function.jl | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/build_function.jl b/src/build_function.jl index c47ef222c..c9cac7868 100644 --- a/src/build_function.jl +++ b/src/build_function.jl @@ -102,21 +102,6 @@ function _build_and_inject_function(mod::Module, ex) RuntimeGeneratedFunctions.RuntimeGeneratedFunction(module_tag, module_tag, ex) end -# Detect heterogeneous element types of "arrays of matrices/sparce matrices" -function is_array_matrix(F) - return isa(F, AbstractVector) && all(x->isa(x, AbstractArray), F) -end -function is_array_sparse_matrix(F) - return isa(F, AbstractVector) && all(x->isa(x, AbstractSparseMatrix), F) -end -# Detect heterogeneous element types of "arrays of arrays of matrices/sparce matrices" -function is_array_array_matrix(F) - return isa(F, AbstractVector) && all(x->isa(x, AbstractArray{<:AbstractMatrix}), F) -end -function is_array_array_sparse_matrix(F) - return isa(F, AbstractVector) && all(x->isa(x, AbstractArray{<:AbstractSparseMatrix}), F) -end - toexpr(n::Num, st) = toexpr(value(n), st) function fill_array_with_zero!(x::AbstractArray) From 5a42da615e7d9207828a03a5d071b3fb9c696341 Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Sat, 13 Mar 2021 14:32:15 +0530 Subject: [PATCH 2/4] fix in-place sparse matrix code --- src/build_function.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/build_function.jl b/src/build_function.jl index c9cac7868..0456634df 100644 --- a/src/build_function.jl +++ b/src/build_function.jl @@ -298,6 +298,10 @@ function set_array(s::MultithreadedForm, closed_args, out, outputidxs, rhss, che SpawnFetch{MultithreadedForm}(first.(arrays), last.(arrays), @inline noop(args...) = nothing) end +function _set_array(out, outputidxs, rhss::AbstractSparseArray, checkbounds, skipzeros) + _set_array(LiteralExpr(:($out.nzval)), nothing, rhss.nzval, checkbounds, skipzeros) +end + function _set_array(out, outputidxs, rhss::AbstractArray, checkbounds, skipzeros) if outputidxs === nothing outputidxs = collect(eachindex(rhss)) From b7cfcf47fbb4b328f6a9fea1fb90ac4e36e7298e Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Sat, 13 Mar 2021 14:37:10 +0530 Subject: [PATCH 3/4] test 800 --- test/build_function.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/build_function.jl b/test/build_function.jl index 1113e0829..5fb162e94 100644 --- a/test/build_function.jl +++ b/test/build_function.jl @@ -104,3 +104,15 @@ f = eval(build_function(sparse([1],[1], [(x+y)/k], 10,10), [x,y,k])[1]) @test size(f([1.,1.,2])) == (10,10) @test f([1.,1.,2])[1,1] == 1.0 @test sum(f([1.,1.,2])) == 1.0 + +let #800 + @variables x + y = sparse(1:3,1:3,x) + + f1,f2 = build_function(y,x) + sf1, sf2 = string(f1), string(f2) + @test !contains(sf1, "CartesianIndex") + @test !contains(sf2, "CartesianIndex") + @test contains(sf1, "SparseMatrixCSC(") + @test contains(sf2, ".nzval") +end From ef52c0e65d843b01173ad1ecf9daf365a61c569b Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Sat, 13 Mar 2021 14:38:46 +0530 Subject: [PATCH 4/4] update comment to say mtk#800 --- test/build_function.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/build_function.jl b/test/build_function.jl index 5fb162e94..859791dfd 100644 --- a/test/build_function.jl +++ b/test/build_function.jl @@ -105,7 +105,7 @@ f = eval(build_function(sparse([1],[1], [(x+y)/k], 10,10), [x,y,k])[1]) @test f([1.,1.,2])[1,1] == 1.0 @test sum(f([1.,1.,2])) == 1.0 -let #800 +let # ModelingToolkit.jl#800 @variables x y = sparse(1:3,1:3,x)