File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1+ # TODO : remove once FillArrays compat for <v1 is dropped
12struct OneHotVector{T} <: AbstractVector{T}
23 n :: Int
34 len :: Int
@@ -9,13 +10,18 @@ struct OneHotVector{T} <: AbstractVector{T}
910 end
1011end
1112OneHotVector (n, len = n) = OneHotVector {Float64} (n, len)
12- Base . size (v:: OneHotVector ) = (v. len,)
13- Base . length (v:: OneHotVector ) = v. len
14- function Base . getindex (v:: OneHotVector{T} , i:: Int ) where {T}
13+ size (v:: OneHotVector ) = (v. len,)
14+ length (v:: OneHotVector ) = v. len
15+ function getindex (v:: OneHotVector{T} , i:: Int ) where {T}
1516 i == v. n ? one (T) : zero (T)
1617end
18+ @static if isdefined (FillArrays, :OneElement )
19+ const _OneElement = FillArrays. OneElement
20+ else
21+ const _OneElement = OneHotVector
22+ end
1723# assume that the basis label starts at zero
1824function basisfunction (sp, oneindex)
1925 oneindex >= 0 || throw (ArgumentError (" index to set to one must be non-negative, received $oneindex " ))
20- Fun (sp, OneHotVector ( oneindex))
26+ Fun (sp, _OneElement {Float64} (oneindex, oneindex))
2127end
You can’t perform that action at this time.
0 commit comments