@@ -32,60 +32,22 @@ checkbounds(::Type{Bool}, dict::Dictionary, idx::NTuple{N,Int}) where {N} =
3232@inline checkbounds (:: Type{Bool} , dict:: Dictionary , I... ) = checkbounds_indices (Bool, axes (dict), I)
3333
3434" Return the support of the idx-th basis function. Default is support of the dictionary."
35- function support (dict:: Dictionary , idx)
35+ function dict_support (dict, idx)
36+ checkdictionary (dict)
3637 checkbounds (dict, idx)
3738 support (dict)
3839end
39- # Warning: the functions above and below may be wrong for certain concrete
40- # dictionaries, for example for univariate functions with non-connected support.
41- # Make sure to override, and make sure that the overridden version is called.
42-
4340" Does the given point lie inside the support of the given function or dictionary?"
4441in_support (dict:: Dictionary , x) = dict_in_support (dict, x)
45- in_support (dict:: Dictionary , idx, x) = dict_in_support (dict, idx, x)
46-
47- # in_support(dict::Dictionary, x) =
48- # dict_in_support(dict, element_type_check(x, domaintype(dict)))
49- # in_support(dict::Dictionary, idx, x) =
50- # dict_in_support(dict, idx, element_type_check(x, domaintype(dict)))
51- #
52- # element_type_check(x, T) = _element_type_check(x, T, typeof(x))
53- # _element_type_check(x, T, S) = _element_type_check(x, T, S, promote_type(S,T))
54- # _element_type_check(x, T, S, V) = x
55- # _element_type_check(x, T, S, V) = x
56- # function _element_type_check(x, T, S, ::Type{Any})
57- # @warn "Dictionary with domain type $(T) may not support evaluation with type $(S)."
58- # x
59- # end
60- #
61- # # Some special cases
62- # _element_type_check(x, ::NTuple{N,T}, ::SVector{N,T}) where {T,N} = x
63- # _element_type_check(x, ::SVector{N,T}, ::NTuple{N,T}) where {T,N} = x
64-
65-
66- # The mechanism is as follows:
67- # - in_support(dict::Dictionary, ...) calls dict_in_support
68- # - any linear index is converted to a native index
69- # - concrete dictionary should implement dict_in_support
70- # The reasoning is that concrete dictionaries need not all worry about handling
71- # linear indices. Yet, they are free to implement other types of indices.
72- # If a more efficient algorithm is available for linear indices, then the concrete
73- # dictionary can still intercept the call to in_support.
74- # The delegation to a method with a different name (dict_in_support) makes it
75- # substantially easier to deal with ambiguity errors.
76-
77- # This is the standard conversion to a native_index for an index of type
78- # Int. This calls a different function, hence it is fine if the native
79- # index happens to be a linear index (Int).
80- in_support (dict:: Dictionary , idx:: Int , x) =
81- dict_in_support (dict, native_index (dict, idx), x)
82-
83- # The default fallback is implemented below in terms of the support of the dictionary:
84- dict_in_support (dict:: Dictionary , idx, x) = default_in_support (dict, idx, x)
85- dict_in_support (dict:: Dictionary , x) = default_in_support (dict, x)
86-
87- default_in_support (dict:: Dictionary , idx, x) = approx_in (x, support (dict, idx), tolerance (dict))
88- default_in_support (dict:: Dictionary , x) = approx_in (x, support (dict), tolerance (dict))
42+ in_support (dict:: Dictionary , idx, x) = dict_in_support (dict, native_index (dict, idx), x)
43+
44+ # Concrete types can override this if there is a more efficient implementation
45+ dict_in_support (dict, x) = default_in_support (dict, x)
46+ dict_in_support (dict, idx, x) = default_in_support (dict, idx, x)
47+
48+ # by default we invoke the support of the dictionary
49+ default_in_support (dict, x) = approx_in (x, support (dict), tolerance (dict))
50+ default_in_support (dict, idx, x) = approx_in (x, dict_support (dict, idx), tolerance (dict))
8951
9052
9153
0 commit comments