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
1
2
struct OneHotVector{T} <: AbstractVector{T}
2
3
n :: Int
3
4
len :: Int
@@ -9,13 +10,18 @@ struct OneHotVector{T} <: AbstractVector{T}
9
10
end
10
11
end
11
12
OneHotVector (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}
15
16
i == v. n ? one (T) : zero (T)
16
17
end
18
+ @static if isdefined (FillArrays, :OneElement )
19
+ const _OneElement = FillArrays. OneElement
20
+ else
21
+ const _OneElement = OneHotVector
22
+ end
17
23
# assume that the basis label starts at zero
18
24
function basisfunction (sp, oneindex)
19
25
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))
21
27
end
You can’t perform that action at this time.
0 commit comments