Skip to content
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 = "FunctionImplementations"
uuid = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.1.0"
version = "0.2.0"

[compat]
julia = "1.10"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ FunctionImplementations = {path = ".."}
[compat]
Documenter = "1"
Literate = "2"
FunctionImplementations = "0.1"
FunctionImplementations = "0.2"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ FunctionImplementations = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c"
FunctionImplementations = {path = ".."}

[compat]
FunctionImplementations = "0.1"
FunctionImplementations = "0.2"
15 changes: 7 additions & 8 deletions src/style.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ by defining a type/method pair

"""
abstract type Style end
Style(x) = Style(typeof(x))
Style(::Type{T}) where {T} = throw(MethodError(Style, (T,)))

struct UnknownStyle <: Style end
Expand Down Expand Up @@ -114,24 +113,24 @@ Style(a::AbstractArrayStyle{M}, ::DefaultArrayStyle{N}) where {M, N} =
## logic for deciding the Style

"""
combine_styles(cs...)::Style
style(cs...)::Style

Decides which `Style` to use for any number of value arguments.
Uses [`Style`](@ref) to get the style for each argument, and uses
[`result_style`](@ref) to combine styles.

# Examples
```jldoctest
julia> FunctionImplementations.combine_styles([1], [1 2; 3 4])
julia> FunctionImplementations.style([1], [1 2; 3 4])
FunctionImplementations.DefaultArrayStyle{Any}()
```
"""
function combine_styles end
function style end

combine_styles() = DefaultArrayStyle{0}()
combine_styles(c) = result_style(Style(typeof(c)))
combine_styles(c1, c2) = result_style(combine_styles(c1), combine_styles(c2))
@inline combine_styles(c1, c2, cs...) = result_style(combine_styles(c1), combine_styles(c2, cs...))
style() = DefaultArrayStyle{0}()
style(c) = result_style(Style(typeof(c)))
style(c1, c2) = result_style(style(c1), style(c2))
@inline style(c1, c2, cs...) = result_style(style(c1), style(c2, cs...))

"""
result_style(s1::Style[, s2::Style])::Style
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FunctionImplementations = {path = ".."}

[compat]
Aqua = "0.8"
FunctionImplementations = "0.1"
FunctionImplementations = "0.2"
SafeTestsets = "0.1"
Suppressor = "0.2"
Test = "1.10"
26 changes: 13 additions & 13 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ using Test: @test, @testset
@testset "(s::Style)(f)" begin
# Test the shorthand for creating an Implementation by calling a Style with a
# function.
@test FI.Style([1, 2, 3])(getindex) ≡
@test FI.style([1, 2, 3])(getindex) ≡
FI.Implementation(getindex, FI.DefaultArrayStyle{1}())
end
@testset "Style" begin
# Test basic Style trait for different array types
@test FI.Style(typeof([1, 2, 3])) isa FI.DefaultArrayStyle{1}
@test FI.Style([1, 2, 3]) isa FI.DefaultArrayStyle{1}
@test FI.style([1, 2, 3]) isa FI.DefaultArrayStyle{1}
@test FI.Style(typeof([1 2; 3 4])) isa FI.DefaultArrayStyle{2}
@test FI.Style(typeof(rand(2, 3, 4))) isa FI.DefaultArrayStyle{3}

Expand Down Expand Up @@ -79,23 +79,23 @@ using Test: @test, @testset
conflict_val = FI.ArrayConflict(Val(3))
@test conflict_val isa FI.ArrayConflict

# Test combine_styles with no arguments
@test FI.combine_styles() isa FI.DefaultArrayStyle{0}
# Test style with no arguments
@test FI.style() isa FI.DefaultArrayStyle{0}

# Test combine_styles with single argument
@test FI.combine_styles([1, 2]) isa FI.DefaultArrayStyle{1}
@test FI.combine_styles([1 2; 3 4]) isa FI.DefaultArrayStyle{2}
# Test style with single argument
@test FI.style([1, 2]) isa FI.DefaultArrayStyle{1}
@test FI.style([1 2; 3 4]) isa FI.DefaultArrayStyle{2}

# Test combine_styles with two arguments
result = FI.combine_styles([1, 2], [1 2; 3 4])
# Test style with two arguments
result = FI.style([1, 2], [1 2; 3 4])
@test result isa FI.DefaultArrayStyle{Any}

# Test combine_styles with same dimensions
result = FI.combine_styles([1], [2])
# Test style with same dimensions
result = FI.style([1], [2])
@test result isa FI.DefaultArrayStyle{1}

# Test combine_styles with multiple arguments
result = FI.combine_styles([1], [1 2], rand(2, 3, 4))
# Test style with multiple arguments
result = FI.style([1], [1 2], rand(2, 3, 4))
@test result isa FI.DefaultArrayStyle{Any}

# Test result_style with single argument
Expand Down
Loading