From a98609b275fc97ef867e4f5bcb1c865818e66f50 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 4 Feb 2025 23:33:46 +0530 Subject: [PATCH 1/5] test: update legacy array codegen tests --- test/arrays.jl | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/test/arrays.jl b/test/arrays.jl index 119f7aec7..d0f27bf2c 100644 --- a/test/arrays.jl +++ b/test/arrays.jl @@ -185,15 +185,10 @@ end n = 2 A = randn(n, n) foo(x) = A * x # a function to represent symbolically, note, if this function is defined inside the testset, it's not found by the function fun_eval = eval(fun_ex) -function Symbolics.propagate_ndims(::typeof(foo), x) - ndims(x) -end -function Symbolics.propagate_shape(::typeof(foo), x) - shape(x) -end -@wrapped function foo(x::AbstractVector) - t = array_term(foo, x) - setmetadata(t, Symbolics.ScalarizeCache, Ref{Any}(nothing)) +@register_array_symbolic foo(x::Vector{Real}) begin + size = (n,) + eltype = eltype(x) + ndims = 1 end #= @@ -203,33 +198,17 @@ The following two testsets test jacobians for symbolic functions of symbolic arr @testset "Functions and Jacobians using @syms" begin @variables x[1:n] - function symbolic_call(x) - @syms foo(x::Symbolics.Arr{Num,1})::Symbolics.Arr{Num,1} # symbolic foo can not be created in global scope due to conflict with function foo - foo(x) # return a symbolic call to foo - end - x0 = randn(n) @test foo(x0) == A * x0 - ex = symbolic_call(x) + ex = foo(x) - fun_genf = build_function(ex, x, expression=Val{false}) - @test_broken fun_genf(x0) == A * x0# UndefVarError: foo not defined + fun_oop, fun_iip = build_function(ex, x, expression=Val{false}) + @test fun_oop(x0) == A * x0# UndefVarError: foo not defined # Generate an expression instead and eval it manually - fun_ex = build_function(ex, x, expression=Val{true}) - fun_eval = eval(fun_ex) + fun_ex_oop, fun_ex_iip = build_function(ex, x, expression=Val{true}) + fun_eval = eval(fun_ex_oop) @test fun_eval(x0) == foo(x0) - - # Try to provide the hidden argument `expression_module` to solve the scoping issue - @test_skip begin - fun_genf = build_function(ex, x, expression=Val{false}, expression_module=Main) # UndefVarError: #_RGF_ModTag not defined - fun_genf(x0) == A * x0 - end - - ## Jacobians - @test_broken Symbolics.value.(Symbolics.jacobian(foo(x), x)) == A - @test_throws ErrorException Symbolics.value.(Symbolics.jacobian(ex , x)) - end @@ -242,11 +221,11 @@ end @test shape(ex) == shape(x) - fun_iip, fun_genf = build_function(ex, x, expression=Val{false}) - @test fun_genf(x0) == A * x0 + fun_oop, fun_iif = build_function(ex, x, expression=Val{false}) + @test fun_oop(x0) == A * x0 # Generate an expression instead and eval it manually - fun_ex_ip, fun_ex_oop = build_function(ex, x, expression=Val{true}) + fun_ex_oop, fun_ex_ip = build_function(ex, x, expression=Val{true}) fun_eval = eval(fun_ex_oop) @test fun_eval(x0) == foo(x0) From df09d0d014144d7df7d712184072d2ec65987bc0 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 4 Feb 2025 23:33:59 +0530 Subject: [PATCH 2/5] test: update tests using wrong order of build function output --- test/build_function.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/build_function.jl b/test/build_function.jl index 8e9cdd0a3..9a90ecd29 100644 --- a/test/build_function.jl +++ b/test/build_function.jl @@ -186,7 +186,7 @@ expr = toexpr(Func([value(D(x))], [], value(D(x)))) a = rand(4) @variables x[1:4] -@test eval(build_function(sin.(cos.(x)), cos.(x))[2])(a) == sin.(a) +@test eval(build_function(sin.(cos.(x)), cos.(x))[1])(a) == sin.(a) # more skipzeros @variables x,y @@ -272,7 +272,7 @@ end let #658 using Symbolics @variables a, X1[1:3], X2[1:3] - k = eval(build_function(a * X1 + X2, X1, X2, a)[2]) + k = eval(build_function(a * X1 + X2, X1, X2, a)[1]) @test k(ones(3), ones(3), 1.5) == [2.5, 2.5, 2.5] end From af4edfce4451d04147ff6c0cd7380b4ed73dcb80 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 4 Feb 2025 23:34:31 +0530 Subject: [PATCH 3/5] test: fix shadowing of `limit` imported from Symbolics --- test/arrays.jl | 36 ++++++++++++++++++------------------ test/runtests.jl | 4 ++-- test/stencils.jl | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/arrays.jl b/test/arrays.jl index d0f27bf2c..5ad257a03 100644 --- a/test/arrays.jl +++ b/test/arrays.jl @@ -4,6 +4,7 @@ using Symbolics: symtype, shape, wrap, unwrap, Unknown, Arr, array_term, jacobia using Base: Slice using SymbolicUtils: Sym, term, operation import LinearAlgebra: dot +import ..limit2 struct TestMetaT end Symbolics.option_to_metadata_type(::Val{:test_meta}) = TestMetaT @@ -336,29 +337,28 @@ end A = 3.4 alpha = 10.0 - limit = Main.limit - dtu = @arrayop (i, j) alpha * (u[limit(i - 1, n), j] + - u[limit(i + 1, n), j] + - u[i, limit(j + 1, n)] + - u[i, limit(j - 1, n)] - + dtu = @arrayop (i, j) alpha * (u[limit2(i - 1, n), j] + + u[limit2(i + 1, n), j] + + u[i, limit2(j + 1, n)] + + u[i, limit2(j - 1, n)] - 4u[i, j]) + 1.0 + u[i, j]^2 * v[i, j] - (A + 1) * u[i, j] + brusselator_f(x[i], y[j], t) i in 1:n j in 1:n - dtv = @arrayop (i, j) alpha * (v[limit(i - 1, n), j] + - v[limit(i + 1, n), j] + - v[i, limit(j + 1, n)] + - v[i, limit(j - 1, n)] - + dtv = @arrayop (i, j) alpha * (v[limit2(i - 1, n), j] + + v[limit2(i + 1, n), j] + + v[i, limit2(j + 1, n)] + + v[i, limit2(j - 1, n)] - 4v[i, j]) - u[i, j]^2 * v[i, j] + A * u[i, j] i in 1:n j in 1:n - lapu = @arrayop (i, j) (u[limit(i - 1, n), j] + - u[limit(i + 1, n), j] + - u[i, limit(j + 1, n)] + - u[i, limit(j - 1, n)] - + lapu = @arrayop (i, j) (u[limit2(i - 1, n), j] + + u[limit2(i + 1, n), j] + + u[i, limit2(j + 1, n)] + + u[i, limit2(j - 1, n)] - 4u[i, j]) i in 1:n j in 1:n - lapv = @arrayop (i, j) (v[limit(i - 1, n), j] + - v[limit(i + 1, n), j] + - v[i, limit(j + 1, n)] + - v[i, limit(j - 1, n)] - + lapv = @arrayop (i, j) (v[limit2(i - 1, n), j] + + v[limit2(i + 1, n), j] + + v[i, limit2(j + 1, n)] + + v[i, limit2(j - 1, n)] - 4v[i, j]) i in 1:n j in 1:n s = brusselator_f.(x, y', t) @@ -367,7 +367,7 @@ end lapu = wrap(lapu) lapv = wrap(lapv) - f, g = build_function(dtu, u, v, t, expression=Val{false}, nanmath = false) + g, f = build_function(dtu, u, v, t, expression=Val{false}, nanmath = false) du = zeros(Num, 8, 8) f(du, u,v,t) @test isequal(collect(du), collect(dtu)) diff --git a/test/runtests.jl b/test/runtests.jl index 5ce1b5ff2..e66697892 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,8 +20,8 @@ if haskey(ENV, "BENCHMARK_ONLY") end # this needs to be defined at top level -limit(a, N) = a == N + 1 ? 1 : a == 0 ? N : a -@register_symbolic limit(a, N)::Integer +limit2(a, N) = a == N + 1 ? 1 : a == 0 ? N : a +@register_symbolic limit2(a, N)::Integer if GROUP == "All" || GROUP == "Core" @testset begin diff --git a/test/stencils.jl b/test/stencils.jl index a9781a9ca..1940dd30c 100644 --- a/test/stencils.jl +++ b/test/stencils.jl @@ -3,6 +3,7 @@ using Symbolics using ReferenceTests using Test using SymbolicUtils.Code: toexpr, LiteralExpr +import ..limit2 _repr(x) = repr(toexpr(LiteralExpr(x)) |> Base.remove_linenums!) function test_funcs(name, f, args...; broken=false) @@ -59,8 +60,7 @@ end @variables u[1:5, 1:5] n = 5 - limit = Main.limit - y = @arrayop (i, j) u[limit(i-1, n), limit(j+1,n)] i in 1:n j in 1:n + y = @arrayop (i, j) u[limit2(i-1, n), limit2(j+1,n)] i in 1:n j in 1:n test_funcs("manual-limits", y, u) z = @arrayop (i, j) y[j, i] From 3ccd9dba60e3711877f4c9ef0cecbf246359757c Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 4 Feb 2025 23:34:43 +0530 Subject: [PATCH 4/5] test: update outplace-inplace stencil tests --- .../intermediate-exprs-inplace.jl | 27 +++++++++---------- .../intermediate-exprs-outplace.jl | 27 ++++++++++--------- .../manual-limits-inplace.jl | 13 ++++----- .../manual-limits-outplace.jl | 13 +++++---- .../stencil-broadcast-inplace.jl | 21 +++++++-------- .../stencil-broadcast-outplace.jl | 21 ++++++++------- .../stencil-extents-inplace.jl | 19 ++++++------- .../stencil-extents-outplace.jl | 19 +++++++------ .../stencil-transpose-arrayop-inplace.jl | 15 +++++------ .../stencil-transpose-arrayop-outplace.jl | 15 ++++++----- .../build_function_tests/transpose-inplace.jl | 13 ++++----- .../transpose-outplace.jl | 13 +++++---- .../transpose-term-inplace.jl | 10 +++++-- .../transpose-term-outplace.jl | 10 ++----- 14 files changed, 118 insertions(+), 118 deletions(-) diff --git a/test/build_function_tests/intermediate-exprs-inplace.jl b/test/build_function_tests/intermediate-exprs-inplace.jl index f81204b48..2ec2fa480 100644 --- a/test/build_function_tests/intermediate-exprs-inplace.jl +++ b/test/build_function_tests/intermediate-exprs-inplace.jl @@ -1,22 +1,19 @@ -:(function (u,) - let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) - begin - ˍ₋out_input_1 = let _out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) - begin - for (j, j′) = zip(1:5, reset_to_one(1:5)) - for (i, i′) = zip(1:5, reset_to_one(1:5)) - _out[i′, j′] = (+)(_out[i′, j′], (getindex)(u, (Main.limit)((+)(-1, i), 5), (Main.limit)((+)(1, j), 5))) - end +:(function (ˍ₋out, u) + begin + ˍ₋out_input_1 = let _out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) + begin + for (j, j′) = zip(1:5, reset_to_one(1:5)) + for (i, i′) = zip(1:5, reset_to_one(1:5)) + _out[i′, j′] = (+)(_out[i′, j′], (getindex)(u, (Main.limit2)((+)(-1, i), 5), (Main.limit2)((+)(1, j), 5))) end end - _out - end - for (j, j′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) - for (i, i′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(ˍ₋out_input_1, j, i)) end + _out + end + for (j, j′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) + for (i, i′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(ˍ₋out_input_1, j, i)) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/intermediate-exprs-outplace.jl b/test/build_function_tests/intermediate-exprs-outplace.jl index 8113cf9e1..c9599c279 100644 --- a/test/build_function_tests/intermediate-exprs-outplace.jl +++ b/test/build_function_tests/intermediate-exprs-outplace.jl @@ -1,19 +1,22 @@ -:(function (ˍ₋out, u) - begin - ˍ₋out_input_1 = let _out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) - begin - for (j, j′) = zip(1:5, reset_to_one(1:5)) - for (i, i′) = zip(1:5, reset_to_one(1:5)) - _out[i′, j′] = (+)(_out[i′, j′], (getindex)(u, (Main.limit)((+)(-1, i), 5), (Main.limit)((+)(1, j), 5))) +:(function (u,) + let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) + begin + ˍ₋out_input_1 = let _out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) + begin + for (j, j′) = zip(1:5, reset_to_one(1:5)) + for (i, i′) = zip(1:5, reset_to_one(1:5)) + _out[i′, j′] = (+)(_out[i′, j′], (getindex)(u, (Main.limit2)((+)(-1, i), 5), (Main.limit2)((+)(1, j), 5))) + end end end + _out + end + for (j, j′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) + for (i, i′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(ˍ₋out_input_1, j, i)) end - _out - end - for (j, j′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) - for (i, i′) = zip(Base.OneTo(5), reset_to_one(Base.OneTo(5))) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(ˍ₋out_input_1, j, i)) end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/manual-limits-inplace.jl b/test/build_function_tests/manual-limits-inplace.jl index 5c8590138..d3ed5d330 100644 --- a/test/build_function_tests/manual-limits-inplace.jl +++ b/test/build_function_tests/manual-limits-inplace.jl @@ -1,12 +1,9 @@ -:(function (u,) - let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) - begin - for (j, j′) = zip(1:5, reset_to_one(1:5)) - for (i, i′) = zip(1:5, reset_to_one(1:5)) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(u, (Main.limit)((+)(-1, i), 5), (Main.limit)((+)(1, j), 5))) - end +:(function (ˍ₋out, u) + begin + for (j, j′) = zip(1:5, reset_to_one(1:5)) + for (i, i′) = zip(1:5, reset_to_one(1:5)) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(u, (Main.limit2)((+)(-1, i), 5), (Main.limit2)((+)(1, j), 5))) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/manual-limits-outplace.jl b/test/build_function_tests/manual-limits-outplace.jl index 85d19be7b..099cf69ff 100644 --- a/test/build_function_tests/manual-limits-outplace.jl +++ b/test/build_function_tests/manual-limits-outplace.jl @@ -1,9 +1,12 @@ -:(function (ˍ₋out, u) - begin - for (j, j′) = zip(1:5, reset_to_one(1:5)) - for (i, i′) = zip(1:5, reset_to_one(1:5)) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(u, (Main.limit)((+)(-1, i), 5), (Main.limit)((+)(1, j), 5))) +:(function (u,) + let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(5), Base.OneTo(5)))) + begin + for (j, j′) = zip(1:5, reset_to_one(1:5)) + for (i, i′) = zip(1:5, reset_to_one(1:5)) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(u, (Main.limit2)((+)(-1, i), 5), (Main.limit2)((+)(1, j), 5))) + end end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-broadcast-inplace.jl b/test/build_function_tests/stencil-broadcast-inplace.jl index 8e7331058..2d2b6d2aa 100644 --- a/test/build_function_tests/stencil-broadcast-inplace.jl +++ b/test/build_function_tests/stencil-broadcast-inplace.jl @@ -1,16 +1,13 @@ -:(function (x,) - let ˍ₋out = zeros(Float64, map(length, (1:6, 1:6))) - begin - ˍ₋out_2_input_1 = (broadcast)(+, x, (adjoint)(x)) - ˍ₋out_1 = (view)(ˍ₋out, 1:6, 1:6) - ˍ₋out_1 .= 0 - ˍ₋out_2 = (view)(ˍ₋out, 2:5, 2:5) - for (j, j′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) - for (i, i′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) - ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (+)(1, (getindex)(ˍ₋out_2_input_1, i, j))) - end +:(function (ˍ₋out, x) + begin + ˍ₋out_2_input_1 = (broadcast)(+, x, (adjoint)(x)) + ˍ₋out_1 = (view)(ˍ₋out, 1:6, 1:6) + ˍ₋out_1 .= 0 + ˍ₋out_2 = (view)(ˍ₋out, 2:5, 2:5) + for (j, j′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) + for (i, i′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) + ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (+)(1, (getindex)(ˍ₋out_2_input_1, i, j))) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-broadcast-outplace.jl b/test/build_function_tests/stencil-broadcast-outplace.jl index 2d2b6d2aa..8e7331058 100644 --- a/test/build_function_tests/stencil-broadcast-outplace.jl +++ b/test/build_function_tests/stencil-broadcast-outplace.jl @@ -1,13 +1,16 @@ -:(function (ˍ₋out, x) - begin - ˍ₋out_2_input_1 = (broadcast)(+, x, (adjoint)(x)) - ˍ₋out_1 = (view)(ˍ₋out, 1:6, 1:6) - ˍ₋out_1 .= 0 - ˍ₋out_2 = (view)(ˍ₋out, 2:5, 2:5) - for (j, j′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) - for (i, i′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) - ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (+)(1, (getindex)(ˍ₋out_2_input_1, i, j))) +:(function (x,) + let ˍ₋out = zeros(Float64, map(length, (1:6, 1:6))) + begin + ˍ₋out_2_input_1 = (broadcast)(+, x, (adjoint)(x)) + ˍ₋out_1 = (view)(ˍ₋out, 1:6, 1:6) + ˍ₋out_1 .= 0 + ˍ₋out_2 = (view)(ˍ₋out, 2:5, 2:5) + for (j, j′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) + for (i, i′) = zip(Base.OneTo(4), reset_to_one(Base.OneTo(4))) + ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (+)(1, (getindex)(ˍ₋out_2_input_1, i, j))) + end end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-extents-inplace.jl b/test/build_function_tests/stencil-extents-inplace.jl index 20069daef..e063cf0b3 100644 --- a/test/build_function_tests/stencil-extents-inplace.jl +++ b/test/build_function_tests/stencil-extents-inplace.jl @@ -1,15 +1,12 @@ -:(function (x,) - let ˍ₋out = zeros(Float64, map(length, (1:5, 1:5))) - begin - ˍ₋out_1 = (view)(ˍ₋out, 1:5, 1:5) - ˍ₋out_1 .= 0 - ˍ₋out_2 = (view)(ˍ₋out, 2:4, 2:4) - for (j, j′) = zip(2:4, reset_to_one(2:4)) - for (i, i′) = zip(2:4, reset_to_one(2:4)) - ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (*)(1//2, (+)((+)((+)((getindex)(x, (+)(-1, i), j), (getindex)(x, (+)(1, i), j)), (getindex)(x, i, (+)(-1, j))), (getindex)(x, i, (+)(1, j))))) - end +:(function (ˍ₋out, x) + begin + ˍ₋out_1 = (view)(ˍ₋out, 1:5, 1:5) + ˍ₋out_1 .= 0 + ˍ₋out_2 = (view)(ˍ₋out, 2:4, 2:4) + for (j, j′) = zip(2:4, reset_to_one(2:4)) + for (i, i′) = zip(2:4, reset_to_one(2:4)) + ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (*)(1//2, (+)((+)((+)((getindex)(x, (+)(-1, i), j), (getindex)(x, (+)(1, i), j)), (getindex)(x, i, (+)(-1, j))), (getindex)(x, i, (+)(1, j))))) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-extents-outplace.jl b/test/build_function_tests/stencil-extents-outplace.jl index e063cf0b3..20069daef 100644 --- a/test/build_function_tests/stencil-extents-outplace.jl +++ b/test/build_function_tests/stencil-extents-outplace.jl @@ -1,12 +1,15 @@ -:(function (ˍ₋out, x) - begin - ˍ₋out_1 = (view)(ˍ₋out, 1:5, 1:5) - ˍ₋out_1 .= 0 - ˍ₋out_2 = (view)(ˍ₋out, 2:4, 2:4) - for (j, j′) = zip(2:4, reset_to_one(2:4)) - for (i, i′) = zip(2:4, reset_to_one(2:4)) - ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (*)(1//2, (+)((+)((+)((getindex)(x, (+)(-1, i), j), (getindex)(x, (+)(1, i), j)), (getindex)(x, i, (+)(-1, j))), (getindex)(x, i, (+)(1, j))))) +:(function (x,) + let ˍ₋out = zeros(Float64, map(length, (1:5, 1:5))) + begin + ˍ₋out_1 = (view)(ˍ₋out, 1:5, 1:5) + ˍ₋out_1 .= 0 + ˍ₋out_2 = (view)(ˍ₋out, 2:4, 2:4) + for (j, j′) = zip(2:4, reset_to_one(2:4)) + for (i, i′) = zip(2:4, reset_to_one(2:4)) + ˍ₋out_2[i′, j′] = (+)(ˍ₋out_2[i′, j′], (*)(1//2, (+)((+)((+)((getindex)(x, (+)(-1, i), j), (getindex)(x, (+)(1, i), j)), (getindex)(x, i, (+)(-1, j))), (getindex)(x, i, (+)(1, j))))) + end end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-transpose-arrayop-inplace.jl b/test/build_function_tests/stencil-transpose-arrayop-inplace.jl index b16912590..ed58d0356 100644 --- a/test/build_function_tests/stencil-transpose-arrayop-inplace.jl +++ b/test/build_function_tests/stencil-transpose-arrayop-inplace.jl @@ -1,13 +1,10 @@ -:(function (x,) - let ˍ₋out = zeros(Float64, map(length, (1:6, 1:6))) - begin - ˍ₋out_1 = (view)(ˍ₋out, 2:5, 2:5) - for (j, j′) = zip(1:4, reset_to_one(1:4)) - for (i, i′) = zip(1:4, reset_to_one(1:4)) - ˍ₋out_1[i′, j′] = (+)(ˍ₋out_1[i′, j′], (getindex)(x, j, i)) - end +:(function (ˍ₋out, x) + begin + ˍ₋out_1 = (view)(ˍ₋out, 2:5, 2:5) + for (j, j′) = zip(1:4, reset_to_one(1:4)) + for (i, i′) = zip(1:4, reset_to_one(1:4)) + ˍ₋out_1[i′, j′] = (+)(ˍ₋out_1[i′, j′], (getindex)(x, j, i)) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/stencil-transpose-arrayop-outplace.jl b/test/build_function_tests/stencil-transpose-arrayop-outplace.jl index ed58d0356..b16912590 100644 --- a/test/build_function_tests/stencil-transpose-arrayop-outplace.jl +++ b/test/build_function_tests/stencil-transpose-arrayop-outplace.jl @@ -1,10 +1,13 @@ -:(function (ˍ₋out, x) - begin - ˍ₋out_1 = (view)(ˍ₋out, 2:5, 2:5) - for (j, j′) = zip(1:4, reset_to_one(1:4)) - for (i, i′) = zip(1:4, reset_to_one(1:4)) - ˍ₋out_1[i′, j′] = (+)(ˍ₋out_1[i′, j′], (getindex)(x, j, i)) +:(function (x,) + let ˍ₋out = zeros(Float64, map(length, (1:6, 1:6))) + begin + ˍ₋out_1 = (view)(ˍ₋out, 2:5, 2:5) + for (j, j′) = zip(1:4, reset_to_one(1:4)) + for (i, i′) = zip(1:4, reset_to_one(1:4)) + ˍ₋out_1[i′, j′] = (+)(ˍ₋out_1[i′, j′], (getindex)(x, j, i)) + end end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/transpose-inplace.jl b/test/build_function_tests/transpose-inplace.jl index 3e139301e..7d9dc7671 100644 --- a/test/build_function_tests/transpose-inplace.jl +++ b/test/build_function_tests/transpose-inplace.jl @@ -1,12 +1,9 @@ -:(function (x,) - let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(4), Base.OneTo(4)))) - begin - for (j, j′) = zip(1:4, reset_to_one(1:4)) - for (i, i′) = zip(1:4, reset_to_one(1:4)) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) - end +:(function (ˍ₋out, x) + begin + for (j, j′) = zip(1:4, reset_to_one(1:4)) + for (i, i′) = zip(1:4, reset_to_one(1:4)) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) end end - ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/transpose-outplace.jl b/test/build_function_tests/transpose-outplace.jl index 7d9dc7671..3e139301e 100644 --- a/test/build_function_tests/transpose-outplace.jl +++ b/test/build_function_tests/transpose-outplace.jl @@ -1,9 +1,12 @@ -:(function (ˍ₋out, x) - begin - for (j, j′) = zip(1:4, reset_to_one(1:4)) - for (i, i′) = zip(1:4, reset_to_one(1:4)) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) +:(function (x,) + let ˍ₋out = zeros(Float64, map(length, (Base.OneTo(4), Base.OneTo(4)))) + begin + for (j, j′) = zip(1:4, reset_to_one(1:4)) + for (i, i′) = zip(1:4, reset_to_one(1:4)) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) + end end end + ˍ₋out end end) \ No newline at end of file diff --git a/test/build_function_tests/transpose-term-inplace.jl b/test/build_function_tests/transpose-term-inplace.jl index 3dcb4066e..7d9dc7671 100644 --- a/test/build_function_tests/transpose-term-inplace.jl +++ b/test/build_function_tests/transpose-term-inplace.jl @@ -1,3 +1,9 @@ -:(function (x,) - (adjoint)(x) +:(function (ˍ₋out, x) + begin + for (j, j′) = zip(1:4, reset_to_one(1:4)) + for (i, i′) = zip(1:4, reset_to_one(1:4)) + ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) + end + end + end end) \ No newline at end of file diff --git a/test/build_function_tests/transpose-term-outplace.jl b/test/build_function_tests/transpose-term-outplace.jl index 7d9dc7671..3dcb4066e 100644 --- a/test/build_function_tests/transpose-term-outplace.jl +++ b/test/build_function_tests/transpose-term-outplace.jl @@ -1,9 +1,3 @@ -:(function (ˍ₋out, x) - begin - for (j, j′) = zip(1:4, reset_to_one(1:4)) - for (i, i′) = zip(1:4, reset_to_one(1:4)) - ˍ₋out[i′, j′] = (+)(ˍ₋out[i′, j′], (getindex)(x, j, i)) - end - end - end +:(function (x,) + (adjoint)(x) end) \ No newline at end of file From eced9006aed4da01da8413537fd02171dd2c361e Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 4 Feb 2025 23:36:21 +0530 Subject: [PATCH 5/5] test: temporarily comment test requiring SymbolicUtils changes --- test/build_function.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/build_function.jl b/test/build_function.jl index 9a90ecd29..3714cfd3e 100644 --- a/test/build_function.jl +++ b/test/build_function.jl @@ -302,14 +302,14 @@ end end end -@testset "cse with arrayops" begin - @variables x[1:3] y f(..) - t = x .+ y - t = t .* f(t) - res = cse(value(t)) - @test res isa Let - @test !isempty(res.pairs) -end +# @testset "cse with arrayops" begin +# @variables x[1:3] y f(..) +# t = x .+ y +# t = t .* f(t) +# res = cse(value(t)) +# @test res isa Let +# @test !isempty(res.pairs) +# end @testset "`CallWithMetadata` in `DestructuredArgs` with `create_bindings = false`" begin @variables x f(..)