diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92fd1320..3cb18556 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,36 @@ jobs: - uses: julia-actions/julia-uploadcodecov@latest env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + test-downstream: + name: Julia ${{ matrix.version }} downstream - ${{ matrix.package }} [${{ matrix.env }}] + runs-on: ubuntu-latest + strategy: + matrix: + version: + - '1.10' + - '1' + package: + - 'Mooncake' + env: + - 'old' + - 'new' + env: + STATICARRAYS_DOWNSTREAM_TEST_PACKAGE: ${{ matrix.package }} + STATICARRAYS_DOWNSTREAM_TEST_ENV: ${{ matrix.env }} + steps: + - uses: actions/checkout@v6 + - uses: julia-actions/setup-julia@v3 + with: + version: ${{ matrix.version }} + - uses: julia-actions/cache@v3 + - uses: julia-actions/julia-buildpkg@v1 + - run: julia -O1 --code-coverage=user --color=yes test/downstream/harness.jl + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v6 + with: + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false docs: name: Documentation runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 94cabef0..d9bc4633 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /benchmark/*.json /benchmark/Manifest.toml /docs/Manifest.toml +/test/downstream/**/Manifest.toml \ No newline at end of file diff --git a/Project.toml b/Project.toml index ba8ee58d..c460612e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StaticArrays" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.9.18" +version = "1.9.19" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -11,10 +11,12 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [weakdeps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [extensions] StaticArraysChainRulesCoreExt = "ChainRulesCore" +StaticArraysMooncakeExt = "Mooncake" StaticArraysStatisticsExt = "Statistics" [compat] @@ -25,6 +27,7 @@ ChainRulesTestUtils = "1" InteractiveUtils = "1" JLArrays = "0.1" LinearAlgebra = "1.6" +Mooncake = "0.5" OffsetArrays = "1" PrecompileTools = "1" Random = "1.6" @@ -41,6 +44,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" +Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/ext/StaticArraysMooncakeExt.jl b/ext/StaticArraysMooncakeExt.jl new file mode 100644 index 00000000..22ede3cc --- /dev/null +++ b/ext/StaticArraysMooncakeExt.jl @@ -0,0 +1,13 @@ +module StaticArraysMooncakeExt + +using StaticArrays: SArray,MArray +using Mooncake: Mooncake + +@static if isdefined(Mooncake, :FriendlyTangentCache) # checks Mooncake >= v0.5.25 + # see https://github.com/JuliaDiff/DifferentiationInterface.jl/issues/998 + function Mooncake.friendly_tangent_cache(x::Union{SArray,MArray}) + return Mooncake.FriendlyTangentCache{Mooncake.AsPrimal}(copy(x)) + end +end + +end diff --git a/test/downstream/Mooncake/new/Project.toml b/test/downstream/Mooncake/new/Project.toml new file mode 100644 index 00000000..586dd7e8 --- /dev/null +++ b/test/downstream/Mooncake/new/Project.toml @@ -0,0 +1,10 @@ +[deps] +Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[sources] +StaticArrays = {path = "../../../.."} + +[compat] +Mooncake = ">=0.5.25" diff --git a/test/downstream/Mooncake/old/Project.toml b/test/downstream/Mooncake/old/Project.toml new file mode 100644 index 00000000..5427876c --- /dev/null +++ b/test/downstream/Mooncake/old/Project.toml @@ -0,0 +1,10 @@ +[deps] +Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[sources] +StaticArrays = {path = "../../../.."} + +[compat] +Mooncake = "<0.5.25" diff --git a/test/downstream/Mooncake/test.jl b/test/downstream/Mooncake/test.jl new file mode 100644 index 00000000..1b0bcd9c --- /dev/null +++ b/test/downstream/Mooncake/test.jl @@ -0,0 +1,20 @@ +using StaticArrays +using Mooncake +using Test + +@testset verbose=true "Mooncake integration" begin + f(x) = sum(abs2, x) + config = Mooncake.Config(; friendly_tangents=true) + @testset "$(typeof(x))" for x in [ + SVector(1.0, 2.0), + MVector(1.0, 2.0) , + SMatrix{2,2}(1.0, 2.0, 3.0, 4.0), + MMatrix{2,2}(1.0, 2.0, 3.0, 4.0) + ] + cache = prepare_gradient_cache(f, zero(x); config) + val, grads = value_and_gradient!!(cache, f, x) + g = grads[2] + @test g isa typeof(x) + @test g == 2x + end +end diff --git a/test/downstream/harness.jl b/test/downstream/harness.jl new file mode 100644 index 00000000..97aaabbf --- /dev/null +++ b/test/downstream/harness.jl @@ -0,0 +1,6 @@ +using Pkg +package = ENV["STATICARRAYS_DOWNSTREAM_TEST_PACKAGE"]; +env = ENV["STATICARRAYS_DOWNSTREAM_TEST_ENV"]; +Pkg.activate(joinpath(@__DIR__, package, env)) +Pkg.develop(PackageSpec(path=joinpath(@__DIR__, "..", ".."))) +include(joinpath(package, "test.jl"))