diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..d60f0707f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "monthly" diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index e47f93896..09a92853a 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -11,7 +11,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@latest with: version: '1' diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 196ed216b..f09362284 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -25,14 +25,14 @@ jobs: - {user: SciML, repo: ModelOrderReduction.jl, group: All} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} arch: x64 - uses: julia-actions/julia-buildpkg@latest - name: Clone Downstream - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: ${{ matrix.package.user }}/${{ matrix.package.repo }} path: downstream diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc1a6f479..cefa73be8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - '1' - '1.6' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - run: | @@ -27,7 +27,7 @@ jobs: - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} - - uses: actions/cache@v1 + - uses: actions/cache@v3 env: cache-name: cache-artifacts with: @@ -42,6 +42,6 @@ jobs: env: GROUP: ${{ matrix.group }} - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: file: lcov.info diff --git a/src/Symbolics.jl b/src/Symbolics.jl index d30cd5d6c..1b7e0c066 100644 --- a/src/Symbolics.jl +++ b/src/Symbolics.jl @@ -16,7 +16,7 @@ using Setfield import DomainSets: Domain @reexport using SymbolicUtils -import SymbolicUtils: similarterm, istree, operation, arguments, symtype +import SymbolicUtils: similarterm, istree, operation, arguments, symtype, metadata import SymbolicUtils: Term, Add, Mul, Pow, Sym, Div, BasicSymbolic, FnType, @rule, Rewriters, substitute, diff --git a/src/arrays.jl b/src/arrays.jl index 19aab684d..5aecc990b 100644 --- a/src/arrays.jl +++ b/src/arrays.jl @@ -88,7 +88,7 @@ function operation(a::ArrayOp) end function arguments(a::ArrayOp) isnothing(a.term) ? [a.output_idx, a.expr, a.reduce, - a.term, a.shape, a.ranges, a.metadata] : + a.term, a.shape, a.ranges, metadata(a)] : arguments(a.term) end @@ -723,7 +723,7 @@ function scalarize(arr) elseif arr isa Num wrap(scalarize(unwrap(arr))) elseif istree(arr) && symtype(arr) <: Number - t = similarterm(arr, operation(arr), map(scalarize, arguments(arr)), symtype(arr), metadata=arr.metadata) + t = similarterm(arr, operation(arr), map(scalarize, arguments(arr)), symtype(arr), metadata=metadata(arr)) istree(t) ? scalarize_op(operation(t), t) : t else arr diff --git a/src/build_function.jl b/src/build_function.jl index 457078c95..d641f0bac 100644 --- a/src/build_function.jl +++ b/src/build_function.jl @@ -113,11 +113,11 @@ function _build_function(target::JuliaTarget, op, args...; expr = if cse fun = Func(dargs, [], Code.cse(unwrap(op))) (wrap_code !== nothing) && (fun = wrap_code(fun)) - toexpr(fun, states) + conv(fun, states) else fun = Func(dargs, [], op) (wrap_code !== nothing) && (fun = wrap_code(fun)) - toexpr(fun, states) + conv(fun, states) end if expression == Val{true} @@ -142,14 +142,14 @@ function _build_function(target::JuliaTarget, op::Union{Arr, ArrayOp}, args...; Symbol("ˍ₋arg$(x[1])")), enumerate([args...])) expr = if cse - toexpr(Func(dargs, [], Code.cse(unwrap(op))), states) + conv(Func(dargs, [], Code.cse(unwrap(op))), states) else - toexpr(Func(dargs, [], op), states) + conv(Func(dargs, [], op), states) end outsym = Symbol("ˍ₋out") body = inplace_expr(unwrap(op), outsym) - oop_expr = toexpr(Func([outsym, dargs...], [], body), states) + oop_expr = conv(Func([outsym, dargs...], [], body), states) N = length(shape(op)) op = unwrap(op) @@ -161,7 +161,7 @@ function _build_function(target::JuliaTarget, op::Union{Arr, ArrayOp}, args...; $outsym end) |> LiteralExpr end - ip_expr = toexpr(Func(dargs, [], op_body), states) + ip_expr = conv(Func(dargs, [], op_body), states) if expression == Val{true} oop_expr, ip_expr else @@ -194,11 +194,28 @@ function fill_array_with_zero!(x::AbstractArray) end """ + _build_function(target::JuliaTarget, rhss::AbstractArray, args...; + conv=toexpr, + expression = Val{true}, + expression_module = @__MODULE__(), + checkbounds = false, + postprocess_fbody=ex -> ex, + linenumbers = false, + outputidxs=nothing, + skipzeros = false, + force_SA = false, + wrap_code = (nothing, nothing), + fillzeros = skipzeros && !(rhss isa SparseMatrixCSC), + states = LazyState(), + iip_config = (true, true), + parallel=nothing, cse = false, kwargs...) + Build function target: `JuliaTarget` ```julia function _build_function(target::JuliaTarget, rhss, args...; - conv = toexpr, expression = Val{true}, + conv = toexpr, + expression = Val{true}, checkbounds = false, linenumbers = false, headerfun = addheader, outputidxs=nothing, @@ -250,6 +267,7 @@ Special Keyword Arguments: safety with `skipzeros`. """ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...; + conv=toexpr, expression = Val{true}, expression_module = @__MODULE__(), checkbounds = false, @@ -303,10 +321,10 @@ function _build_function(target::JuliaTarget, rhss::AbstractArray, args...; end if expression == Val{true} - return toexpr(oop_expr, states), toexpr(ip_expr, states) + return conv(oop_expr, states), conv(ip_expr, states) else - return _build_and_inject_function(expression_module, toexpr(oop_expr, states)), - _build_and_inject_function(expression_module, toexpr(ip_expr, states)) + return _build_and_inject_function(expression_module, conv(oop_expr, states)), + _build_and_inject_function(expression_module, conv(ip_expr, states)) end end diff --git a/src/complex.jl b/src/complex.jl index e063f709f..832d2816a 100644 --- a/src/complex.jl +++ b/src/complex.jl @@ -21,6 +21,7 @@ symtype(a::ComplexTerm{T}) where T = Complex{T} istree(a::ComplexTerm) = true operation(a::ComplexTerm{T}) where T = Complex{T} arguments(a::ComplexTerm) = [a.re, a.im] +metadata(a::ComplexTerm) = a.re.metadata function similarterm(t::ComplexTerm, f, args, symtype; metadata=nothing) if f <: Complex diff --git a/src/utils.jl b/src/utils.jl index 29424c7d8..94b9433a7 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -323,6 +323,8 @@ function coeff(p, sym=nothing) else @views prod(Iterators.flatten((coeffs[findall(!iszero, coeffs)], args[findall(iszero, coeffs)]))) end + elseif isdiv(p) + throw(DomainError(p, "coeff on expressions with division is not yet implemented.")) else p isa Number && return sym === nothing ? p : 0 p isa Symbolic && return coeff(p, sym) diff --git a/test/complex.jl b/test/complex.jl index 2a24d3304..47a10b9c6 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -1,4 +1,6 @@ using Symbolics, Test +using SymbolicUtils: metadata +using Symbolics: unwrap @variables a b::Real z::Complex (Z::Complex)[1:10] @@ -26,3 +28,10 @@ end @test repr(z) == "z" @test repr(a + b*im) == "a + b*im" end + +@testset "metadata" begin + z1 = z+1.0 + @test_nowarn substitute(z1, z=>1.0im) + @test metadata(z1) == unwrap(z1.im).metadata + @test metadata(z1) == unwrap(z1.re).metadata +end