|
1 | | -struct LinearSimplex{D,N,Tv} |
2 | | - points::SVector{N,Point{D,Tv}} |
3 | | - values::SVector{N,Tv} |
| 1 | +struct LinearSimplex{D, N, Tv} |
| 2 | + points::SVector{N, Point{D, Tv}} |
| 3 | + values::SVector{N, Tv} |
4 | 4 | end |
5 | 5 |
|
6 | | -values(s::LinearSimplex)=s.values |
7 | | -points(s::LinearSimplex)=s.points |
| 6 | +values(s::LinearSimplex) = s.values |
| 7 | +points(s::LinearSimplex) = s.points |
8 | 8 |
|
9 | 9 |
|
10 | | -function LinearSimplex(::Type{Val{D}},points::Union{Vector,Tuple}, values::Union{Vector,Tuple}) where {D} |
11 | | - spoints=SVector{D+1,Point{D,Float32}}(points...) |
12 | | - svalues=SVector{D+1,Float32}(values...) |
13 | | - LinearSimplex(spoints,svalues) |
| 10 | +function LinearSimplex(::Type{Val{D}}, points::Union{Vector, Tuple}, values::Union{Vector, Tuple}) where {D} |
| 11 | + spoints = SVector{D + 1, Point{D, Float32}}(points...) |
| 12 | + svalues = SVector{D + 1, Float32}(values...) |
| 13 | + return LinearSimplex(spoints, svalues) |
14 | 14 | end |
15 | 15 |
|
16 | | -function LinearSimplex(::Type{Val{1}},points::AbstractMatrix, values::AbstractVector) |
17 | | - @views spoints=SVector{2,Point{1,Float32}}(points[:,1],points[:,2]) |
18 | | - svalues=SVector{2,Float32}(values[1],values[2]) |
19 | | - LinearSimplex(spoints,svalues) |
| 16 | +function LinearSimplex(::Type{Val{1}}, points::AbstractMatrix, values::AbstractVector) |
| 17 | + @views spoints = SVector{2, Point{1, Float32}}(points[:, 1], points[:, 2]) |
| 18 | + svalues = SVector{2, Float32}(values[1], values[2]) |
| 19 | + return LinearSimplex(spoints, svalues) |
20 | 20 | end |
21 | 21 |
|
22 | | -function LinearSimplex(::Type{Val{2}},points::AbstractMatrix, values::AbstractVector) |
23 | | - @views spoints=SVector{3,Point{2,Float32}}(points[:,1],points[:,2],points[:,3]) |
24 | | - svalues=SVector{3,Float32}(values[1],values[2],values[3]) |
25 | | - LinearSimplex(spoints,svalues) |
| 22 | +function LinearSimplex(::Type{Val{2}}, points::AbstractMatrix, values::AbstractVector) |
| 23 | + @views spoints = SVector{3, Point{2, Float32}}(points[:, 1], points[:, 2], points[:, 3]) |
| 24 | + svalues = SVector{3, Float32}(values[1], values[2], values[3]) |
| 25 | + return LinearSimplex(spoints, svalues) |
26 | 26 | end |
27 | 27 |
|
28 | | -function LinearSimplex(::Type{Val{3}},points::AbstractMatrix, values::AbstractVector) |
29 | | - @views spoints=SVector{4,Point{3,Float32}}(points[:,1],points[:,2],points[:,3],points[:,4]) |
30 | | - svalues=SVector{4,Float32}(values[1],values[2],values[3],values[4]) |
31 | | - LinearSimplex(spoints,svalues) |
| 28 | +function LinearSimplex(::Type{Val{3}}, points::AbstractMatrix, values::AbstractVector) |
| 29 | + @views spoints = SVector{4, Point{3, Float32}}(points[:, 1], points[:, 2], points[:, 3], points[:, 4]) |
| 30 | + svalues = SVector{4, Float32}(values[1], values[2], values[3], values[4]) |
| 31 | + return LinearSimplex(spoints, svalues) |
32 | 32 | end |
33 | 33 |
|
34 | 34 |
|
35 | | -function LinearSimplex(::Type{Val{1}},points::AbstractMatrix, values::AbstractVector,coordscale) |
36 | | - @views spoints=SVector{2,Point{1,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale) |
37 | | - svalues=SVector{2,Float32}(values[1],values[2]) |
38 | | - LinearSimplex(spoints,svalues) |
| 35 | +function LinearSimplex(::Type{Val{1}}, points::AbstractMatrix, values::AbstractVector, coordscale) |
| 36 | + @views spoints = SVector{2, Point{1, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale) |
| 37 | + svalues = SVector{2, Float32}(values[1], values[2]) |
| 38 | + return LinearSimplex(spoints, svalues) |
39 | 39 | end |
40 | 40 |
|
41 | | -function LinearSimplex(::Type{Val{2}},points::AbstractMatrix, values::AbstractVector,coordscale) |
42 | | - @views spoints=SVector{3,Point{2,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale,points[:,3]*coordscale) |
43 | | - svalues=SVector{3,Float32}(values[1],values[2],values[3]) |
44 | | - LinearSimplex(spoints,svalues) |
| 41 | +function LinearSimplex(::Type{Val{2}}, points::AbstractMatrix, values::AbstractVector, coordscale) |
| 42 | + @views spoints = SVector{3, Point{2, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale, points[:, 3] * coordscale) |
| 43 | + svalues = SVector{3, Float32}(values[1], values[2], values[3]) |
| 44 | + return LinearSimplex(spoints, svalues) |
45 | 45 | end |
46 | 46 |
|
47 | | -function LinearSimplex(::Type{Val{3}},points::AbstractMatrix, values::AbstractVector,coordscale) |
48 | | - @views spoints=SVector{4,Point{3,Float32}}(points[:,1]*coordscale,points[:,2]*coordscale,points[:,3]*coordscale,points[:,4]*coordscale) |
49 | | - svalues=SVector{4,Float32}(values[1],values[2],values[3],values[4]) |
50 | | - LinearSimplex(spoints,svalues) |
| 47 | +function LinearSimplex(::Type{Val{3}}, points::AbstractMatrix, values::AbstractVector, coordscale) |
| 48 | + @views spoints = SVector{4, Point{3, Float32}}(points[:, 1] * coordscale, points[:, 2] * coordscale, points[:, 3] * coordscale, points[:, 4] * coordscale) |
| 49 | + svalues = SVector{4, Float32}(values[1], values[2], values[3], values[4]) |
| 50 | + return LinearSimplex(spoints, svalues) |
51 | 51 | end |
52 | 52 |
|
53 | | -LinearEdge(points,values)=LinearSimplex(Val{1},points,values) |
54 | | -LinearTriangle(points,values)=LinearSimplex(Val{2},points,values) |
55 | | -LinearTetrahedron(points,values)=LinearSimplex(Val{3},points,values) |
| 53 | +LinearEdge(points, values) = LinearSimplex(Val{1}, points, values) |
| 54 | +LinearTriangle(points, values) = LinearSimplex(Val{2}, points, values) |
| 55 | +LinearTetrahedron(points, values) = LinearSimplex(Val{3}, points, values) |
56 | 56 |
|
57 | 57 |
|
58 | 58 | """ |
@@ -81,15 +81,15 @@ Useful for: |
81 | 81 | very few (<10) allocations. So any allocations beyond this from a |
82 | 82 | call to `testloop` hint at possibilities to improve an iterator implementation. |
83 | 83 | """ |
84 | | -function testloop(iterators::AbstractVector{T}) where T<:LinearSimplexIterator |
85 | | - threads=map(iterators) do iterator |
86 | | - begin |
87 | | - local x=0.0 |
| 84 | +function testloop(iterators::AbstractVector{T}) where {T <: LinearSimplexIterator} |
| 85 | + threads = map(iterators) do iterator |
| 86 | + begin |
| 87 | + local x = 0.0 |
88 | 88 | for vt in iterator |
89 | | - x+=sum(vt.values) |
| 89 | + x += sum(vt.values) |
90 | 90 | end |
91 | | - x |
92 | | - end |
| 91 | + x |
| 92 | + end |
93 | 93 | end |
94 | | - sum(fetch.(threads)) |
| 94 | + return sum(fetch.(threads)) |
95 | 95 | end |
0 commit comments