From 6d282ac97579c8a175f2a75b318984bc4dd4d5f9 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 18:21:24 -0500 Subject: [PATCH 1/6] Package setup --- README.md | 84 ------------------- TODO.md | 1 + examples/Project.toml | 4 - examples/README.jl | 79 ----------------- src/DiagonalArrays.jl | 2 + .../abstractdiagonalarray.jl | 2 +- src/abstractdiagonalarray/arraylayouts.jl | 2 +- .../diagonalarraydiaginterface.jl | 2 +- .../sparsearrayinterface.jl | 2 +- src/diagonalarray/diagonalarray.jl | 4 +- test/runtests.jl | 5 +- 11 files changed, 10 insertions(+), 177 deletions(-) delete mode 100644 README.md create mode 100644 TODO.md delete mode 100644 examples/Project.toml delete mode 100644 examples/README.jl diff --git a/README.md b/README.md deleted file mode 100644 index 1043d09..0000000 --- a/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# DiagonalArrays.jl - -A Julia `DiagonalArray` type. - -````julia -using NDTensors.DiagonalArrays: - DiagonalArray, DiagonalMatrix, DiagIndex, DiagIndices, diaglength, isdiagindex -using Test - -function main() - d = DiagonalMatrix([1.0, 2.0, 3.0]) - @test eltype(d) == Float64 - @test diaglength(d) == 3 - @test size(d) == (3, 3) - @test d[1, 1] == 1 - @test d[2, 2] == 2 - @test d[3, 3] == 3 - @test d[1, 2] == 0 - - d = DiagonalArray([1.0, 2.0, 3.0], 3, 4, 5) - @test eltype(d) == Float64 - @test diaglength(d) == 3 - @test d[1, 1, 1] == 1 - @test d[2, 2, 2] == 2 - @test d[3, 3, 3] == 3 - @test d[1, 2, 1] == 0 - - d[2, 2, 2] = 22 - @test d[2, 2, 2] == 22 - - d_r = reshape(d, 3, 20) - @test size(d_r) == (3, 20) - @test all(I -> d_r[I] == d[I], LinearIndices(d)) - - @test length(d[DiagIndices(:)]) == 3 - @test Array(d) == d - @test d[DiagIndex(2)] == d[2, 2, 2] - - d[DiagIndex(2)] = 222 - @test d[2, 2, 2] == 222 - - a = randn(3, 4, 5) - new_diag = randn(3) - a[DiagIndices(:)] = new_diag - d[DiagIndices(:)] = a[DiagIndices(:)] - - @test a[DiagIndices(:)] == new_diag - @test d[DiagIndices(:)] == new_diag - - permuted_d = permutedims(d, (3, 2, 1)) - @test permuted_d isa DiagonalArray - @test permuted_d[DiagIndices(:)] == d[DiagIndices(:)] - @test size(d) == (3, 4, 5) - @test size(permuted_d) == (5, 4, 3) - for I in eachindex(d) - if !isdiagindex(d, I) - @test iszero(d[I]) - else - @test !iszero(d[I]) - end - end - - mapped_d = map(x -> 2x, d) - @test mapped_d isa DiagonalArray - @test mapped_d == map(x -> 2x, Array(d)) - - return nothing -end - -main() -```` - -You can generate this README with: -```julia -using Literate -using NDTensors.DiagonalArrays -dir = joinpath(pkgdir(DiagonalArrays), "src", "lib", "DiagonalArrays") -Literate.markdown(joinpath(dir, "examples", "README.jl"), dir; flavor=Literate.CommonMarkFlavor()) -``` - ---- - -*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* - diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..bdf465c --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +- Remove Compat dependency. diff --git a/examples/Project.toml b/examples/Project.toml deleted file mode 100644 index b46e6ac..0000000 --- a/examples/Project.toml +++ /dev/null @@ -1,4 +0,0 @@ -[deps] -Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" -NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/examples/README.jl b/examples/README.jl deleted file mode 100644 index 074adec..0000000 --- a/examples/README.jl +++ /dev/null @@ -1,79 +0,0 @@ -# # DiagonalArrays.jl -# -# A Julia `DiagonalArray` type. - -using NDTensors.DiagonalArrays: - DiagonalArray, DiagonalMatrix, DiagIndex, DiagIndices, diaglength, isdiagindex -using Test - -function main() - d = DiagonalMatrix([1.0, 2.0, 3.0]) - @test eltype(d) == Float64 - @test diaglength(d) == 3 - @test size(d) == (3, 3) - @test d[1, 1] == 1 - @test d[2, 2] == 2 - @test d[3, 3] == 3 - @test d[1, 2] == 0 - - d = DiagonalArray([1.0, 2.0, 3.0], 3, 4, 5) - @test eltype(d) == Float64 - @test diaglength(d) == 3 - @test d[1, 1, 1] == 1 - @test d[2, 2, 2] == 2 - @test d[3, 3, 3] == 3 - @test d[1, 2, 1] == 0 - - d[2, 2, 2] = 22 - @test d[2, 2, 2] == 22 - - d_r = reshape(d, 3, 20) - @test size(d_r) == (3, 20) - @test all(I -> d_r[I] == d[I], LinearIndices(d)) - - @test length(d[DiagIndices(:)]) == 3 - @test Array(d) == d - @test d[DiagIndex(2)] == d[2, 2, 2] - - d[DiagIndex(2)] = 222 - @test d[2, 2, 2] == 222 - - a = randn(3, 4, 5) - new_diag = randn(3) - a[DiagIndices(:)] = new_diag - d[DiagIndices(:)] = a[DiagIndices(:)] - - @test a[DiagIndices(:)] == new_diag - @test d[DiagIndices(:)] == new_diag - - permuted_d = permutedims(d, (3, 2, 1)) - @test permuted_d isa DiagonalArray - @test permuted_d[DiagIndices(:)] == d[DiagIndices(:)] - @test size(d) == (3, 4, 5) - @test size(permuted_d) == (5, 4, 3) - for I in eachindex(d) - if !isdiagindex(d, I) - @test iszero(d[I]) - else - @test !iszero(d[I]) - end - end - - mapped_d = map(x -> 2x, d) - @test mapped_d isa DiagonalArray - @test mapped_d == map(x -> 2x, Array(d)) - - return nothing -end - -main() - -#= -You can generate this README with: -```julia -using Literate -using NDTensors.DiagonalArrays -dir = joinpath(pkgdir(DiagonalArrays), "src", "lib", "DiagonalArrays") -Literate.markdown(joinpath(dir, "examples", "README.jl"), dir; flavor=Literate.CommonMarkFlavor()) -``` -=# diff --git a/src/DiagonalArrays.jl b/src/DiagonalArrays.jl index 94566eb..6f3d972 100644 --- a/src/DiagonalArrays.jl +++ b/src/DiagonalArrays.jl @@ -1,4 +1,5 @@ module DiagonalArrays + include("diaginterface/defaults.jl") include("diaginterface/diaginterface.jl") include("diaginterface/diagindex.jl") @@ -11,4 +12,5 @@ include("diagonalarray/diagonalarray.jl") include("diagonalarray/diagonalmatrix.jl") include("diagonalarray/diagonalvector.jl") include("diagonalarray/arraylayouts.jl") + end diff --git a/src/abstractdiagonalarray/abstractdiagonalarray.jl b/src/abstractdiagonalarray/abstractdiagonalarray.jl index 8180a61..3c0bdd6 100644 --- a/src/abstractdiagonalarray/abstractdiagonalarray.jl +++ b/src/abstractdiagonalarray/abstractdiagonalarray.jl @@ -1,3 +1,3 @@ -using ..SparseArraysBase: AbstractSparseArray +using SparseArraysBase: AbstractSparseArray abstract type AbstractDiagonalArray{T,N} <: AbstractSparseArray{T,N} end diff --git a/src/abstractdiagonalarray/arraylayouts.jl b/src/abstractdiagonalarray/arraylayouts.jl index d8f0b41..39285cf 100644 --- a/src/abstractdiagonalarray/arraylayouts.jl +++ b/src/abstractdiagonalarray/arraylayouts.jl @@ -1,5 +1,5 @@ using ArrayLayouts: ArrayLayouts -using ..SparseArraysBase: AbstractSparseLayout +using SparseArraysBase: AbstractSparseLayout abstract type AbstractDiagonalLayout <: AbstractSparseLayout end struct DiagonalLayout <: AbstractDiagonalLayout end diff --git a/src/abstractdiagonalarray/diagonalarraydiaginterface.jl b/src/abstractdiagonalarray/diagonalarraydiaginterface.jl index bcc2c81..b8fe8e8 100644 --- a/src/abstractdiagonalarray/diagonalarraydiaginterface.jl +++ b/src/abstractdiagonalarray/diagonalarraydiaginterface.jl @@ -1,4 +1,4 @@ -using ..SparseArraysBase: SparseArraysBase, StorageIndex, StorageIndices +using SparseArraysBase: SparseArraysBase, StorageIndex, StorageIndices SparseArraysBase.StorageIndex(i::DiagIndex) = StorageIndex(index(i)) diff --git a/src/abstractdiagonalarray/sparsearrayinterface.jl b/src/abstractdiagonalarray/sparsearrayinterface.jl index 98762bb..b5779a0 100644 --- a/src/abstractdiagonalarray/sparsearrayinterface.jl +++ b/src/abstractdiagonalarray/sparsearrayinterface.jl @@ -1,5 +1,5 @@ using Compat: Returns, allequal -using ..SparseArraysBase: SparseArraysBase +using SparseArraysBase: SparseArraysBase # `SparseArraysBase` interface function SparseArraysBase.index_to_storage_index( diff --git a/src/diagonalarray/diagonalarray.jl b/src/diagonalarray/diagonalarray.jl index 6f3fc95..f64c211 100644 --- a/src/diagonalarray/diagonalarray.jl +++ b/src/diagonalarray/diagonalarray.jl @@ -1,6 +1,4 @@ -using ..SparseArraysBase: Zero, getindex_zero_function -# TODO: Put into `DiagonalArraysSparseArraysBaseExt`? -using ..SparseArraysBase: SparseArraysBase, SparseArrayDOK +using SparseArraysBase: SparseArraysBase, SparseArrayDOK, Zero, getindex_zero_function struct DiagonalArray{T,N,Diag<:AbstractVector{T},Zero} <: AbstractDiagonalArray{T,N} diag::Diag diff --git a/test/runtests.jl b/test/runtests.jl index af43973..151c67b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,7 @@ @eval module $(gensym()) using Test: @test, @testset, @test_broken -using NDTensors.DiagonalArrays: DiagonalArrays, DiagonalArray, DiagonalMatrix, diaglength -using NDTensors.SparseArraysBase: SparseArrayDOK -using NDTensors.SparseArraysBase: stored_length +using DiagonalArrays: DiagonalArrays, DiagonalArray, DiagonalMatrix, diaglength +using SparseArraysBase: SparseArrayDOK, stored_length @testset "Test NDTensors.DiagonalArrays" begin @testset "README" begin @test include( From 531aa024eb99df46749583f1718787793cfd3d9d Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 18:31:59 -0500 Subject: [PATCH 2/6] Package setup --- .JuliaFormatter.toml | 1 + .github/ISSUE_TEMPLATE/BUG_REPORT.md | 62 ++++++++++++++++ .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md | 24 +++++++ .github/PULL_REQUEST_TEMPLATE.md | 42 +++++++++++ .github/dependabot.yml | 7 ++ .github/workflows/CI.yml | 79 ++++++++++++++++++++ .github/workflows/CompatHelper.yml | 16 +++++ .github/workflows/FormatCheck.yml | 35 +++++++++ .github/workflows/LiterateCheck.yml | 39 ++++++++++ .github/workflows/Register.yml | 16 +++++ .github/workflows/TagBot.yml | 31 ++++++++ .gitignore | 14 ++++ .pre-commit-config.yaml | 13 ++++ LICENSE | 21 ++++++ Project.toml | 16 +++++ README.md | 29 ++++++++ benchmark/benchmarks.jl | 7 ++ docs/Project.toml | 4 ++ docs/make.jl | 24 +++++++ docs/make_index.jl | 9 +++ docs/make_readme.jl | 9 +++ examples/Project.toml | 2 + examples/README.jl | 88 +++++++++++++++++++++++ 23 files changed, 588 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/BUG_REPORT.md create mode 100644 .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/CompatHelper.yml create mode 100644 .github/workflows/FormatCheck.yml create mode 100644 .github/workflows/LiterateCheck.yml create mode 100644 .github/workflows/Register.yml create mode 100644 .github/workflows/TagBot.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 LICENSE create mode 100644 Project.toml create mode 100644 README.md create mode 100644 benchmark/benchmarks.jl create mode 100644 docs/Project.toml create mode 100644 docs/make.jl create mode 100644 docs/make_index.jl create mode 100644 docs/make_readme.jl create mode 100644 examples/Project.toml create mode 100644 examples/README.jl diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 08f664c..4c49a86 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1,2 +1,3 @@ +# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options style = "blue" indent = 2 diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md new file mode 100644 index 0000000..fbb5b64 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -0,0 +1,62 @@ +--- +name: DiagonalArrays.jl bug report +about: Create a bug report to help us improve DiagonalArrays.jl +title: "[BUG] YOUR SHORT DESCRIPTION OF THE BUG HERE" +labels: ["bug"] +assignees: '' + +--- + +**Description of bug** + +Please give a brief description of the bug or unexpected behavior here. + +**Minimal code demonstrating the bug or unexpected behavior** + +If applicable, provide a minimal code that can be run to demonstrate the bug or unexpected behavior. + +If you are unable to construct a minimal code that demonstrates the bug or unexpected behavior, provide detailed steps for how to reproduce the behavior you are seeing. + +
Minimal runnable code

