Skip to content

Commit

Permalink
Rename to DerivableInterfaces.jl (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 10, 2025
1 parent d194ece commit bb982a0
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 75 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/BUG_REPORT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Derive.jl bug report
about: Create a bug report to help us improve Derive.jl
name: DerivableInterfaces.jl bug report
about: Create a bug report to help us improve DerivableInterfaces.jl
title: "[BUG] YOUR SHORT DESCRIPTION OF THE BUG HERE"
labels: ["bug"]
assignees: ''
Expand Down Expand Up @@ -55,8 +55,8 @@ If you provided a minimal code that demonstrates the bug or unexpected behavior,
julia> versioninfo()
[YOUR OUTPUT HERE]
```
- Output from `using Pkg; Pkg.status("Derive")`:
- Output from `using Pkg; Pkg.status("DerivableInterfaces")`:
```julia
julia> using Pkg; Pkg.status("Derive")
julia> using Pkg; Pkg.status("DerivableInterfaces")
[YOUR OUTPUT HERE]
```
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Derive.jl feature request
about: Suggest an idea for Derive.jl
name: DerivableInterfaces.jl feature request
about: Suggest an idea for DerivableInterfaces.jl
title: "[ENHANCEMENT] YOUR SHORT DESCRIPTION OF THE FEATURE REQUEST HERE"
labels: ["enhancement"]
assignees: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Please give a summary of the tests that you added to verify your changes.

# Checklist:

- [ ] My code follows the style guidelines of this project. Please run `using JuliaFormatter; format(".")` in the base directory of the repository (`~/.julia/dev/Derive`) to format your code according to our style guidelines.
- [ ] My code follows the style guidelines of this project. Please run `using JuliaFormatter; format(".")` in the base directory of the repository (`~/.julia/dev/DerivableInterfaces`) 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.
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name = "Derive"
uuid = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
name = "DerivableInterfaces"
uuid = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.3.6"
version = "0.3.7"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
BroadcastMapConversion = "4a4adec5-520f-4750-bb37-d5e66b4ddeb2"
ExproniconLite = "55351af7-c7e9-48d6-89ff-24e801d99491"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
MapBroadcast = "ebd9b9da-f48d-417c-9660-449667d60261"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"

[compat]
Adapt = "4.1.1"
Aqua = "0.8.9"
ArrayLayouts = "1.11.0"
BroadcastMapConversion = "0.1.0"
ExproniconLite = "0.10.13"
LinearAlgebra = "1.10"
MLStyle = "0.4.17"
MapBroadcast = "0.1.5"
SafeTestsets = "0.1"
Suppressor = "0.2"
Test = "1.10"
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Derive.jl
# DerivableInterfaces.jl

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/Derive.jl/stable/)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/Derive.jl/dev/)
[![Build Status](https://github.com/ITensor/Derive.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/Derive.jl/actions/workflows/Tests.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/ITensor/Derive.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/Derive.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)
[![Coverage](https://codecov.io/gh/ITensor/DerivableInterfaces.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/DerivableInterfaces.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)

Expand Down Expand Up @@ -42,13 +42,14 @@ if you want to use SSH credentials, which can make it so you don't have to enter
Then, the package can be added as usual through the package manager:

```julia
julia> Pkg.add("Derive")
julia> Pkg.add("DerivableInterfaces")
```

## Examples

````julia
using Derive: Derive, @array_aliases, @derive, @interface, interface
using DerivableInterfaces:
DerivableInterfaces, @array_aliases, @derive, @interface, interface
using Test: @test
````

Expand Down Expand Up @@ -113,7 +114,7 @@ end
Specify the interface the type adheres to.

````julia
Derive.interface(::Type{<:SparseArrayDOK}) = SparseArrayInterface()
DerivableInterfaces.interface(::Type{<:SparseArrayDOK}) = SparseArrayInterface()
````

Define aliases like `SparseMatrixDOK`, `AnySparseArrayDOK`, etc.
Expand All @@ -122,7 +123,7 @@ Define aliases like `SparseMatrixDOK`, `AnySparseArrayDOK`, etc.
@array_aliases SparseArrayDOK
````

Derive the interface for the type.
DerivableInterfaces the interface for the type.

````julia
@derive (T=SparseArrayDOK,) begin
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Derive
using DerivableInterfaces
using BenchmarkTools

SUITE = BenchmarkGroup()
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[deps]
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
18 changes: 12 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
using Derive: Derive
using DerivableInterfaces: DerivableInterfaces
using Documenter: Documenter, DocMeta, deploydocs, makedocs

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

include("make_index.jl")

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

deploydocs(; repo="github.com/ITensor/Derive.jl", devbranch="main", push_preview=true)
deploydocs(;
repo="github.com/ITensor/DerivableInterfaces.jl", devbranch="main", push_preview=true
)
6 changes: 3 additions & 3 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Literate: Literate
using Derive: Derive
using DerivableInterfaces: DerivableInterfaces

Literate.markdown(
joinpath(pkgdir(Derive), "examples", "README.jl"),
joinpath(pkgdir(Derive), "docs", "src");
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
)
6 changes: 3 additions & 3 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Literate: Literate
using Derive: Derive
using DerivableInterfaces: DerivableInterfaces

Literate.markdown(
joinpath(pkgdir(Derive), "examples", "README.jl"),
joinpath(pkgdir(Derive));
joinpath(pkgdir(DerivableInterfaces), "examples", "README.jl"),
joinpath(pkgdir(DerivableInterfaces));
flavor=Literate.CommonMarkFlavor(),
name="README",
)
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Derive = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
19 changes: 10 additions & 9 deletions examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# # Derive.jl
# # DerivableInterfaces.jl
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/Derive.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/Derive.jl/dev/)
# [![Build Status](https://github.com/ITensor/Derive.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/Derive.jl/actions/workflows/Tests.yml?query=branch%3Amain)
# [![Coverage](https://codecov.io/gh/ITensor/Derive.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/Derive.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)
# [![Coverage](https://codecov.io/gh/ITensor/DerivableInterfaces.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/DerivableInterfaces.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)

Expand Down Expand Up @@ -47,13 +47,14 @@ julia> Pkg.Registry.add(url="[email protected]:ITensor/ITensorRegistry.git")

#=
```julia
julia> Pkg.add("Derive")
julia> Pkg.add("DerivableInterfaces")
```
=#

# ## Examples

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

# Define an interface.
Expand Down Expand Up @@ -106,12 +107,12 @@ function setunstoredindex!(a::SparseArrayDOK, value, I::Int...)
end

# Specify the interface the type adheres to.
Derive.interface(::Type{<:SparseArrayDOK}) = SparseArrayInterface()
DerivableInterfaces.interface(::Type{<:SparseArrayDOK}) = SparseArrayInterface()

# Define aliases like `SparseMatrixDOK`, `AnySparseArrayDOK`, etc.
@array_aliases SparseArrayDOK

# Derive the interface for the type.
# DerivableInterfaces the interface for the type.
@derive (T=SparseArrayDOK,) begin
Base.getindex(::T, ::Int...)
Base.setindex!(::T, ::Any, ::Int...)
Expand Down
2 changes: 1 addition & 1 deletion src/Derive.jl → src/DerivableInterfaces.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Derive
module DerivableInterfaces

include("interface_function.jl")
include("abstractinterface.jl")
Expand Down
10 changes: 6 additions & 4 deletions src/abstractarrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ end
return similar(arraytype(interface, T), axes)
end

using BroadcastMapConversion: map_function, map_args
using MapBroadcast: Mapped
# TODO: Turn this into an `@interface AbstractArrayInterface` function?
# TODO: Look into `SparseArrays.capturescalars`:
# https://github.com/JuliaSparse/SparseArrays.jl/blob/1beb0e4a4618b0399907b0000c43d9f66d34accc/src/higherorderfns.jl#L1092-L1102
@interface interface::AbstractArrayInterface function Base.copyto!(
a_dest::AbstractArray, bc::Broadcast.Broadcasted
)
return @interface interface map!(map_function(bc), a_dest, map_args(bc)...)
m = Mapped(bc)
return @interface interface map!(m.f, a_dest, m.args...)
end

# This captures broadcast expressions such as `a .= 2`.
Expand All @@ -123,8 +124,9 @@ end
@interface interface::AbstractArrayInterface function Base.copyto!(
a_dest::AbstractArray, bc::Broadcast.Broadcasted{Broadcast.DefaultArrayStyle{0}}
)
isempty(map_args(bc)) || error("Bad broadcast expression.")
return @interface interface map!(map_function(bc), a_dest, a_dest)
m = Mapped(bc)
isempty(m.args) || error("Bad broadcast expression.")
return @interface interface map!(m.f, a_dest, a_dest)
end

# This is defined in this way so we can rely on the Broadcast logic
Expand Down
14 changes: 8 additions & 6 deletions src/derive_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ argname(i::Int) = Symbol(:arg, i)

# Remove lines from a block.
# See: https://thautwarm.github.io/MLStyle.jl/stable/syntax/pattern/#Ast-Pattern-1
# TODO: Use this type of function to replace `Derive.f` with `GlobalRef(Derive, f)`
# TODO: Use this type of function to replace `DerivableInterfaces.f` with `GlobalRef(DerivableInterfaces, f)`
# and also replace `T` with `SparseArrayDOK`.
function rmlines(expr)
return @match expr begin
Expand All @@ -17,7 +17,7 @@ end

function globalref_derive(expr)
return @match expr begin
:(Derive.$f) => :($(GlobalRef(Derive, :($f))))
:(DerivableInterfaces.$f) => :($(GlobalRef(DerivableInterfaces, :($f))))
e::Expr => Expr(e.head, map(globalref_derive, e.args)...)
a => a
end
Expand Down Expand Up @@ -165,7 +165,9 @@ function derive_func_from_types(types::Expr, func::Expr)
end
return argname(i)
end
interface = globalref_derive(:(Derive.combine_interfaces($(active_argnames...))))
interface = globalref_derive(
:(DerivableInterfaces.combine_interfaces($(active_argnames...)))
)
return derive_interface_func(interface, new_func)
end

Expand Down Expand Up @@ -200,18 +202,18 @@ function derive_interface_func(interface::Union{Symbol,Expr}, func::Expr)
:(::$T...) => :($argname...)
end
end
# TODO: Use the `@interface` macro rather than `Derive.call`
# TODO: Use the `@interface` macro rather than `DerivableInterfaces.call`
# directly, in case we want to change the implementation.
body_args = [interface; name; body_args...]
body_name = @match name begin
:($M.$f) => :(Derive.call)
:($M.$f) => :(DerivableInterfaces.call)
end
# TODO: Remove defaults from `kwargs`.
_, body, _ = split_function(
codegen_ast(JLFunction(; name=body_name, args=body_args, kwargs))
)
jlfn = JLFunction(; name, args=named_args, kwargs, whereparams, rettype, body)
# Use `globalref_derive` to not require having `Derive` in the
# Use `globalref_derive` to not require having `DerivableInterfaces` in the
# namespace when `@derive` is called.
return globalref_derive(codegen_ast(jlfn))
end
Expand Down
2 changes: 1 addition & 1 deletion src/interface_function.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=
Rewrite `f(args...)` to `Derive.call(interface, f, args...)`.
Rewrite `f(args...)` to `DerivableInterfaces.call(interface, f, args...)`.
Similar to `Cassette.overdub`.
This errors for debugging, but probably should be defined as:
Expand Down
16 changes: 9 additions & 7 deletions src/interface_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ or:
```
to:
```julia
Derive.call(SparseArrayInterface(), Base.getindex, a, I...)
DerivableInterfaces.call(SparseArrayInterface(), Base.getindex, a, I...)
```
=#
function interface_call(interface::Union{Symbol,Expr}, func::Expr)
return @match func begin
:($name($(args...))) =>
:($(GlobalRef(Derive, :InterfaceFunction))($interface, $name)($(args...)))
:($(GlobalRef(DerivableInterfaces, :InterfaceFunction))($interface, $name)(
$(args...)
))
:($name($(args...); $(kwargs...))) =>
:($(GlobalRef(Derive, :InterfaceFunction))($interface, $name)(
:($(GlobalRef(DerivableInterfaces, :InterfaceFunction))($interface, $name)(
$(args...); $(kwargs...)
))
end
Expand All @@ -57,7 +59,7 @@ Rewrite:
```
to:
```julia
Derive.call(SparseArrayInterface(), Base.getindex, a, I...)
DerivableInterfaces.call(SparseArrayInterface(), Base.getindex, a, I...)
```
=#
function interface_ref(interface::Union{Symbol,Expr}, func::Expr)
Expand All @@ -74,7 +76,7 @@ Rewrite:
```
to:
```julia
Derive.call(SparseArrayInterface(), Base.setindex!, a, value, I...)
DerivableInterfaces.call(SparseArrayInterface(), Base.setindex!, a, value, I...)
```
=#
function interface_setref(interface::Union{Symbol,Expr}, func::Expr)
Expand All @@ -94,7 +96,7 @@ end
```
to:
```julia
function Derive.call(interface::SparseArrayInterface, Base.getindex, a, I::Int...)
function DerivableInterfaces.call(interface::SparseArrayInterface, Base.getindex, a, I::Int...)
!isstored(a, I...) && return getunstoredindex(a, I...)
return getstoredindex(a, I...)
end
Expand All @@ -103,7 +105,7 @@ end
function interface_definition(interface::Union{Symbol,Expr}, func::Expr)
head, call, body = split_function(func)
name, args, kwargs, whereparams, rettype = split_function_head(call)
new_name = :(Derive.call)
new_name = :(DerivableInterfaces.call)
# We use `Core.Typeof` here because `name` can either be a function or type,
# and `typeof(T::Type)` outputs things like `DataType`, `UnionAll`, etc.
# while `Core.Typeof(T::Type)` returns `Type{T}`.
Expand Down
Loading

0 comments on commit bb982a0

Please sign in to comment.