Mercurial > repos > public > sbplib_julia
comparison src/RegionIndices/RegionIndices.jl @ 1868:81559cb7b11c feature/grids/manifolds
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Jan 2025 23:22:11 +0100 |
parents | 3ada7e9be4d6 |
children |
comparison
equal
deleted
inserted
replaced
1867:de4b4f2aee4f | 1868:81559cb7b11c |
---|---|
23 ## Vill kunna skriva | 23 ## Vill kunna skriva |
24 ## IndexTupleType(Int, (Lower, Interior)) | 24 ## IndexTupleType(Int, (Lower, Interior)) |
25 Index(R::Type{<:Region}, T::Type{<:Integer}) = Index{R,T} | 25 Index(R::Type{<:Region}, T::Type{<:Integer}) = Index{R,T} |
26 IndexTupleType(T::Type{<:Integer},R::NTuple{N, DataType} where N) = Tuple{Index.(R, T)...} | 26 IndexTupleType(T::Type{<:Integer},R::NTuple{N, DataType} where N) = Tuple{Index.(R, T)...} |
27 | 27 |
28 Base.convert(::Type{T}, i::Index{R,T} where R) where T = i.i | 28 Base.convert(::Type{T}, i::Index{R,T} where R) where T <: Integer = i.i |
29 Base.convert(::Type{CartesianIndex}, I::NTuple{N,Index} where N) = CartesianIndex(convert.(Int, I)) | 29 Base.convert(::Type{CartesianIndex}, I::NTuple{N,Index} where N) = CartesianIndex(convert.(Int, I)) |
30 | 30 |
31 Base.Int(I::Index) = I.i | 31 Base.Int(I::Index) = I.i |
32 Base.to_index(I::Index) = Int(I) #How to get this to work for all cases?? | 32 Base.to_index(I::Index) = Int(I) #How to get this to work for all cases?? |
33 Base.getindex(A::AbstractArray{T,N}, I::NTuple{N,Index}) where {T,N} = A[I...] #Is this ok?? | |
34 | 33 |
35 function Index(i::Integer, boundary_width::Integer, dim_size::Integer) | 34 function Index(i::Integer, boundary_width::Integer, dim_size::Integer) |
36 return Index{getregion(i,boundary_width,dim_size)}(i) | 35 return Index{getregion(i,boundary_width,dim_size)}(i) |
37 end | 36 end |
38 | 37 |
39 IndexTuple(t::Vararg{Tuple{T, DataType}}) where T<:Integer = Index.(t) | 38 IndexTuple(t::Vararg{Tuple{Integer, DataType}}) = Index.(t) |
40 export IndexTuple | 39 export IndexTuple |
41 | 40 |
42 # TODO: Use the values of the region structs, e.g. Lower(), for the region parameter instead of the types. | 41 # TODO: Use the values of the region structs, e.g. Lower(), for the region parameter instead of the types. |
43 # For example the following works: | 42 # For example the following works: |
44 # (Lower(),Upper()) isa NTuple{2, Region} -> true | 43 # (Lower(),Upper()) isa NTuple{2, Region} -> true |