Skip to content

Commit ede86ec

Browse files
committed
ENH: added convenience methods to BasisMatrix to not pass ABSR
1 parent 395f1f0 commit ede86ec

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/basis_structure.jl

+18-3
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,34 @@ function BasisMatrix{N,BT,T2}(::Type{T2}, basis::Basis{N,BT}, ::Tensor,
273273
BasisMatrix{Tensor,val_type}(out_order, vals)
274274
end
275275

276+
# When the user doesn't supply a ABSR, we pick one for them.
277+
# for x::AbstractMatrix we pick direct
278+
# for x::TensorX we pick Tensor
279+
function BasisMatrix{T2}(::Type{T2}, basis::Basis, x::AbstractArray, order=0)
280+
BasisMatrix(T2, basis, Direct(), x, order)
281+
end
282+
283+
function BasisMatrix{T2}(::Type{T2}, basis::Basis, x::TensorX, order=0)
284+
BasisMatrix(T2, basis, Tensor(), x, order)
285+
end
286+
276287

277288
# method to allow passing types instead of instances of ABSR
278289
function BasisMatrix{BST<:ABSR,T2}(::Type{T2}, basis, ::Type{BST}, x, order=0)
279290
BasisMatrix(T2, basis, BST(), x, order)
280291
end
281292

282-
# default method without intermediate types
293+
function BasisMatrix{BST<:ABSR}(basis, ::Type{BST}, x, order=0)
294+
BasisMatrix(basis, BST(), x, order)
295+
end
296+
297+
# method without vals eltypes
283298
function BasisMatrix{TBM<:ABSR}(basis::Basis, tbm::TBM, x, order=0)
284299
BasisMatrix(Void, basis, tbm, x, order)
285300
end
286301

287-
function BasisMatrix{BST<:ABSR}(basis, ::Type{BST}, x, order=0)
288-
BasisMatrix(basis, BST(), x, order)
302+
function BasisMatrix(basis::Basis, x, order=0)
303+
BasisMatrix(Void, basis, x, order)
289304
end
290305

291306
# method without x

test/basis_structure.jl

+16
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,20 @@
206206
@test eltype(bs3.vals) == SplineSparse{Float32,Int}
207207
end
208208

209+
@testset "no ABSR" begin
210+
bmd = BasisMatrix(mb, X)
211+
bmt = BasisMatrix(mb, x123)
212+
@test isa(bmd, BasisMatrix{Direct})
213+
@test isa(bmt, BasisMatrix{Tensor})
214+
215+
bmd2 = BasisMatrix(SplineSparse, mb, X)
216+
bmt2 = BasisMatrix(SplineSparse, mb, x123)
217+
@test isa(bmd2.vals[1], SplineSparse)
218+
@test isa(bmd2.vals[2], Matrix)
219+
@test isa(bmd2.vals[3], SplineSparse)
220+
@test isa(bmt2.vals[1], SplineSparse)
221+
@test isa(bmt2.vals[2], Matrix)
222+
@test isa(bmt2.vals[3], SplineSparse)
223+
end
224+
209225
end # testset

0 commit comments

Comments
 (0)