Skip to content

Commit ea4cb6c

Browse files
committed
Add keyword filtering to createLinearOp helper function
1 parent 7081bed commit ea4cb6c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearOperatorCollection"
22
uuid = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
33
authors = ["Tobias Knopp <tobias.knopp@tuhh.de> and contributors"]
4-
version = "2.0.4"
4+
version = "2.0.5"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/LinearOperatorCollection.jl

+19-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,29 @@ function linearOperatorList()
5151
return subtypes(AbstractLinearOperatorFromCollection)
5252
end
5353

54+
# TODO (except for basetype) copied from RegLS, maybe place in utility package
55+
function filterKwargs(T::Type, kwargWarning, kwargs)
56+
# If we don't take the basetype we won't find any methods
57+
baseType = Base.typename(T).wrapper # https://github.com/JuliaLang/julia/issues/35543
58+
table = methods(baseType)
59+
keywords = union(Base.kwarg_decl.(table)...)
60+
filtered = filter(in(keywords), keys(kwargs))
61+
62+
if length(filtered) < length(kwargs) && kwargWarning
63+
filteredout = filter(!in(keywords), keys(kwargs))
64+
@warn "The following arguments were passed but filtered out: $(join(filteredout, ", ")). Please watch closely if this introduces unexpexted behaviour in your code."
65+
end
66+
67+
return [key=>kwargs[key] for key in filtered]
68+
end
69+
70+
5471
# Next we create the factory methods. We probably want to given
5572
# a better error message if the extension module is not loaded
5673
for op in linearOperatorList()
5774
@eval begin
58-
function createLinearOperator(::Type{ Op }; kargs...) where Op <: $op{T} where T <: Number
59-
return $op(T; kargs...)
75+
function createLinearOperator(::Type{ Op }; kwargWarning::Bool = true, kwargs...) where Op <: $op{T} where T <: Number
76+
return $op(T; filterKwargs(Op,kwargWarning,kwargs)...)
6077
end
6178
end
6279
end

0 commit comments

Comments
 (0)