+ +```julia +[YOUR MINIMAL RUNNABLE CODE HERE] +``` + +

+ + +**Expected output or behavior** + +Describe what you expected to happen. + +If you provided a minimal code that can be run to demonstrate the bug or unexpected behavior, describe what you expected the output would be. + + +**Actual output or behavior** + +Describe what actually happened. + +If you provided a minimal code that demonstrates the bug or unexpected behavior, provide the output you get from that code. If the code leads to an error or warning, include the full error or warning below. + +
Output of minimal runnable code

+ +```julia +[OUTPUT OF YOUR MINIMAL RUNNABLE CODE HERE] +``` + +

+ + +**Version information** + + - Output from `versioninfo()`: +```julia +julia> versioninfo() +[YOUR OUTPUT HERE] +``` + - Output from `using Pkg; Pkg.status("DiagonalArrays")`: +```julia +julia> using Pkg; Pkg.status("DiagonalArrays") +[YOUR OUTPUT HERE] +``` diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md new file mode 100644 index 0000000..7b83ba0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md @@ -0,0 +1,24 @@ +--- +name: DiagonalArrays.jl feature request +about: Suggest an idea for DiagonalArrays.jl +title: "[ENHANCEMENT] YOUR SHORT DESCRIPTION OF THE FEATURE REQUEST HERE" +labels: ["enhancement"] +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** + +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** + +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** + +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** + +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..1f41851 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,42 @@ +# Description + +Please include a summary of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes #(issue) + +If practical and applicable, please include a minimal demonstration of the previous behavior and new behavior below. + +
Minimal demonstration of previous behavior

