Repository: hyrodium/BasicBSpline.jl (julia)

Issue:
Stop promotion `KnotVector([1,2,3])` to `KnotVector([1.0,2.0,3.0])`
```julia
julia> KnotVector([1,2,3])
KnotVector([1.0, 2.0, 3.0])
```

Pull request:
This PR fixes #207.

Patch:
diff --git a/src/_BSplineBasis.jl b/src/_BSplineBasis.jl
index a2ca18fc1..7bae71f62 100644
--- a/src/_BSplineBasis.jl
+++ b/src/_BSplineBasis.jl
@@ -21,7 +21,7 @@ Right-sided limit version.
 # Examples
 ```jldoctest
 julia> P = BSplineSpace{0}(KnotVector(1:6))
-BSplineSpace{0, Float64}(KnotVector([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]))
+BSplineSpace{0, Int64}(KnotVector([1, 2, 3, 4, 5, 6]))
 
 julia> bsplinebasis₊₀.(P,1:5,(1:6)')
 5×6 Matrix{Float64}:
@@ -79,7 +79,7 @@ Left-sided limit version.
 # Examples
 ```jldoctest
 julia> P = BSplineSpace{0}(KnotVector(1:6))
-BSplineSpace{0, Float64}(KnotVector([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]))
+BSplineSpace{0, Int64}(KnotVector([1, 2, 3, 4, 5, 6]))
 
 julia> bsplinebasis₋₀.(P,1:5,(1:6)')
 5×6 Matrix{Float64}:
@@ -138,7 +138,7 @@ Modified version.
 # Examples
 ```jldoctest
 julia> P = BSplineSpace{0}(KnotVector(1:6))
-BSplineSpace{0, Float64}(KnotVector([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]))
+BSplineSpace{0, Int64}(KnotVector([1, 2, 3, 4, 5, 6]))
 
 julia> bsplinebasis.(P,1:5,(1:6)')
 5×6 Matrix{Float64}:
diff --git a/src/_BSplineManifold.jl b/src/_BSplineManifold.jl
index e014454ae..f1e9e3fc9 100644
--- a/src/_BSplineManifold.jl
+++ b/src/_BSplineManifold.jl
@@ -13,7 +13,7 @@ Construct Rational B-spline manifold from given control points and B-spline spac
 julia> using StaticArrays
 
 julia> P = BSplineSpace{2}(KnotVector(0,0,0,1,1,1))
-BSplineSpace{2, Float64}(KnotVector([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]))
+BSplineSpace{2, Int64}(KnotVector([0, 0, 0, 1, 1, 1]))
 
 julia> a = [SVector(1,0), SVector(1,1), SVector(0,1)]
 3-element Vector{SVector{2, Int64}}:
diff --git a/src/_BSplineSpace.jl b/src/_BSplineSpace.jl
index 82a5ff275..ceb6d7f1e 100644
--- a/src/_BSplineSpace.jl
+++ b/src/_BSplineSpace.jl
@@ -34,10 +34,10 @@ julia> p = 2
 2
 
 julia> k = KnotVector([1,3,5,6,8,9])
-KnotVector([1.0, 3.0, 5.0, 6.0, 8.0, 9.0])
+KnotVector([1, 3, 5, 6, 8, 9])
 
 julia> BSplineSpace{p}(k)
-BSplineSpace{2, Float64}(KnotVector([1.0, 3.0, 5.0, 6.0, 8.0, 9.0]))
+BSplineSpace{2, Int64}(KnotVector([1, 3, 5, 6, 8, 9]))
 ```
 """
 struct BSplineSpace{p, T<:Real} <: AbstractBSplineSpace{p,T}
@@ -280,7 +280,7 @@ end
 """
 Expand B-spline space with given additional degree and knotvector.
 """
-function expandspace_I(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector{T}=KnotVector{T}()) where {p,T}
+function expandspace_I(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector=KnotVector{T}()) where {p,T}
     k = knotvector(P)
     k̂ = unique(k[1+p:end-p])
     p′ = p + p₊
@@ -292,7 +292,7 @@ end
 """
 Expand B-spline space with given additional degree and knotvector.
 """
-function expandspace_R(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector{T}=KnotVector{T}()) where {p,T}
+function expandspace_R(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector=KnotVector{T}()) where {p,T}
     k = knotvector(P)
     p′ = p + p₊
     k′ = k + p₊*k
@@ -303,6 +303,6 @@ end
 """
 Expand B-spline space with given additional degree and knotvector.
 """
-function expandspace(P::BSplineSpace{p,T}; p₊::Integer=0, k₊::KnotVector{T}=KnotVector{T}()) where {p,T}
+function expandspace(P::BSplineSpace{p,T}; p₊=0, k₊=KnotVector{T}()) where {p,T}
     expandspace_I(P,p₊=p₊,k₊=k₊)
 end
diff --git a/src/_KnotVector.jl b/src/_KnotVector.jl
index ed43318f9..2caa6d09d 100644
--- a/src/_KnotVector.jl
+++ b/src/_KnotVector.jl
@@ -11,10 +11,10 @@ k=(k_1,\dots,k_l)
 # Examples
 ```jldoctest
 julia> k = KnotVector([1,2,3])
-KnotVector([1.0, 2.0, 3.0])
+KnotVector([1, 2, 3])
 
 julia> k = KnotVector(1:3)
-KnotVector([1.0, 2.0, 3.0])
+KnotVector([1, 2, 3])
 ```
 """
 struct KnotVector{T} <: AbstractKnotVector{T}
@@ -22,10 +22,7 @@ struct KnotVector{T} <: AbstractKnotVector{T}
     global unsafe_knotvector(::Type{T}, v) where T = new{T}(v)
 end
 KnotVector{T}(v::AbstractVector) where T = unsafe_knotvector(T,sort(v))
-function KnotVector(v::AbstractVector{T}) where {T<:Real}
-    Base.depwarn("KnotVector([1, 2]) will not be converted to KnotVector([1.0, 2.0]) in the next breaking release", :KnotVector)
-    unsafe_knotvector(float(T),sort(v))
-end
+KnotVector(v::AbstractVector{T}) where {T<:Real} = unsafe_knotvector(T,sort(v))
 
 KnotVector(k::KnotVector) = k
 KnotVector(k::AbstractKnotVector{T}) where T = unsafe_knotvector(T,_vec(k))
@@ -43,14 +40,14 @@ Construct knot vector from given real numbers.
 # Examples
 ```jldoctest
 julia> k = KnotVector(1,2,3)
-KnotVector([1.0, 2.0, 3.0])
+KnotVector([1, 2, 3])
 
 julia> k = KnotVector()
 KnotVector([])
 ```
 """
 function KnotVector(knots::Real...)
-    return KnotVector(collect(knots))
+    return KnotVector(collect(promote(knots...)))
 end
 function KnotVector{T}(knots::Real...) where T<:Real
     return unsafe_knotvector(T, sort!(collect(knots)))
@@ -105,7 +102,7 @@ julia> k1 = KnotVector(1,2,3,5);
 julia> k2 = KnotVector(4,5,8);
 
 julia> k1 + k2
-KnotVector([1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 8.0])
+KnotVector([1, 2, 3, 4, 5, 5, 8])
 ```
 """
 Base.:+(k1::KnotVector{T}, k2::KnotVector{T}) where T = unsafe_knotvector(T,sort!(vcat(k1.vector,k2.vector)))
@@ -127,7 +124,7 @@ For example, ``2\cdot (1,2,2,5)=(1,1,2,2,2,2,5,5)``.
 julia> k = KnotVector(1,2,2,5);
 
 julia> 2 * k
-KnotVector([1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 5.0, 5.0])
+KnotVector([1, 1, 2, 2, 2, 2, 5, 5])
 ```
 """
 function Base.:*(m::Integer, k::AbstractKnotVector)
@@ -187,7 +184,7 @@ For example, ``\widehat{(1,2,2,3)}=(1,2,3)``.
 julia> k = KnotVector([1,2,2,3]);
 
 julia> unique(k)
-KnotVector([1.0, 2.0, 3.0])
+KnotVector([1, 2, 3])
 ```
 """
 Base.unique(k::KnotVector) = KnotVector(unique(k.vector))
diff --git a/src/_RationalBSplineManifold.jl b/src/_RationalBSplineManifold.jl
index 2723da23d..74612f46e 100644
--- a/src/_RationalBSplineManifold.jl
+++ b/src/_RationalBSplineManifold.jl
@@ -9,7 +9,7 @@ Construct Rational B-spline manifold from given control points, weights and B-sp
 julia> using StaticArrays, LinearAlgebra
 
 julia> P = BSplineSpace{2}(KnotVector(0,0,0,1,1,1))
-BSplineSpace{2, Float64}(KnotVector([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]))
+BSplineSpace{2, Int64}(KnotVector([0, 0, 0, 1, 1, 1]))
 
 julia> w = [1, 1/√2, 1]
 3-element Vector{Float64}:
diff --git a/src/_Refinement.jl b/src/_Refinement.jl
index b92f051f9..6c6349cec 100644
--- a/src/_Refinement.jl
+++ b/src/_Refinement.jl
@@ -79,7 +79,7 @@ end
 @doc raw"""
 Refinement of B-spline manifold with additional degree and knotvector.
 """
-function refinement(M::AbstractManifold{Dim}; p₊::Union{Nothing,NTuple{Dim,Int}}=nothing, k₊::Union{Nothing,NTuple{Dim,KnotVector{T}}}=nothing) where {Dim, T}
+function refinement(M::AbstractManifold{Dim}; p₊::Union{Nothing,NTuple{Dim,Int}}=nothing, k₊::Union{Nothing,NTuple{Dim,KnotVector{T} where T}}=nothing) where Dim
     Ps = bsplinespaces(M)
     if isnothing(p₊) & isnothing(k₊)
         Ps′ = Ps


Test patch:
diff --git a/test/test_BSplineSpace.jl b/test/test_BSplineSpace.jl
index 3300c8741..92c02791c 100644
--- a/test/test_BSplineSpace.jl
+++ b/test/test_BSplineSpace.jl
@@ -7,7 +7,7 @@
         P3 = BSplineSpace{2,Int}(P1)
         P4 = BSplineSpace{2,Real}(P1)
         @test P1 == P2 == P3 == P4 == bsplinespace(P1) == bsplinespace(P2) == bsplinespace(P3) == bsplinespace(P4)
-        @test P1 isa BSplineSpace{2,Float64}
+        @test P1 isa BSplineSpace{2,Int}
         @test P3 isa BSplineSpace{2,Int}
         @test P4 isa BSplineSpace{2,Real}
         @test_throws MethodError BSplineSpace{3}(P1)
diff --git a/test/test_KnotVector.jl b/test/test_KnotVector.jl
index 8b3b4837c..745189947 100644
--- a/test/test_KnotVector.jl
+++ b/test/test_KnotVector.jl
@@ -3,11 +3,11 @@
     k2 = KnotVector([1,2,2,3])
     k3 = KnotVector([2,4,5])
     @testset "constructor" begin
-        @test k1 isa KnotVector{Float64}
-        @test k1 == KnotVector(1:3)::KnotVector{Float64}
-        @test k1 == KnotVector([1,3,2])::KnotVector{Float64}
-        @test k1 == KnotVector(1,2,3)::KnotVector{Float64}
-        @test k1 == KnotVector(1,3,2)::KnotVector{Float64}
+        @test k1 isa KnotVector{Int64}
+        @test k1 == KnotVector(1:3)::KnotVector{Int}
+        @test k1 == KnotVector([1,3,2])::KnotVector{Int64}
+        @test k1 == KnotVector(1,2,3)::KnotVector{Int64}
+        @test k1 == KnotVector(1,3,2)::KnotVector{Int64}
         @test k1 == KnotVector(1.,3,2)::KnotVector{Float64}
         @test k1 == KnotVector{Int}(1,3,2)::KnotVector{Int}
         @test k1 != k2
@@ -16,12 +16,14 @@
         @test KnotVector{Int}(1,2) isa KnotVector{Int}
         @test KnotVector{Int}(1,2.) isa KnotVector{Int}
         @test KnotVector{Int}(k1) isa KnotVector{Int}
-        @test KnotVector(k1) isa KnotVector{Float64}
+        @test KnotVector(k1) isa KnotVector{Int}
     end
 
     @testset "eltype" begin
-        @test eltype(KnotVector([1,2,3])) == Float64
+        @test eltype(KnotVector([1,2,3])) == Int
         @test eltype(KnotVector{Int}([1,2,3])) == Int
+        @test eltype(KnotVector{Real}([1,2,3])) == Real
+        @test eltype(KnotVector{Float64}([1,2,3])) == Float64
         @test eltype(KnotVector{BigInt}([1,2,3])) == BigInt
         @test eltype(KnotVector{Rational{Int}}([1,2,3])) == Rational{Int}
     end
@@ -43,8 +45,8 @@
         end
         @test k1[1] == 1
         @test k2[end] == 3
-        @test collect(k2) isa Vector{Float64}
-        @test [k2...] isa Vector{Float64}
+        @test collect(k2) isa Vector{Int}
+        @test [k2...] isa Vector{Int}
         @test collect(k2) == [k2...]
         @test collect(k2) != k2
     end
@@ -57,7 +59,7 @@
 
         # type promotion
         @test KnotVector{Int}(1,2) + KnotVector(3) == KnotVector(1,2,3)
-        @test KnotVector{Int}(1,2) + KnotVector(3) isa KnotVector{Float64}
+        @test KnotVector{Int}(1,2) + KnotVector(3) isa KnotVector{Int}
         @test KnotVector{Int}(1,2) + KnotVector{Rational{Int}}(3) == KnotVector(1,2,3)
         @test KnotVector{Int}(1,2) + KnotVector{Rational{Int}}(3) isa KnotVector{Rational{Int}}
         @test KnotVector{Int}(1,2)*0 == KnotVector()
@@ -88,7 +90,7 @@
 
     @testset "string" begin
         k = KnotVector([1,2,2,3])
-        @test string(k) == "KnotVector([1.0, 2.0, 2.0, 3.0])"
+        @test string(k) == "KnotVector([1, 2, 2, 3])"
         @test string(KnotVector()) == "KnotVector([])"
     end