diff --git a/Project.toml b/Project.toml index 9fe8907..17a1cbe 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FunctionImplementations" uuid = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c" authors = ["ITensor developers and contributors"] -version = "0.1.0" +version = "0.2.0" [compat] julia = "1.10" diff --git a/docs/Project.toml b/docs/Project.toml index afeb087..2b628be 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -9,4 +9,4 @@ FunctionImplementations = {path = ".."} [compat] Documenter = "1" Literate = "2" -FunctionImplementations = "0.1" +FunctionImplementations = "0.2" diff --git a/examples/Project.toml b/examples/Project.toml index a0b9102..5e8dc04 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -5,4 +5,4 @@ FunctionImplementations = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c" FunctionImplementations = {path = ".."} [compat] -FunctionImplementations = "0.1" +FunctionImplementations = "0.2" diff --git a/src/style.jl b/src/style.jl index 2430a5e..8324030 100644 --- a/src/style.jl +++ b/src/style.jl @@ -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 @@ -114,7 +113,7 @@ 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 @@ -122,16 +121,16 @@ Uses [`Style`](@ref) to get the style for each argument, and uses # 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 diff --git a/test/Project.toml b/test/Project.toml index 56c49c5..8f9d369 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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" diff --git a/test/test_basics.jl b/test/test_basics.jl index 4bb3488..41ebdb5 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -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} @@ -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