+ +```julia +[YOUR MINIMAL DEMONSTRATION OF PREVIOUS BEHAVIOR] +``` + +

+ +
Minimal demonstration of new behavior

+ +```julia +[YOUR MINIMAL DEMONSTRATION OF NEW BEHAVIOR] +``` + +

+ +# How Has This Been Tested? + +Please add tests that verify your changes to a file in the `test` directory. + +Please give a summary of the tests that you added to verify your changes. + +- [ ] Test A +- [ ] Test B + +# Checklist: + +- [ ] My code follows the style guidelines of this project. Please run `using JuliaFormatter; format(".")` in the base directory of the repository (`~/.julia/dev/DiagonalArrays`) to format your code according to our style guidelines. +- [ ] I have performed a self-review of my own code. +- [ ] I have commented my code, particularly in hard-to-understand areas. +- [ ] I have added tests that verify the behavior of the changes I made. +- [ ] I have made corresponding changes to the documentation. +- [ ] My changes generate no new warnings. +- [ ] Any dependent changes have been merged and published in downstream modules. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..700707c --- /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: "weekly" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..be96cb9 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,79 @@ +name: CI +on: + push: + branches: + - main + tags: ['*'] + pull_request: + workflow_dispatch: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created + actions: write + contents: read + strategy: + fail-fast: false + matrix: + version: + - 'lts' + - '1' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v5 + with: + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false + docs: + name: Documentation + runs-on: ubuntu-latest + permissions: + actions: write # needed to allow julia-actions/cache to proactively delete old caches that it has created + contents: write + statuses: write + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1' + - uses: julia-actions/cache@v2 + - name: Configure doc environment + shell: julia --project=docs --color=yes {0} + run: | + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-docdeploy@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + - name: Run doctests + shell: julia --project=docs --color=yes {0} + run: | + using Documenter: DocMeta, doctest + using DiagonalArrays + DocMeta.setdocmeta!(DiagonalArrays, :DocTestSetup, :(using DiagonalArrays); recursive=true) + doctest(DiagonalArrays) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,16 @@ +name: CompatHelper +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Pkg.add("CompatHelper") + run: julia -e 'using Pkg; Pkg.add("CompatHelper")' + - name: CompatHelper.main() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml new file mode 100644 index 0000000..bb6d933 --- /dev/null +++ b/.github/workflows/FormatCheck.yml @@ -0,0 +1,35 @@ +name: Format check +on: + push: + branches: [main] + tags: [v*] + pull_request: + +jobs: + format: + name: "Format Check" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 1 + - name: Install JuliaFormatter and format + run: | + julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))' + julia -e 'using JuliaFormatter; format(".", verbose=true)' + - name: Check format + run: | + julia -e ' + out = Cmd(`git diff --name-only`) |> read |> String + if out == "" + exit(0) + else + @error "The following files have not been formatted:" + write(stdout, out) + out_diff = Cmd(`git diff`) |> read |> String + @error "Diff:" + write(stdout, out_diff) + exit(1) + @error "" + end' diff --git a/.github/workflows/LiterateCheck.yml b/.github/workflows/LiterateCheck.yml new file mode 100644 index 0000000..ade2453 --- /dev/null +++ b/.github/workflows/LiterateCheck.yml @@ -0,0 +1,39 @@ +name: Literate check +on: + push: + branches: [main] + tags: [v*] + pull_request: + +jobs: + literate: + name: "Literate Check" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 1 + - name: Install Literate and generate docs + run: | + julia -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + Pkg.add(PackageSpec(name="Literate"))' + julia -e 'include("docs/make_readme.jl")' + - name: Check if docs need to be updated + run: | + julia -e ' + out = Cmd(`git diff --name-only`) |> read |> String + if out == "" + exit(0) + else + @error "The docs are outdated, rerun Literate to regenerate them." + write(stdout, out) + out_diff = Cmd(`git diff`) |> read |> String + @error "Diff:" + write(stdout, out_diff) + exit(1) + @error "" + end' diff --git a/.github/workflows/Register.yml b/.github/workflows/Register.yml new file mode 100644 index 0000000..5b7cd3b --- /dev/null +++ b/.github/workflows/Register.yml @@ -0,0 +1,16 @@ +name: Register Package +on: + workflow_dispatch: + inputs: + version: + description: Version to register or component to bump + required: true +jobs: + register: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: julia-actions/RegisterAction@latest + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml new file mode 100644 index 0000000..0cd3114 --- /dev/null +++ b/.github/workflows/TagBot.yml @@ -0,0 +1,31 @@ +name: TagBot +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: "3" +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ssh: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10593a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +*.o +*.swp +.DS_Store +.benchmarkci +.tmp +.vscode/ +Manifest.toml +benchmark/*.json +docs/Manifest.toml +docs/build/ +docs/src/index.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..bff1fb7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + exclude_types: [markdown] # incompatible with Literate.jl +- repo: https://github.com/qiaojunfeng/pre-commit-julia-format + rev: v0.2.0 + hooks: + - id: julia-format diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7f5c8c6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 ITensor developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..5489bf7 --- /dev/null +++ b/Project.toml @@ -0,0 +1,16 @@ +name = "DiagonalArrays" +uuid = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" +authors = ["ITensor developers and contributors"] +version = "0.1.0" + +[compat] +Aqua = "0.8.9" +Test = "1.10" +julia = "1.10" + +[extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Aqua", "Test"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c862d6 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# DiagonalArrays.jl + +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/DiagonalArrays.jl/stable/) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/DiagonalArrays.jl/dev/) +[![Build Status](https://github.com/ITensor/DiagonalArrays.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ITensor/DiagonalArrays.jl/actions/workflows/CI.yml?query=branch%3Amain) +[![Coverage](https://codecov.io/gh/ITensor/DiagonalArrays.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/DiagonalArrays.jl) +[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) +[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) + +## Installation instructions + +```julia +julia> using Pkg: Pkg + +julia> Pkg.add("https://github.com/ITensor/DiagonalArrays.jl") +``` + +## Examples + +````julia +using DiagonalArrays: DiagonalArrays +```` + +Examples go here. + +--- + +*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* + diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..310c132 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,7 @@ +using DiagonalArrays +using BenchmarkTools + +SUITE = BenchmarkGroup() +SUITE["rand"] = @benchmarkable rand(10) + +# Write your benchmarks here. diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 0000000..53066a9 --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,4 @@ +[deps] +DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..23050ab --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,24 @@ +using DiagonalArrays: DiagonalArrays +using Documenter: Documenter, DocMeta, deploydocs, makedocs + +DocMeta.setdocmeta!( + DiagonalArrays, :DocTestSetup, :(using DiagonalArrays); recursive=true +) + +include("make_index.jl") + +makedocs(; + modules=[DiagonalArrays], + authors="ITensor developers and contributors", + sitename="DiagonalArrays.jl", + format=Documenter.HTML(; + canonical="https://ITensor.github.io/DiagonalArrays.jl", + edit_link="main", + assets=String[], + ), + pages=["Home" => "index.md"], +) + +deploydocs(; + repo="github.com/ITensor/DiagonalArrays.jl", devbranch="main", push_preview=true +) diff --git a/docs/make_index.jl b/docs/make_index.jl new file mode 100644 index 0000000..d6fc5db --- /dev/null +++ b/docs/make_index.jl @@ -0,0 +1,9 @@ +using Literate: Literate +using DiagonalArrays: DiagonalArrays + +Literate.markdown( + joinpath(pkgdir(DiagonalArrays), "examples", "README.jl"), + joinpath(pkgdir(DiagonalArrays), "docs", "src"); + flavor=Literate.DocumenterFlavor(), + name="index", +) diff --git a/docs/make_readme.jl b/docs/make_readme.jl new file mode 100644 index 0000000..f1aff56 --- /dev/null +++ b/docs/make_readme.jl @@ -0,0 +1,9 @@ +using Literate: Literate +using DiagonalArrays: DiagonalArrays + +Literate.markdown( + joinpath(pkgdir(DiagonalArrays), "examples", "README.jl"), + joinpath(pkgdir(DiagonalArrays)); + flavor=Literate.CommonMarkFlavor(), + name="README", +) diff --git a/examples/Project.toml b/examples/Project.toml new file mode 100644 index 0000000..34a57b6 --- /dev/null +++ b/examples/Project.toml @@ -0,0 +1,2 @@ +[deps] +DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" diff --git a/examples/README.jl b/examples/README.jl new file mode 100644 index 0000000..cccdd47 --- /dev/null +++ b/examples/README.jl @@ -0,0 +1,88 @@ +# # DiagonalArrays.jl +# +# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/DiagonalArrays.jl/stable/) +# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/DiagonalArrays.jl/dev/) +# [![Build Status](https://github.com/ITensor/DiagonalArrays.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ITensor/DiagonalArrays.jl/actions/workflows/CI.yml?query=branch%3Amain) +# [![Coverage](https://codecov.io/gh/ITensor/DiagonalArrays.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/DiagonalArrays.jl) +# [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) +# [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) + +# A n-dimensional diagonal array type in Julia. + +# ## Installation instructions + +#= +```julia +julia> using Pkg: Pkg + +julia> Pkg.add("https://github.com/ITensor/DiagonalArrays.jl") +``` +=# + +# ## Examples + +using NDTensors.DiagonalArrays: + DiagonalArray, DiagonalMatrix, DiagIndex, DiagIndices, diaglength, isdiagindex +using Test: @test + +function main() + d = DiagonalMatrix([1.0, 2.0, 3.0]) + @test eltype(d) == Float64 + @test diaglength(d) == 3 + @test size(d) == (3, 3) + @test d[1, 1] == 1 + @test d[2, 2] == 2 + @test d[3, 3] == 3 + @test d[1, 2] == 0 + + d = DiagonalArray([1.0, 2.0, 3.0], 3, 4, 5) + @test eltype(d) == Float64 + @test diaglength(d) == 3 + @test d[1, 1, 1] == 1 + @test d[2, 2, 2] == 2 + @test d[3, 3, 3] == 3 + @test d[1, 2, 1] == 0 + + d[2, 2, 2] = 22 + @test d[2, 2, 2] == 22 + + d_r = reshape(d, 3, 20) + @test size(d_r) == (3, 20) + @test all(I -> d_r[I] == d[I], LinearIndices(d)) + + @test length(d[DiagIndices(:)]) == 3 + @test Array(d) == d + @test d[DiagIndex(2)] == d[2, 2, 2] + + d[DiagIndex(2)] = 222 + @test d[2, 2, 2] == 222 + + a = randn(3, 4, 5) + new_diag = randn(3) + a[DiagIndices(:)] = new_diag + d[DiagIndices(:)] = a[DiagIndices(:)] + + @test a[DiagIndices(:)] == new_diag + @test d[DiagIndices(:)] == new_diag + + permuted_d = permutedims(d, (3, 2, 1)) + @test permuted_d isa DiagonalArray + @test permuted_d[DiagIndices(:)] == d[DiagIndices(:)] + @test size(d) == (3, 4, 5) + @test size(permuted_d) == (5, 4, 3) + for I in eachindex(d) + if !isdiagindex(d, I) + @test iszero(d[I]) + else + @test !iszero(d[I]) + end + end + + mapped_d = map(x -> 2x, d) + @test mapped_d isa DiagonalArray + @test mapped_d == map(x -> 2x, Array(d)) + + return nothing +end + +main() From dec883238e2210f5a6faa658fb674fb75d3f4699 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 20:03:08 -0500 Subject: [PATCH 3/6] Try fixing CI --- .github/workflows/CI.yml | 2 +- .github/workflows/LiterateCheck.yml | 2 ++ Project.toml | 8 ++++++++ TODO.md | 1 - docs/Project.toml | 4 ++++ docs/make.jl | 4 +--- examples/Project.toml | 4 ++++ examples/README.jl | 2 +- src/abstractdiagonalarray/sparsearrayinterface.jl | 1 - src/diaginterface/defaults.jl | 2 -- src/diaginterface/diaginterface.jl | 2 -- test/Project.toml | 4 +++- test/runtests.jl | 13 +++++-------- 13 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 TODO.md diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index be96cb9..8d6ffc1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,7 +23,7 @@ jobs: fail-fast: false matrix: version: - - 'lts' + # - 'lts' # TODO: Reenable once dependencies are registered. - '1' os: - ubuntu-latest diff --git a/.github/workflows/LiterateCheck.yml b/.github/workflows/LiterateCheck.yml index ade2453..7949fc8 100644 --- a/.github/workflows/LiterateCheck.yml +++ b/.github/workflows/LiterateCheck.yml @@ -18,6 +18,8 @@ jobs: run: | julia -e ' using Pkg + # TODO: Delete once they are registered. + Pkg.add(url="https://github.com/ITensor/SparseArraysBase.jl") Pkg.develop(PackageSpec(path=pwd())) Pkg.instantiate() Pkg.add(PackageSpec(name="Literate"))' diff --git a/Project.toml b/Project.toml index 5489bf7..cf15b2a 100644 --- a/Project.toml +++ b/Project.toml @@ -3,8 +3,16 @@ uuid = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" authors = ["ITensor developers and contributors"] version = "0.1.0" +[deps] +ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" +SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" + +[sources] +SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} + [compat] Aqua = "0.8.9" +ArrayLayouts = "1.10.4" Test = "1.10" julia = "1.10" diff --git a/TODO.md b/TODO.md deleted file mode 100644 index bdf465c..0000000 --- a/TODO.md +++ /dev/null @@ -1 +0,0 @@ -- Remove Compat dependency. diff --git a/docs/Project.toml b/docs/Project.toml index 53066a9..a4facb4 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -2,3 +2,7 @@ DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" +SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" + +[sources] +SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} diff --git a/docs/make.jl b/docs/make.jl index 23050ab..928d37f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,9 +1,7 @@ using DiagonalArrays: DiagonalArrays using Documenter: Documenter, DocMeta, deploydocs, makedocs -DocMeta.setdocmeta!( - DiagonalArrays, :DocTestSetup, :(using DiagonalArrays); recursive=true -) +DocMeta.setdocmeta!(DiagonalArrays, :DocTestSetup, :(using DiagonalArrays); recursive=true) include("make_index.jl") diff --git a/examples/Project.toml b/examples/Project.toml index 34a57b6..b22a72b 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,2 +1,6 @@ [deps] DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" +SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" + +[sources] +SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} diff --git a/examples/README.jl b/examples/README.jl index cccdd47..d937f7b 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -21,7 +21,7 @@ julia> Pkg.add("https://github.com/ITensor/DiagonalArrays.jl") # ## Examples -using NDTensors.DiagonalArrays: +using DiagonalArrays: DiagonalArray, DiagonalMatrix, DiagIndex, DiagIndices, diaglength, isdiagindex using Test: @test diff --git a/src/abstractdiagonalarray/sparsearrayinterface.jl b/src/abstractdiagonalarray/sparsearrayinterface.jl index b5779a0..9e72181 100644 --- a/src/abstractdiagonalarray/sparsearrayinterface.jl +++ b/src/abstractdiagonalarray/sparsearrayinterface.jl @@ -1,4 +1,3 @@ -using Compat: Returns, allequal using SparseArraysBase: SparseArraysBase # `SparseArraysBase` interface diff --git a/src/diaginterface/defaults.jl b/src/diaginterface/defaults.jl index 39e9395..3b1ed5d 100644 --- a/src/diaginterface/defaults.jl +++ b/src/diaginterface/defaults.jl @@ -1,3 +1 @@ -using Compat: Returns - default_size(diag::AbstractVector, n) = ntuple(Returns(length(diag)), n) diff --git a/src/diaginterface/diaginterface.jl b/src/diaginterface/diaginterface.jl index 1909201..7a878db 100644 --- a/src/diaginterface/diaginterface.jl +++ b/src/diaginterface/diaginterface.jl @@ -1,5 +1,3 @@ -using Compat: allequal - diaglength(a::AbstractArray{<:Any,0}) = 1 function diaglength(a::AbstractArray) diff --git a/test/Project.toml b/test/Project.toml index 9b1d5cc..b22f139 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,2 +1,4 @@ [deps] -NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" +DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" +SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 151c67b..72a133e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,16 +2,13 @@ using Test: @test, @testset, @test_broken using DiagonalArrays: DiagonalArrays, DiagonalArray, DiagonalMatrix, diaglength using SparseArraysBase: SparseArrayDOK, stored_length -@testset "Test NDTensors.DiagonalArrays" begin +@testset "Test DiagonalArrays" begin @testset "README" begin - @test include( - joinpath( - pkgdir(DiagonalArrays), "src", "lib", "DiagonalArrays", "examples", "README.jl" - ), - ) isa Any + @test include(joinpath(pkgdir(DiagonalArrays), "examples", "README.jl")) isa Any end - @testset "DiagonalArray (eltype=$elt)" for elt in - (Float32, Float64, ComplexF32, ComplexF64) + @testset "DiagonalArray (eltype=$elt)" for elt in ( + Float32, Float64, Complex{Float32}, Complex{Float64} + ) @testset "Basics" begin a = fill(one(elt), 2, 3) @test diaglength(a) == 2 From 26f7aff01b1078603de00fc7c1723341f3b0f66f Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 20:18:21 -0500 Subject: [PATCH 4/6] Add missing deps --- Project.toml | 6 ++++++ docs/Project.toml | 7 +++++++ examples/Project.toml | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/Project.toml b/Project.toml index cf15b2a..9c86ffb 100644 --- a/Project.toml +++ b/Project.toml @@ -5,10 +5,16 @@ version = "0.1.0" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" +BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" +NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" +TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" [sources] +BroadcastMapConversion = {url = "https://github.com/ITensor/BroadcastMapConversion.jl"} +NestedPermutedDimsArrays = {url = "https://github.com/ITensor/NestedPermutedDimsArrays.jl"} SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} +TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"} [compat] Aqua = "0.8.9" diff --git a/docs/Project.toml b/docs/Project.toml index a4facb4..74d3bea 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,8 +1,15 @@ [deps] +BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" +NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" +TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" + [sources] +BroadcastMapConversion = {url = "https://github.com/ITensor/BroadcastMapConversion.jl"} +NestedPermutedDimsArrays = {url = "https://github.com/ITensor/NestedPermutedDimsArrays.jl"} SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} +TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"} diff --git a/examples/Project.toml b/examples/Project.toml index b22a72b..3df672f 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,6 +1,12 @@ [deps] +BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" +NestedPermutedDimsArrays = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" +TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138" [sources] +BroadcastMapConversion = {url = "https://github.com/ITensor/BroadcastMapConversion.jl"} +NestedPermutedDimsArrays = {url = "https://github.com/ITensor/NestedPermutedDimsArrays.jl"} SparseArraysBase = {url = "https://github.com/ITensor/SparseArraysBase.jl"} +TypeParameterAccessors = {url = "https://github.com/ITensor/TypeParameterAccessors.jl"} From e2a936490204589c93c32646c75ca70b810c2620 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 20:19:50 -0500 Subject: [PATCH 5/6] Add missing deps --- .github/workflows/LiterateCheck.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/LiterateCheck.yml b/.github/workflows/LiterateCheck.yml index 7949fc8..15a72c3 100644 --- a/.github/workflows/LiterateCheck.yml +++ b/.github/workflows/LiterateCheck.yml @@ -19,6 +19,9 @@ jobs: julia -e ' using Pkg # TODO: Delete once they are registered. + Pkg.add(url="https://github.com/ITensor/BroadcastMapConversion.jl") + Pkg.add(url="https://github.com/ITensor/NestedPermutedDimsArrays.jl") + Pkg.add(url="https://github.com/ITensor/TypeParameterAccessors.jl") Pkg.add(url="https://github.com/ITensor/SparseArraysBase.jl") Pkg.develop(PackageSpec(path=pwd())) Pkg.instantiate() From 16e248bdb2da28b5575a9ea603ca67d9b9547ac0 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 26 Nov 2024 20:22:48 -0500 Subject: [PATCH 6/6] Update README --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4c862d6..6cc1434 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) +A n-dimensional diagonal array type in Julia. + ## Installation instructions ```julia @@ -18,10 +20,72 @@ julia> Pkg.add("https://github.com/ITensor/DiagonalArrays.jl") ## Examples ````julia -using DiagonalArrays: DiagonalArrays -```` +using DiagonalArrays: + DiagonalArray, DiagonalMatrix, DiagIndex, DiagIndices, diaglength, isdiagindex +using Test: @test + +function main() + d = DiagonalMatrix([1.0, 2.0, 3.0]) + @test eltype(d) == Float64 + @test diaglength(d) == 3 + @test size(d) == (3, 3) + @test d[1, 1] == 1 + @test d[2, 2] == 2 + @test d[3, 3] == 3 + @test d[1, 2] == 0 + + d = DiagonalArray([1.0, 2.0, 3.0], 3, 4, 5) + @test eltype(d) == Float64 + @test diaglength(d) == 3 + @test d[1, 1, 1] == 1 + @test d[2, 2, 2] == 2 + @test d[3, 3, 3] == 3 + @test d[1, 2, 1] == 0 + + d[2, 2, 2] = 22 + @test d[2, 2, 2] == 22 + + d_r = reshape(d, 3, 20) + @test size(d_r) == (3, 20) + @test all(I -> d_r[I] == d[I], LinearIndices(d)) + + @test length(d[DiagIndices(:)]) == 3 + @test Array(d) == d + @test d[DiagIndex(2)] == d[2, 2, 2] -Examples go here. + d[DiagIndex(2)] = 222 + @test d[2, 2, 2] == 222 + + a = randn(3, 4, 5) + new_diag = randn(3) + a[DiagIndices(:)] = new_diag + d[DiagIndices(:)] = a[DiagIndices(:)] + + @test a[DiagIndices(:)] == new_diag + @test d[DiagIndices(:)] == new_diag + + permuted_d = permutedims(d, (3, 2, 1)) + @test permuted_d isa DiagonalArray + @test permuted_d[DiagIndices(:)] == d[DiagIndices(:)] + @test size(d) == (3, 4, 5) + @test size(permuted_d) == (5, 4, 3) + for I in eachindex(d) + if !isdiagindex(d, I) + @test iszero(d[I]) + else + @test !iszero(d[I]) + end + end + + mapped_d = map(x -> 2x, d) + @test mapped_d isa DiagonalArray + @test mapped_d == map(x -> 2x, Array(d)) + + return nothing +end + +main() +```` ---