Mercurial > repos > public > sbplib_julia
comparison src/Grids/equidistant_grid.jl @ 1529:43aaf710463e refactor/equidistant_grid/signature
Change to signature of equidistant_grid to same style as many array methods.
See for example Array{T}(undef, dims...), zeros(T, dims...), fill(a, dims...) and more.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 11 Apr 2024 22:31:04 +0200 |
parents | d7bc11053951 |
children | 9113f437431d c3425b4302b8 efe1fc4cb6b0 |
comparison
equal
deleted
inserted
replaced
1528:d641798539c2 | 1529:43aaf710463e |
---|---|
86 return EquidistantGrid(change_length(g.points, new_sz)) | 86 return EquidistantGrid(change_length(g.points, new_sz)) |
87 end | 87 end |
88 | 88 |
89 | 89 |
90 """ | 90 """ |
91 equidistant_grid(size::Dims, limit_lower, limit_upper) | 91 equidistant_grid(limit_lower, limit_upper, dims...) |
92 | 92 |
93 Construct an equidistant grid with corners at the coordinates `limit_lower` and | 93 Construct an equidistant grid with corners at the coordinates `limit_lower` and |
94 `limit_upper`. | 94 `limit_upper`. |
95 | 95 |
96 The length of the domain sides are given by the components of | 96 The length of the domain sides are given by the components of |
97 `limit_upper-limit_lower`. E.g for a 2D grid with `limit_lower=(-1,0)` and | 97 `limit_upper-limit_lower`. E.g for a 2D grid with `limit_lower=(-1,0)` and |
98 `limit_upper=(1,2)` the domain is defined as `(-1,1)x(0,2)`. The side lengths | 98 `limit_upper=(1,2)` the domain is defined as `(-1,1)x(0,2)`. The side lengths |
99 of the grid are not allowed to be negative. | 99 of the grid are not allowed to be negative. |
100 | 100 |
101 The number of equispaced points in each coordinate direction are given | 101 The number of equispaced points in each coordinate direction are given |
102 by the tuple `size`. | 102 by the tuple `dims`. |
103 | 103 |
104 Note: If `limit_lower` and `limit_upper` are integers and `size` would allow a | 104 Note: If `limit_lower` and `limit_upper` are integers and `dims` would allow a |
105 completely integer grid, `equidistant_grid` will still return a floating point | 105 completely integer grid, `equidistant_grid` will still return a floating point |
106 grid. This simplifies the implementation and avoids certain surprise | 106 grid. This simplifies the implementation and avoids certain surprise |
107 behaviors. | 107 behaviors. |
108 """ | 108 """ |
109 function equidistant_grid(size::Dims, limit_lower, limit_upper) | 109 function equidistant_grid(limit_lower, limit_upper, dims::Vararg{Int}) |
110 gs = map(equidistant_grid, size, limit_lower, limit_upper) | 110 gs = map(equidistant_grid, limit_lower, limit_upper, dims) |
111 return TensorGrid(gs...) | 111 return TensorGrid(gs...) |
112 end | 112 end |
113 | 113 |
114 """ | 114 """ |
115 equidistant_grid(size::Int, limit_lower::T, limit_upper::T) | 115 equidistant_grid(limit_lower::T, limit_upper::T, size::Int) |
116 | 116 |
117 Constructs a 1D equidistant grid. | 117 Constructs a 1D equidistant grid. |
118 """ | 118 """ |
119 function equidistant_grid(size::Int, limit_lower::T, limit_upper::T) where T | 119 function equidistant_grid(limit_lower::T, limit_upper::T, size::Int) where T |
120 if any(size .<= 0) | 120 if any(size .<= 0) |
121 throw(DomainError("size must be postive")) | 121 throw(DomainError("size must be postive")) |
122 end | 122 end |
123 | 123 |
124 if any(limit_upper.-limit_lower .<= 0) | 124 if any(limit_upper.-limit_lower .<= 0) |