Skip to content

Commit

Permalink
Merge branch 'JuliaSymbolics:master' into vector-calc
Browse files Browse the repository at this point in the history
  • Loading branch information
xtalax authored Sep 4, 2023
2 parents af60a35 + 60d26bb commit dc4a596
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
- '1'
- '1.6'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: |
if [ "`git rev-parse --abbrev-ref HEAD`" != master ]; then git fetch origin master:master; fi
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
- uses: actions/cache@v1
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
with:
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions src/build_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Symbolics, Test
using SymbolicUtils: metadata
using Symbolics: unwrap

@variables a b::Real z::Complex (Z::Complex)[1:10]

Expand Down Expand Up @@ -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

0 comments on commit dc4a596

Please sign in to comment.