Mercurial > repos > public > sbplib_julia
comparison src/Grids/tensor_grid.jl @ 1270:dcbac783e4c1 refactor/grids
Factor out functions for getting the type and number of components in a type
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 25 Feb 2023 22:42:16 +0100 |
parents | a4ddae8b5d49 |
children | 3b7ebd135918 |
comparison
equal
deleted
inserted
replaced
1269:20f42cf0800c | 1270:dcbac783e4c1 |
---|---|
76 return TensorGrid(new_grids...) | 76 return TensorGrid(new_grids...) |
77 end | 77 end |
78 | 78 |
79 | 79 |
80 function combined_coordinate_vector_type(coordinate_types...) | 80 function combined_coordinate_vector_type(coordinate_types...) |
81 coord_length(::Type{<:Number}) = 1 | 81 combined_coord_length = mapreduce(_ncomponents, +, coordinate_types) |
82 coord_length(T::Type{<:SVector}) = length(T) | 82 combined_coord_type = mapreduce(_component_type, promote_type, coordinate_types) |
83 | |
84 coord_type(T::Type{<:Number}) = T | |
85 coord_type(T::Type{<:SVector}) = eltype(T) | |
86 | |
87 | |
88 combined_coord_length = mapreduce(coord_length, +, coordinate_types) | |
89 combined_coord_type = mapreduce(coord_type, promote_type, coordinate_types) | |
90 | 83 |
91 if combined_coord_length == 1 | 84 if combined_coord_length == 1 |
92 return combined_coord_type | 85 return combined_coord_type |
93 else | 86 else |
94 return SVector{combined_coord_length, combined_coord_type} | 87 return SVector{combined_coord_length, combined_coord_type} |