2
2
# BasisMatrix Type #
3
3
# ------------------- #
4
4
5
- @compat abstract type AbstractBasisMatrixRep end
5
+ abstract type AbstractBasisMatrixRep end
6
6
const ABSR = AbstractBasisMatrixRep
7
7
8
- immutable Tensor <: ABSR end
9
- immutable Direct <: ABSR end
10
- immutable Expanded <: ABSR end
8
+ struct Tensor <: ABSR end
9
+ struct Direct <: ABSR end
10
+ struct Expanded <: ABSR end
11
11
12
- type BasisMatrix{BST<: ABSR , TM<: AbstractMatrix }
12
+ mutable struct BasisMatrix{BST<: ABSR , TM<: AbstractMatrix }
13
13
order:: Matrix{Int}
14
14
vals:: Matrix{TM}
15
15
end
16
16
17
- Base. show {BST} (io:: IO , b:: BasisMatrix{BST} ) =
17
+ Base. show (io:: IO , b:: BasisMatrix{BST} ) where {BST} =
18
18
print (io, " BasisMatrix{$BST } of order $(b. order) " )
19
19
20
20
Base. ndims (bs:: BasisMatrix ) = size (bs. order, 2 )
21
21
22
22
# not the same if either type parameter is different
23
- function == {BST1 <: ABSR ,BST2 <: ABSR } (:: BasisMatrix{BST1} , :: BasisMatrix{BST2} )
23
+ function == (:: BasisMatrix{BST1} , :: BasisMatrix{BST2} ) where {BST1 <: ABSR ,BST2 <: ABSR }
24
24
false
25
25
end
26
26
27
- function == {BST <: ABSR ,TM1 <: AbstractMatrix ,TM2 <: AbstractMatrix } (:: BasisMatrix{BST,TM1} ,
28
- :: BasisMatrix{BST,TM2} )
27
+ function == (:: BasisMatrix{BST,TM1} ,
28
+ :: BasisMatrix{BST,TM2} ) where {BST <: ABSR ,TM1 <: AbstractMatrix ,TM2 <: AbstractMatrix }
29
29
false
30
30
end
31
31
32
32
# if type parameters are the same, then it is the same if all fields are the
33
33
# same
34
- function == {BST <: ABSR ,TM <: AbstractMatrix } (b1:: BasisMatrix{BST,TM} ,
35
- b2:: BasisMatrix{BST,TM} )
34
+ function == (b1:: BasisMatrix{BST,TM} ,
35
+ b2:: BasisMatrix{BST,TM} ) where {BST <: ABSR ,TM <: AbstractMatrix }
36
36
b1. order == b2. order && b1. vals == b2. vals
37
37
end
38
38
45
45
x
46
46
end
47
47
48
- @inline function _checkx {T} (N, x:: AbstractVector{T} )
48
+ @inline function _checkx (N, x:: AbstractVector{T} ) where T
49
49
# if we have a 1d basis, we can evaluate at each point
50
50
if N == 1
51
51
return x
@@ -132,11 +132,11 @@ end
132
132
# --------------- #
133
133
134
134
# no-op. Don't worry about the order argument.
135
- Base. convert {T<:ABSR} (:: Type{T} , bs:: BasisMatrix{T} , order= bs. order) = bs
135
+ Base. convert (:: Type{T} , bs:: BasisMatrix{T} , order= bs. order) where {T <: ABSR } = bs
136
136
137
137
# funbconv from direct to expanded
138
- function Base. convert {TM} (:: Type{Expanded} , bs:: BasisMatrix{Direct,TM} ,
139
- order= fill (0 , 1 , size (bs. order, 2 )))
138
+ function Base. convert (:: Type{Expanded} , bs:: BasisMatrix{Direct,TM} ,
139
+ order= fill (0 , 1 , size (bs. order, 2 ))) where TM
140
140
d, numbas, d1 = check_convert (bs, order)
141
141
142
142
vals = Array {TM} (numbas, 1 )
@@ -152,8 +152,8 @@ function Base.convert{TM}(::Type{Expanded}, bs::BasisMatrix{Direct,TM},
152
152
end
153
153
154
154
# funbconv from tensor to expanded
155
- function Base. convert {TM} (:: Type{Expanded} , bs:: BasisMatrix{Tensor,TM} ,
156
- order= fill (0 , 1 , size (bs. order, 2 )))
155
+ function Base. convert (:: Type{Expanded} , bs:: BasisMatrix{Tensor,TM} ,
156
+ order= fill (0 , 1 , size (bs. order, 2 ))) where TM
157
157
d, numbas, d1 = check_convert (bs, order)
158
158
159
159
vals = Array {TM} (numbas, 1 )
174
174
# plan on doing it much, this will do for now. The basic point is that
175
175
# we need to expand the rows of each element of `vals` so that all of
176
176
# them have prod([size(v, 1) for v in bs.vals])) rows.
177
- function Base. convert {TM} (:: Type{Direct} , bs:: BasisMatrix{Tensor,TM} ,
178
- order= fill (0 , 1 , size (bs. order, 2 )))
177
+ function Base. convert (:: Type{Direct} , bs:: BasisMatrix{Tensor,TM} ,
178
+ order= fill (0 , 1 , size (bs. order, 2 ))) where TM
179
179
d, numbas, d1 = check_convert (bs, order)
180
180
vals = Array {TM} (numbas, d)
181
181
raw_ind = Array {Vector{Int}} (d)
206
206
207
207
# method to construct BasisMatrix in direct or expanded form based on
208
208
# a matrix of `x` values -- funbasex
209
- function BasisMatrix {N,BF,T2} (:: Type{T2} , basis:: Basis{N,BF} , :: Direct ,
210
- x:: AbstractArray = nodes (basis)[1 ], order= 0 )
209
+ function BasisMatrix (:: Type{T2} , basis:: Basis{N,BF} , :: Direct ,
210
+ x:: AbstractArray = nodes (basis)[1 ], order= 0 ) where {N,BF,T2}
211
211
m, order, minorder, numbases, x = check_basis_structure (N, x, order)
212
212
# 76-77
213
213
out_order = minorder
@@ -237,15 +237,15 @@ function BasisMatrix{N,BF,T2}(::Type{T2}, basis::Basis{N,BF}, ::Direct,
237
237
BasisMatrix {Direct,val_type} (out_order, vals)
238
238
end
239
239
240
- function BasisMatrix {T2} (:: Type{T2} , basis:: Basis , :: Expanded ,
241
- x:: AbstractArray = nodes (basis)[1 ], order= 0 ) # funbasex
240
+ function BasisMatrix (:: Type{T2} , basis:: Basis , :: Expanded ,
241
+ x:: AbstractArray = nodes (basis)[1 ], order= 0 ) where T2 # funbasex
242
242
# create direct form, then convert to expanded
243
243
bsd = BasisMatrix (T2, basis, Direct (), x, order)
244
244
convert (Expanded, bsd, bsd. order)
245
245
end
246
246
247
- function BasisMatrix {N,BT,T2} (:: Type{T2} , basis:: Basis{N,BT} , :: Tensor ,
248
- x:: TensorX = nodes (basis)[2 ], order= 0 )
247
+ function BasisMatrix (:: Type{T2} , basis:: Basis{N,BT} , :: Tensor ,
248
+ x:: TensorX = nodes (basis)[2 ], order= 0 ) where {N,BT,T2}
249
249
250
250
m, order, minorder, numbases, x = check_basis_structure (N, x, order)
251
251
out_order = minorder
@@ -276,29 +276,29 @@ end
276
276
# When the user doesn't supply a ABSR, we pick one for them.
277
277
# for x::AbstractMatrix we pick direct
278
278
# for x::TensorX we pick Tensor
279
- function BasisMatrix {T2} (:: Type{T2} , basis:: Basis , x:: AbstractArray , order= 0 )
279
+ function BasisMatrix (:: Type{T2} , basis:: Basis , x:: AbstractArray , order= 0 ) where T2
280
280
BasisMatrix (T2, basis, Direct (), x, order)
281
281
end
282
282
283
- function BasisMatrix {T2} (:: Type{T2} , basis:: Basis , x:: TensorX , order= 0 )
283
+ function BasisMatrix (:: Type{T2} , basis:: Basis , x:: TensorX , order= 0 ) where T2
284
284
BasisMatrix (T2, basis, Tensor (), x, order)
285
285
end
286
286
287
287
288
288
# method to allow passing types instead of instances of ABSR
289
- function BasisMatrix {BST<:ABSR,T2} (:: Type{T2} , basis, :: Type{BST} ,
290
- x:: Union{AbstractArray,TensorX} , order= 0 )
289
+ function BasisMatrix (:: Type{T2} , basis, :: Type{BST} ,
290
+ x:: Union{AbstractArray,TensorX} , order= 0 ) where {BST <: ABSR ,T2}
291
291
BasisMatrix (T2, basis, BST (), x, order)
292
292
end
293
293
294
- function BasisMatrix {BST<:ABSR} (basis, :: Type{BST} ,
295
- x:: Union{AbstractArray,TensorX} , order= 0 )
294
+ function BasisMatrix (basis, :: Type{BST} ,
295
+ x:: Union{AbstractArray,TensorX} , order= 0 ) where BST <: ABSR
296
296
BasisMatrix (basis, BST (), x, order)
297
297
end
298
298
299
299
# method without vals eltypes
300
- function BasisMatrix {TBM<:ABSR} (basis:: Basis , tbm:: TBM ,
301
- x:: Union{AbstractArray,TensorX} , order= 0 )
300
+ function BasisMatrix (basis:: Basis , tbm:: TBM ,
301
+ x:: Union{AbstractArray,TensorX} , order= 0 ) where TBM <: ABSR
302
302
BasisMatrix (Void, basis, tbm, x, order)
303
303
end
304
304
@@ -307,6 +307,6 @@ function BasisMatrix(basis::Basis, x::Union{AbstractArray,TensorX}, order=0)
307
307
end
308
308
309
309
# method without x
310
- function BasisMatrix {TBM<:ABSR} (basis:: Basis , tbm:: Union{Type{TBM},TBM} )
310
+ function BasisMatrix (basis:: Basis , tbm:: Union{Type{TBM},TBM} ) where TBM <: ABSR
311
311
BasisMatrix (Void, basis, tbm)
312
312
end
0 commit comments