@@ -88,7 +88,7 @@ const LB = Histogramming.LinearBinning()
88
88
end
89
89
90
90
@testset " Low Level ($(N) D, $style )" for N in 1 : 3 , style in (HB, LB)
91
- using . Histogramming: HistEdge, _histogram!
91
+ using . Histogramming: HistEdge, _histogram!, _histogram
92
92
93
93
edges = ((0.0 : 0.25 : 1.0 for _ in 1 : N). .. ,)
94
94
edges′ = HistEdge .(edges)
104
104
fill! (hist, 0 )
105
105
_histogram! (style, hist, edges′, x1, nothing )
106
106
@test sum (hist) * step (edges[1 ])^ N == 1.0
107
+ # compare to the allocating interface
108
+ @test hist == _histogram (style, x1, edges′)
109
+ @test hist == _histogram (style, x1, edges′; weights = [1 ])
107
110
108
111
# out-of-bounds elements are not binned
109
112
x0 = [(- 1.0 , (0.0 for _ in 1 : N- 1 ). .. ,)]
115
118
fill! (hist, 0 )
116
119
@test (@inferred _histogram! (style, hist, edges′, x1, nothing )) === 1.0
117
120
@test_broken (@allocated _histogram! (style, hist, edges′, x1, nothing )) == 0
121
+
122
+ @test (@inferred _histogram (style, x1, edges)) isa Array{Float64,N}
123
+ @test (@inferred _histogram (style, x1, edges; weights = [1 ])) isa Array{Float64,N}
124
+ @test (@inferred _histogram (style, x1, edges′)) isa Array{Float64,N}
125
+ @test (@inferred _histogram (style, x1, edges′; weights = [1 ])) isa Array{Float64,N}
126
+ @test (@inferred _histogram (style, x1, edges... )) isa Array{Float64,N}
127
+ @test (@inferred _histogram (style, x1, edges... ; weights = [1 ])) isa Array{Float64,N}
128
+ @test (@inferred _histogram (style, x1, edges′... )) isa Array{Float64,N}
129
+ @test (@inferred _histogram (style, x1, edges′... ; weights = [1 ])) isa Array{Float64,N}
118
130
end
119
131
120
132
@testset " Unitful numbers" begin
128
140
# verify that the function accepts unitful quantities
129
141
@test _histogram! (style, uhist, HistEdge .(uedges), vals, nothing ) === 1.0
130
142
@test sum (uhist) * mapreduce (step, * , uedges) ≈ 1.0 rtol= 2 eps (1.0 )
143
+
144
+ uhist2 = _histogram (style, vals, uedges)
145
+ @test eltype (uhist2) == eltype (uhist)
146
+ @test uhist2 == uhist
147
+
148
+ uhist3 = _histogram (style, vals, uedges... )
149
+ @test eltype (uhist3) == eltype (uhist)
150
+ @test uhist3 == uhist
131
151
end
132
152
end
133
153
0 commit comments