Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Add support for linear indexing #19

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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 = "Derive"
uuid = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.3.5"
version = "0.3.6"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
14 changes: 14 additions & 0 deletions src/abstractarrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@
return @interface interface getindex(a, Tuple(I)...)
end

# Linear indexing.
@interface interface ::AbstractArrayInterface function Base.getindex(

Check warning on line 48 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L48

Added line #L48 was not covered by tests
a::AbstractArray, I::Int
)
return @interface interface getindex(a, CartesianIndices(a)[I])

Check warning on line 51 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L51

Added line #L51 was not covered by tests
end

# TODO: Use `MethodError`?
@interface ::AbstractArrayInterface function Base.setindex!(
a::AbstractArray{<:Any,N}, value, I::Vararg{Int,N}
) where {N}
return error("Not implemented.")
end

# Linear indexing.
@interface interface ::AbstractArrayInterface function Base.setindex!(

Check warning on line 62 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L62

Added line #L62 was not covered by tests
a::AbstractArray, value, I::Int
)
return @interface interface setindex!(a, value, CartesianIndices(a)[I])

Check warning on line 65 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L65

Added line #L65 was not covered by tests
end

# TODO: Make this more general, use `Base.to_index`.
@interface interface::AbstractArrayInterface function Base.setindex!(
a::AbstractArray{<:Any,N}, value, I::CartesianIndex{N}
Expand Down
Loading