Mercurial > repos > public > sbplib_julia
changeset 1518:0cd6cf62af93 feature/grids/componentview
Merge refactor/component_type
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 21 Mar 2024 15:51:29 +0100 |
parents | 7ee7df7d9b61 (current diff) b6f6425e34ac (diff) |
children | 2fa325f08b66 |
files | src/Grids/grid.jl test/Grids/grid_test.jl |
diffstat | 8 files changed, 38 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/Grids/equidistant_grid.jl Thu Mar 21 15:51:29 2024 +0100 @@ -103,8 +103,8 @@ Note: If `limit_lower` and `limit_upper` are integers and `size` would allow a completely integer grid, `equidistant_grid` will still return a floating point -grid. This simlifies the implementation and avoids certain surprise -behaviours. +grid. This simplifies the implementation and avoids certain surprise +behaviors. """ function equidistant_grid(size::Dims, limit_lower, limit_upper) gs = map(equidistant_grid, size, limit_lower, limit_upper)
--- a/src/Grids/grid.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/Grids/grid.jl Thu Mar 21 15:51:29 2024 +0100 @@ -27,7 +27,7 @@ """ coordinate_size(g) -The lenght of the coordinate vector of `Grid` `g`. +The length of the coordinate vector of `Grid` `g`. """ coordinate_size(::Type{<:Grid{T}}) where T = _ncomponents(T) coordinate_size(g::Grid) = coordinate_size(typeof(g)) # TBD: Name of this function?! @@ -35,7 +35,15 @@ """ component_type(gf) -The type of the components of the elements of `gf`. +The type of the components of the elements of `gf`. I.e if `gf` is a vector +valued grid function, `component_view(gf)` is the element type of the vectors +at each grid point. + +# Examples +```julia-repl +julia> component_type([[1,2], [2,3], [3,4]]) +Int64 +``` """ component_type(T::Type) = eltype(eltype(T)) component_type(t) = component_type(typeof(t))
--- a/src/LazyTensors/lazy_array.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/LazyTensors/lazy_array.jl Thu Mar 21 15:51:29 2024 +0100 @@ -1,7 +1,7 @@ """ LazyArray{T,D} <: AbstractArray{T,D} -Array which is calcualted lazily when indexing. +Array which is calculated lazily when indexing. A subtype of `LazyArray` will use lazy version of `+`, `-`, `*`, `/`. """ @@ -42,7 +42,7 @@ """ LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} -Struct allowing for lazy evaluation of elementwise operations on `AbstractArray`s. +Struct allowing for lazy evaluation of element-wise operations on `AbstractArray`s. A `LazyElementwiseOperation` contains two arrays together with an operation. The operations are carried out when the `LazyElementwiseOperation` is indexed.
--- a/src/LazyTensors/lazy_tensor_operations.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/LazyTensors/lazy_tensor_operations.jl Thu Mar 21 15:51:29 2024 +0100 @@ -5,7 +5,7 @@ Allows the result of a `LazyTensor` applied to a vector to be treated as an `AbstractArray`. With a mapping `m` and a vector `v` the TensorApplication object can be created by `m*v`. -The actual result will be calcualted when indexing into `m*v`. +The actual result will be calculated when indexing into `m*v`. """ struct TensorApplication{T,R,D, TM<:LazyTensor{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R} t::TM @@ -102,7 +102,7 @@ TensorComposition(tm, tmi::IdentityTensor) TensorComposition(tmi::IdentityTensor, tm) -Composes a `Tensormapping` `tm` with an `IdentityTensor` `tmi`, by returning `tm` +Composes a `LazyTensor` `tm` with an `IdentityTensor` `tmi`, by returning `tm` """ function TensorComposition(tm::LazyTensor{T,R,D}, tmi::IdentityTensor{T,D}) where {T,R,D} @boundscheck check_domain_size(tm, range_size(tmi)) @@ -125,7 +125,7 @@ """ InflatedTensor{T,R,D} <: LazyTensor{T,R,D} -An inflated `LazyTensor` with dimensions added before and afer its actual dimensions. +An inflated `LazyTensor` with dimensions added before and after its actual dimensions. """ struct InflatedTensor{T,R,D,D_before,R_middle,D_middle,D_after, TM<:LazyTensor{T,R_middle,D_middle}} <: LazyTensor{T,R,D} before::IdentityTensor{T,D_before} @@ -219,7 +219,7 @@ @doc raw""" LazyOuterProduct(tms...) -Creates a `TensorComposition` for the outerproduct of `tms...`. +Creates a `TensorComposition` for the outer product of `tms...`. This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping. First let @@ -278,7 +278,7 @@ `tm`. An example of when this operation is useful is when extending a one -dimensional difference operator `D` to a 2D grid of a ceratin size. In that +dimensional difference operator `D` to a 2D grid of a certain size. In that case we could have ```julia
--- a/src/LazyTensors/tensor_types.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/LazyTensors/tensor_types.jl Thu Mar 21 15:51:29 2024 +0100 @@ -1,7 +1,7 @@ """ IdentityTensor{T,D} <: LazyTensor{T,D,D} -The lazy identity LazyTensor for a given size. Usefull for building up higher dimensional tensor mappings from lower +The lazy identity LazyTensor for a given size. Useful for building up higher dimensional tensor mappings from lower dimensional ones through outer products. Also used in the Implementation for InflatedTensor. """ struct IdentityTensor{T,D} <: LazyTensor{T,D,D} @@ -57,8 +57,8 @@ """ DenseTensor{T,R,D,...}(A, range_indicies, domain_indicies) -LazyTensor defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should -be considerd the range and domain of the LazyTensor. Each set of indices must be ordered in ascending order. +LazyTensor defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indices of A should +be considered the range and domain of the LazyTensor. Each set of indices must be ordered in ascending order. For instance, if A is a m x n matrix, and range_size = (1,), domain_size = (2,), then the DenseTensor performs the standard matrix-vector product on vectors of size n.
--- a/src/LazyTensors/tuple_manipulation.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/LazyTensors/tuple_manipulation.jl Thu Mar 21 15:51:29 2024 +0100 @@ -3,7 +3,7 @@ Splits the multi-index `I` into two parts. One part which is expected to be used as a view, and one which is expected to be used as an index. -Eg. +E.g. ```julia-repl julia> LazyTensors.split_index(1, 3, 2, 1, (1,2,3,4)...) ((1, Colon(), Colon(), Colon(), 4), (2, 3)) @@ -33,7 +33,7 @@ split_tuple(t, szs) Split the tuple `t` into a set of tuples of the sizes given in `szs`. -`sum(szs)` should equal `lenght(t)`. +`sum(szs)` should equal `length(t)`. E.g ```julia-repl
--- a/src/SbpOperators/stencil_set.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/src/SbpOperators/stencil_set.jl Thu Mar 21 15:51:29 2024 +0100 @@ -5,7 +5,7 @@ StencilSet A `StencilSet` contains a set of associated stencils. The stencils -are are stored in a table, and can be accesed by indexing into the `StencilSet`. +are are stored in a table, and can be accessed by indexing into the `StencilSet`. """ struct StencilSet table @@ -21,7 +21,7 @@ table of the `StencilSet` is a parsed TOML intended for functions like `parse_scalar` and `parse_stencil`. -The `StencilSet` table is not parsed beyond the inital TOML parse. To get usable +The `StencilSet` table is not parsed beyond the initial TOML parse. To get usable stencils use the `parse_stencil` functions on the fields of the stencil set. The reason for this is that since stencil sets are intended to be very
--- a/test/Grids/grid_test.jl Thu Mar 21 07:43:48 2024 +0100 +++ b/test/Grids/grid_test.jl Thu Mar 21 15:51:29 2024 +0100 @@ -15,19 +15,21 @@ @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3 +end - @testset "component_type" begin - @test component_type(DummyGrid{Int,1}()) == Int - @test component_type(DummyGrid{Float64,1}()) == Float64 - @test component_type(DummyGrid{Rational,1}()) == Rational +@testset "component_type" begin + @test component_type(DummyGrid{Int,1}()) == Int + @test component_type(DummyGrid{Float64,1}()) == Float64 + @test component_type(DummyGrid{Rational,1}()) == Rational - @test component_type(DummyGrid{SVector{3,Int},2}()) == Int - @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 - @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational + @test component_type(DummyGrid{SVector{3,Int},2}()) == Int + @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 + @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational - @test component_type(DummyGrid{Float64,1}) == Float64 - @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 - end + @test component_type(DummyGrid{Float64,1}) == Float64 + @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 + + @test component_type(fill(@SVector[1,2], 4,2)) == Int end @testset "eval_on" begin