Skip to content

Commit 41fbf4b

Browse files
authored
Change combine_styles to style (#3)
1 parent 94837cd commit 41fbf4b

6 files changed

Lines changed: 24 additions & 25 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FunctionImplementations"
22
uuid = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c"
33
authors = ["ITensor developers <support@itensor.org> and contributors"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[compat]
77
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ FunctionImplementations = {path = ".."}
99
[compat]
1010
Documenter = "1"
1111
Literate = "2"
12-
FunctionImplementations = "0.1"
12+
FunctionImplementations = "0.2"

examples/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ FunctionImplementations = "7c7cc465-9c6a-495f-bdd1-f42428e86d0c"
55
FunctionImplementations = {path = ".."}
66

77
[compat]
8-
FunctionImplementations = "0.1"
8+
FunctionImplementations = "0.2"

src/style.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ by defining a type/method pair
1313
1414
"""
1515
abstract type Style end
16-
Style(x) = Style(typeof(x))
1716
Style(::Type{T}) where {T} = throw(MethodError(Style, (T,)))
1817

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

116115
"""
117-
combine_styles(cs...)::Style
116+
style(cs...)::Style
118117
119118
Decides which `Style` to use for any number of value arguments.
120119
Uses [`Style`](@ref) to get the style for each argument, and uses
121120
[`result_style`](@ref) to combine styles.
122121
123122
# Examples
124123
```jldoctest
125-
julia> FunctionImplementations.combine_styles([1], [1 2; 3 4])
124+
julia> FunctionImplementations.style([1], [1 2; 3 4])
126125
FunctionImplementations.DefaultArrayStyle{Any}()
127126
```
128127
"""
129-
function combine_styles end
128+
function style end
130129

131-
combine_styles() = DefaultArrayStyle{0}()
132-
combine_styles(c) = result_style(Style(typeof(c)))
133-
combine_styles(c1, c2) = result_style(combine_styles(c1), combine_styles(c2))
134-
@inline combine_styles(c1, c2, cs...) = result_style(combine_styles(c1), combine_styles(c2, cs...))
130+
style() = DefaultArrayStyle{0}()
131+
style(c) = result_style(Style(typeof(c)))
132+
style(c1, c2) = result_style(style(c1), style(c2))
133+
@inline style(c1, c2, cs...) = result_style(style(c1), style(c2, cs...))
135134

136135
"""
137136
result_style(s1::Style[, s2::Style])::Style

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FunctionImplementations = {path = ".."}
1010

1111
[compat]
1212
Aqua = "0.8"
13-
FunctionImplementations = "0.1"
13+
FunctionImplementations = "0.2"
1414
SafeTestsets = "0.1"
1515
Suppressor = "0.2"
1616
Test = "1.10"

test/test_basics.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ using Test: @test, @testset
1515
@testset "(s::Style)(f)" begin
1616
# Test the shorthand for creating an Implementation by calling a Style with a
1717
# function.
18-
@test FI.Style([1, 2, 3])(getindex)
18+
@test FI.style([1, 2, 3])(getindex)
1919
FI.Implementation(getindex, FI.DefaultArrayStyle{1}())
2020
end
2121
@testset "Style" begin
2222
# Test basic Style trait for different array types
2323
@test FI.Style(typeof([1, 2, 3])) isa FI.DefaultArrayStyle{1}
24-
@test FI.Style([1, 2, 3]) isa FI.DefaultArrayStyle{1}
24+
@test FI.style([1, 2, 3]) isa FI.DefaultArrayStyle{1}
2525
@test FI.Style(typeof([1 2; 3 4])) isa FI.DefaultArrayStyle{2}
2626
@test FI.Style(typeof(rand(2, 3, 4))) isa FI.DefaultArrayStyle{3}
2727

@@ -79,23 +79,23 @@ using Test: @test, @testset
7979
conflict_val = FI.ArrayConflict(Val(3))
8080
@test conflict_val isa FI.ArrayConflict
8181

82-
# Test combine_styles with no arguments
83-
@test FI.combine_styles() isa FI.DefaultArrayStyle{0}
82+
# Test style with no arguments
83+
@test FI.style() isa FI.DefaultArrayStyle{0}
8484

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

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

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

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

101101
# Test result_style with single argument

0 commit comments

Comments
 (0)