Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DerivableInterfaces"
uuid = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
version = "0.5.6"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.5.5"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
22 changes: 11 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ using DerivableInterfaces: DerivableInterfaces
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
DerivableInterfaces, :DocTestSetup, :(using DerivableInterfaces); recursive=true
DerivableInterfaces, :DocTestSetup, :(using DerivableInterfaces); recursive = true
)

include("make_index.jl")

makedocs(;
modules=[DerivableInterfaces],
authors="ITensor developers <[email protected]> and contributors",
sitename="DerivableInterfaces.jl",
format=Documenter.HTML(;
canonical="https://itensor.github.io/DerivableInterfaces.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [DerivableInterfaces],
authors = "ITensor developers <[email protected]> and contributors",
sitename = "DerivableInterfaces.jl",
format = Documenter.HTML(;
canonical = "https://itensor.github.io/DerivableInterfaces.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/DerivableInterfaces.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/DerivableInterfaces.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using DerivableInterfaces: DerivableInterfaces

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using DerivableInterfaces: DerivableInterfaces

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
54 changes: 27 additions & 27 deletions examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # DerivableInterfaces.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/DerivableInterfaces.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/DerivableInterfaces.jl/dev/)
# [![Build Status](https://github.com/ITensor/DerivableInterfaces.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/DerivableInterfaces.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down Expand Up @@ -60,56 +60,56 @@ julia> Pkg.add("DerivableInterfaces")
# ## Examples

using DerivableInterfaces:
DerivableInterfaces, @array_aliases, @derive, @interface, interface
DerivableInterfaces, @array_aliases, @derive, @interface, interface
using Test: @test

# Define an interface.
struct SparseArrayInterface end

# Define interface functions.
@interface ::SparseArrayInterface function Base.getindex(a, I::Int...)
checkbounds(a, I...)
!isstored(a, I...) && return getunstoredindex(a, I...)
return getstoredindex(a, I...)
checkbounds(a, I...)
!isstored(a, I...) && return getunstoredindex(a, I...)
return getstoredindex(a, I...)
end
@interface ::SparseArrayInterface function Base.setindex!(a, value, I::Int...)
checkbounds(a, I...)
iszero(value) && return a
if !isstored(a, I...)
setunstoredindex!(a, value, I...)
checkbounds(a, I...)
iszero(value) && return a
if !isstored(a, I...)
setunstoredindex!(a, value, I...)
return a
end
setstoredindex!(a, value, I...)
return a
end
setstoredindex!(a, value, I...)
return a
end

# Define a type that will derive the interface.
struct SparseArrayDOK{T,N} <: AbstractArray{T,N}
storage::Dict{CartesianIndex{N},T}
size::NTuple{N,Int}
struct SparseArrayDOK{T, N} <: AbstractArray{T, N}
storage::Dict{CartesianIndex{N}, T}
size::NTuple{N, Int}
end
storage(a::SparseArrayDOK) = a.storage
Base.size(a::SparseArrayDOK) = a.size
function SparseArrayDOK{T}(size::Int...) where {T}
N = length(size)
return SparseArrayDOK{T,N}(Dict{CartesianIndex{N},T}(), size)
N = length(size)
return SparseArrayDOK{T, N}(Dict{CartesianIndex{N}, T}(), size)
end
function isstored(a::SparseArrayDOK, I::Int...)
return CartesianIndex(I) in keys(storage(a))
return CartesianIndex(I) in keys(storage(a))
end
function getstoredindex(a::SparseArrayDOK, I::Int...)
return storage(a)[CartesianIndex(I)]
return storage(a)[CartesianIndex(I)]
end
function getunstoredindex(a::SparseArrayDOK, I::Int...)
return zero(eltype(a))
return zero(eltype(a))
end
function setstoredindex!(a::SparseArrayDOK, value, I::Int...)
storage(a)[CartesianIndex(I)] = value
return a
storage(a)[CartesianIndex(I)] = value
return a
end
function setunstoredindex!(a::SparseArrayDOK, value, I::Int...)
storage(a)[CartesianIndex(I)] = value
return a
storage(a)[CartesianIndex(I)] = value
return a
end

# Specify the interface the type adheres to.
Expand All @@ -119,9 +119,9 @@ DerivableInterfaces.interface(::Type{<:SparseArrayDOK}) = SparseArrayInterface()
@array_aliases SparseArrayDOK

# DerivableInterfaces the interface for the type.
@derive (T=SparseArrayDOK,) begin
Base.getindex(::T, ::Int...)
Base.setindex!(::T, ::Any, ::Int...)
@derive (T = SparseArrayDOK,) begin
Base.getindex(::T, ::Int...)
Base.setindex!(::T, ::Any, ::Int...)
end

a = SparseArrayDOK{Float64}(2, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using BlockArrays: BlockedOneTo, blockedrange, blocklengths
using DerivableInterfaces.Concatenate: Concatenate

function Concatenate.cat_axis(a1::BlockedOneTo, a2::BlockedOneTo)
return blockedrange([blocklengths(a1); blocklengths(a2)])
return blockedrange([blocklengths(a1); blocklengths(a2)])
end

end
Loading