Skip to content

Commit

Permalink
Pass in checkbounds and fix outputidxs
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Feb 4, 2021
1 parent b25faac commit 08614d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions src/build_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...;
end

out = Sym{Any}(gensym("out"))
ip_expr = Func([out, dargs...], [], _set_array(out, outputidxs, rhss, skipzeros))
ip_expr = Func([out, dargs...], [], _set_array(out, outputidxs, rhss, checkbounds, skipzeros))

if !isnothing(wrap_code[2])
ip_expr = wrap_code[2](ip_expr)
Expand All @@ -231,18 +231,18 @@ function _make_array(rhss::AbstractSparseArray, similarto)
end

## In-place version
function _set_array(out, outputidxs, rhss::AbstractArray, skipzeros)
function _set_array(out, outputidxs, rhss::AbstractArray, checkbounds, skipzeros)
if rhss isa Union{SparseVector, SparseMatrixCSC}
return SetArray(false, LiteralExpr(:($out.nzval)), rhss.nzval)
elseif isnothing(outputidxs)
return SetArray(checkbounds, LiteralExpr(:($out.nzval)), rhss.nzval)
elseif outputidxs === nothing
outputidxs = collect(eachindex(rhss))
end

# sometimes outputidxs is a Tuple
ii = findall(i->!(rhss[i] isa AbstractArray) && !(skipzeros && iszero(rhss[i])), outputidxs)
jj = findall(i->rhss[i] isa AbstractArray, outputidxs)
ii = findall(i->!(rhss[i] isa AbstractArray) && !(skipzeros && _iszero(rhss[i])), eachindex(outputidxs))
jj = findall(i->rhss[i] isa AbstractArray, eachindex(outputidxs))
exprs = []
push!(exprs, SetArray(false, out, AtIndex.(vec(collect(outputidxs[ii])), vec(rhss[ii]))))
push!(exprs, SetArray(checkbounds, out, AtIndex.(vec(collect(outputidxs[ii])), vec(rhss[ii]))))
for j in jj
push!(exprs, _set_array(LiteralExpr(:($out[$j])), nothing, rhss[j], skipzeros))
end
Expand All @@ -251,7 +251,7 @@ function _set_array(out, outputidxs, rhss::AbstractArray, skipzeros)
end)
end

_set_array(out, outputidxs, rhs, skipzeros) = rhs
_set_array(out, outputidxs, rhs, checkbounds, skipzeros) = rhs


function _make_array(rhss::AbstractArray, similarto)
Expand Down
56 changes: 28 additions & 28 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using SafeTestsets, Test

# @safetestset "Parsing Test" begin include("variable_parsing.jl") end
# @safetestset "Differentiation Test" begin include("derivatives.jl") end
# @safetestset "Simplify Test" begin include("simplify.jl") end
# @safetestset "Operation Overloads Test" begin include("operation_overloads.jl") end
# @safetestset "Direct Usage Test" begin include("direct.jl") end
# @safetestset "System Linearity Test" begin include("linearity.jl") end
# @safetestset "Build Function Test" begin include("build_function.jl") end
# @safetestset "ODESystem Test" begin include("odesystem.jl") end
# @safetestset "LabelledArrays Test" begin include("labelledarrays.jl") end
# @safetestset "Mass Matrix Test" begin include("mass_matrix.jl") end
# @safetestset "SteadyStateSystem Test" begin include("steadystatesystems.jl") end
# @safetestset "SDESystem Test" begin include("sdesystem.jl") end
# @safetestset "NonlinearSystem Test" begin include("nonlinearsystem.jl") end
# @safetestset "OptimizationSystem Test" begin include("optimizationsystem.jl") end
# @safetestset "ReactionSystem Test" begin include("reactionsystem.jl") end
# @safetestset "JumpSystem Test" begin include("jumpsystem.jl") end
# @safetestset "ControlSystem Test" begin include("controlsystem.jl") end
# @safetestset "Build Targets Test" begin include("build_targets.jl") end
# @safetestset "Domain Test" begin include("domains.jl") end
# @safetestset "Modelingtoolkitize Test" begin include("modelingtoolkitize.jl") end
# @safetestset "Constraints Test" begin include("constraints.jl") end
# @safetestset "Reduction Test" begin include("reduction.jl") end
# @safetestset "Components Test" begin include("components.jl") end
# @safetestset "PDE Construction Test" begin include("pde.jl") end
# @safetestset "Lowering Integration Test" begin include("lowering_solving.jl") end
# @safetestset "Test Big System Usage" begin include("bigsystem.jl") end
# @safetestset "Depdendency Graph Test" begin include("dep_graphs.jl") end
# @safetestset "Function Registration Test" begin include("function_registration.jl") end
@safetestset "Parsing Test" begin include("variable_parsing.jl") end
@safetestset "Differentiation Test" begin include("derivatives.jl") end
@safetestset "Simplify Test" begin include("simplify.jl") end
@safetestset "Operation Overloads Test" begin include("operation_overloads.jl") end
@safetestset "Direct Usage Test" begin include("direct.jl") end
@safetestset "System Linearity Test" begin include("linearity.jl") end
@safetestset "Build Function Test" begin include("build_function.jl") end
@safetestset "ODESystem Test" begin include("odesystem.jl") end
@safetestset "LabelledArrays Test" begin include("labelledarrays.jl") end
@safetestset "Mass Matrix Test" begin include("mass_matrix.jl") end
@safetestset "SteadyStateSystem Test" begin include("steadystatesystems.jl") end
@safetestset "SDESystem Test" begin include("sdesystem.jl") end
@safetestset "NonlinearSystem Test" begin include("nonlinearsystem.jl") end
@safetestset "OptimizationSystem Test" begin include("optimizationsystem.jl") end
@safetestset "ReactionSystem Test" begin include("reactionsystem.jl") end
@safetestset "JumpSystem Test" begin include("jumpsystem.jl") end
@safetestset "ControlSystem Test" begin include("controlsystem.jl") end
@safetestset "Build Targets Test" begin include("build_targets.jl") end
@safetestset "Domain Test" begin include("domains.jl") end
@safetestset "Modelingtoolkitize Test" begin include("modelingtoolkitize.jl") end
@safetestset "Constraints Test" begin include("constraints.jl") end
@safetestset "Reduction Test" begin include("reduction.jl") end
@safetestset "Components Test" begin include("components.jl") end
@safetestset "PDE Construction Test" begin include("pde.jl") end
@safetestset "Lowering Integration Test" begin include("lowering_solving.jl") end
@safetestset "Test Big System Usage" begin include("bigsystem.jl") end
@safetestset "Depdendency Graph Test" begin include("dep_graphs.jl") end
@safetestset "Function Registration Test" begin include("function_registration.jl") end
@safetestset "Array of Array Test" begin include("build_function_arrayofarray.jl") end
@testset "Distributed Test" begin include("distributed.jl") end
@safetestset "Variable Utils Test" begin include("variable_utils.jl") end
Expand Down

0 comments on commit 08614d0

Please sign in to comment.