Skip to content

Commit bc5a38f

Browse files
authored
Clean up strictconvert usage (#253)
1 parent 58a6b89 commit bc5a38f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/onehotvector.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Base.getindex(v::OneHotVector{T}, i::Int) where {T}
1515
i == v.n ? one(T) : zero(T)
1616
end
1717
# assume that the basis label starts at zero
18-
function basisfunction(sp, k)
19-
k >= 0 || throw(ArgumentError("basis label must be non-negative, received $k"))
20-
Fun(sp, OneHotVector(k))
18+
function basisfunction(sp, oneindex)
19+
oneindex >= 0 || throw(ArgumentError("index to set to one must be non-negative, received $oneindex"))
20+
Fun(sp, OneHotVector(oneindex))
2121
end

src/specialfunctions.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ end
433433

434434
for OP in (:<,:(Base.isless),:(<=))
435435
@eval begin
436-
$OP(a::Fun{<:ConstantSpace},b::Fun{<:ConstantSpace}) = $OP(strictconvert(Number,a),Number(b))
436+
$OP(a::Fun{<:ConstantSpace},b::Fun{<:ConstantSpace}) =
437+
$OP(strictconvert(Number,a), strictconvert(Number, b))
437438
$OP(a::Fun{<:ConstantSpace},b::Number) = $OP(strictconvert(Number,a),b)
438439
$OP(a::Number,b::Fun{<:ConstantSpace}) = $OP(a,strictconvert(Number,b))
439440
end
@@ -479,8 +480,8 @@ for op in (:(argmax),:(argmin))
479480
pts = extremal_args(f)
480481
# the extra real avoids issues with complex round-off
481482
v = map(realf, pts)::Vector
482-
x = pts[strictconvert(Int, $op(v))::Int]
483-
strictconvert(T, x)::T
483+
x = pts[strictconvert(Int, $op(v))]
484+
strictconvert(T, x)
484485
end
485486

486487
function $op(f::Fun)
@@ -493,7 +494,7 @@ for op in (:(argmax),:(argmin))
493494
fp = map(f, pts)
494495
@assert norm(imag(fp))<100eps()
495496
v = real(fp)::Vector
496-
x = pts[strictconvert(Int, $op(v))::Int]
497+
x = pts[strictconvert(Int, $op(v))]
497498
strictconvert(T, x)
498499
end
499500
end

0 commit comments

Comments
 (0)