Repository: hyrodium/BasicBSpline.jl
Pull request #120 (2021-12-28 05:46:22)

update argument order of `BSplineManifold` and CustomBSplineManifold`


Patch:
diff --git a/src/_BSplineManifold.jl b/src/_BSplineManifold.jl
index 20c2ca5f..6108e1ce 100644
--- a/src/_BSplineManifold.jl
+++ b/src/_BSplineManifold.jl
@@ -8,7 +8,7 @@ dim(::AbstractBSplineManifold{Dim}) where Dim = Dim
 struct BSplineManifold{Dim,Deg,T,S<:Tuple,Dim₊₁} <: AbstractBSplineManifold{Dim,Deg}
     bsplinespaces::S
     controlpoints::Array{T,Dim₊₁}
-    function BSplineManifold(Ps::S,a::Array{T,Dim₊₁}) where {S<:Tuple,Dim₊₁,T<:Real}
+    function BSplineManifold(a::Array{T,Dim₊₁},Ps::S) where {S<:Tuple,Dim₊₁,T<:Real}
         if !all(isa.(Ps,AbstractBSplineSpace))
             # TODO: update error message
             error("invalid")
diff --git a/src/_CustomBSplineManifold.jl b/src/_CustomBSplineManifold.jl
index 00e6a5a5..3a5e84e2 100644
--- a/src/_CustomBSplineManifold.jl
+++ b/src/_CustomBSplineManifold.jl
@@ -3,7 +3,7 @@
 struct CustomBSplineManifold{Dim,Deg,C,S<:Tuple} <: AbstractBSplineManifold{Dim,Deg}
     bsplinespaces::S
     controlpoints::Array{C,Dim}
-    function CustomBSplineManifold(Ps::S,a::Array{C,Dim}) where {S<:Tuple,C,Dim}
+    function CustomBSplineManifold(a::Array{C,Dim},Ps::S) where {S<:Tuple,C,Dim}
         if !all(isa.(Ps,AbstractBSplineSpace))
             # TODO: update error message
             error("invalid")
diff --git a/src/_Refinement.jl b/src/_Refinement.jl
index 5ead6b35..e4c6cb0b 100644
--- a/src/_Refinement.jl
+++ b/src/_Refinement.jl
@@ -17,7 +17,7 @@ function refinement(M::BSplineManifold{1}, Ps′::Tuple{<:AbstractBSplineSpace})
     (A1,) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * a[I₁,j] for I₁ in 1:n1) for J₁ in 1:n1′, j in 1:d]
-    return BSplineManifold(Ps′, a′)
+    return BSplineManifold(a′, Ps′)
 end
 function refinement(M::BSplineManifold{2}, Ps′::Tuple{<:AbstractBSplineSpace,<:AbstractBSplineSpace})
     Ps = bsplinespaces(M)
@@ -28,7 +28,7 @@ function refinement(M::BSplineManifold{2}, Ps′::Tuple{<:AbstractBSplineSpace,<
     (A1,A2) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * A2[I₂,J₂] * a[I₁,I₂,j] for I₁ in 1:n1, I₂ in 1:n2) for J₁ in 1:n1′, J₂ in 1:n2′, j in 1:d]
-    return BSplineManifold(Ps′, a′)
+    return BSplineManifold(a′, Ps′)
 end
 function refinement(M::BSplineManifold{3}, Ps′::Tuple{<:AbstractBSplineSpace,<:AbstractBSplineSpace,<:AbstractBSplineSpace})
     Ps = bsplinespaces(M)
@@ -39,7 +39,7 @@ function refinement(M::BSplineManifold{3}, Ps′::Tuple{<:AbstractBSplineSpace,<
     (A1,A2,A3) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * A2[I₂,J₂]* A3[I₃,J₃] * a[I₁,I₂,I₃,j] for I₁ in 1:n1, I₂ in 1:n2, I₃ in 1:n3) for J₁ in 1:n1′, J₂ in 1:n2′, J₃ in 1:n3′, j in 1:d]
-    return BSplineManifold(Ps′, a′)
+    return BSplineManifold(a′, Ps′)
 end
 
 function refinement(M::CustomBSplineManifold{1}, Ps′::Tuple{<:AbstractBSplineSpace})
@@ -50,7 +50,7 @@ function refinement(M::CustomBSplineManifold{1}, Ps′::Tuple{<:AbstractBSplineS
     (A1,) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * a[I₁] for I₁ in 1:n1) for J₁ in 1:n1′]
-    return CustomBSplineManifold(Ps′, a′)
+    return CustomBSplineManifold(a′, Ps′)
 end
 function refinement(M::CustomBSplineManifold{2}, Ps′::Tuple{<:AbstractBSplineSpace,<:AbstractBSplineSpace})
     Ps = bsplinespaces(M)
@@ -60,7 +60,7 @@ function refinement(M::CustomBSplineManifold{2}, Ps′::Tuple{<:AbstractBSplineS
     (A1,A2) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * A2[I₂,J₂] * a[I₁,I₂] for I₁ in 1:n1, I₂ in 1:n2) for J₁ in 1:n1′, J₂ in 1:n2′]
-    return CustomBSplineManifold(Ps′, a′)
+    return CustomBSplineManifold(a′, Ps′)
 end
 function refinement(M::CustomBSplineManifold{3}, Ps′::Tuple{<:AbstractBSplineSpace,<:AbstractBSplineSpace,<:AbstractBSplineSpace})
     Ps = bsplinespaces(M)
@@ -70,7 +70,7 @@ function refinement(M::CustomBSplineManifold{3}, Ps′::Tuple{<:AbstractBSplineS
     (A1,A2,A3) = changebasis.(Ps, Ps′)
 
     a′ = [sum(A1[I₁,J₁] * A2[I₂,J₂] * A3[I₃,J₃] * a[I₁,I₂,I₃] for I₁ in 1:n1, I₂ in 1:n2, I₃ in 1:n3) for J₁ in 1:n1′, J₂ in 1:n2′, J₃ in 1:n3′]
-    return CustomBSplineManifold(Ps′, a′)
+    return CustomBSplineManifold(a′, Ps′)
 end
 
 


Test patch:
diff --git a/test/test_BSplineManifold.jl b/test/test_BSplineManifold.jl
index c88ab1d2..1523154e 100644
--- a/test/test_BSplineManifold.jl
+++ b/test/test_BSplineManifold.jl
@@ -27,7 +27,7 @@
             ax = [i for i in 1:n1]
             ay = [rand() for i in 1:n1]
             a = hcat(ax,ay)  # n1 × 2 array of d̂-dim vector.
-            M = BSplineManifold((P1,), a)
+            M = BSplineManifold(a, (P1,))
             @test dim(M) == 1
 
             P1′ = BSplineSpace{2}(KnotVector([-2, 0, 0, 1, 1, 2]))
@@ -51,7 +51,7 @@
             P1 = BSplineSpace{1}(KnotVector([0, 0, 1, 1]))
             n1 = dim(P1) # 2
             a = [Point(i, rand()) for i in 1:n1]  # n1 × n2 array of d̂-dim vector.
-            M = CustomBSplineManifold((P1,), a)
+            M = CustomBSplineManifold(a, (P1,))
             @test dim(M) == 1
 
             P1′ = BSplineSpace{2}(KnotVector([-2, 0, 0, 1, 1, 2]))
@@ -80,7 +80,7 @@
             n2 = dim(P2) # 3
             rand_a = [rand(2) for i in 1:n1, j in 1:n2]
             a = [[2*i-6.5,2*j-6.5] for i in 1:n1, j in 1:n2] + rand_a
-            M = BSplineManifold((P1, P2), arrayofvector2array(a))
+            M = BSplineManifold(arrayofvector2array(a), (P1, P2))
             @test dim(M) == 2
 
             P1′ = BSplineSpace{2}(KnotVector([-2, 0, 0, 1, 1, 2]))
@@ -108,7 +108,7 @@
             n1 = dim(P1) # 2
             n2 = dim(P2) # 3
             a = [Point(i, j) for i in 1:n1, j in 1:n2]  # n1 × n2 array of d̂-dim vector.
-            M = CustomBSplineManifold((P1, P2), a)
+            M = CustomBSplineManifold(a, (P1, P2))
             @test dim(M) == 2
 
             P1′ = BSplineSpace{2}(KnotVector([0, 0, 0, 1, 1, 1]))
diff --git a/test/test_Fitting.jl b/test/test_Fitting.jl
index cf3f49a8..043f0f6b 100644
--- a/test/test_Fitting.jl
+++ b/test/test_Fitting.jl
@@ -9,7 +9,7 @@
         P1 = BSplineSpace{p1}(k1)
         n1 = dim(P1)
         a_org = [Point(i1, rand()) for i1 in 1:n1]
-        M = CustomBSplineManifold((P1,), a_org)
+        M = CustomBSplineManifold(a_org, (P1,))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
 
@@ -31,7 +31,7 @@
         P1 = BSplineSpace{p1}(k1)
         n1 = dim(P1)
         a_org = [Point(i1, rand()) for i1 in 1:n1]
-        M = CustomBSplineManifold((P1,), a_org)
+        M = CustomBSplineManifold(a_org, (P1,))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
 
@@ -55,7 +55,7 @@
         P2 = BSplineSpace{p2}(k2)
         n2 = dim(P2)
         a_org = [Point(i1, i2, rand()) for i1 in 1:n1, i2 in 1:n2]
-        M = CustomBSplineManifold((P1, P2), a_org)
+        M = CustomBSplineManifold(a_org, (P1, P2))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
         P2′ = expandspace(P2, p₊=1, k₊=KnotVector(rand(2)))
@@ -82,7 +82,7 @@
         P2 = BSplineSpace{p2}(k2)
         n2 = dim(P2)
         a_org = [Point(i1, i2, rand()) for i1 in 1:n1, i2 in 1:n2]
-        M = CustomBSplineManifold((P1, P2), a_org)
+        M = CustomBSplineManifold(a_org, (P1, P2))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
         P2′ = expandspace(P2, p₊=1, k₊=KnotVector(rand(2)))
@@ -110,7 +110,7 @@
         P3 = BSplineSpace{p3}(k3)
         n3 = dim(P3)
         a_org = [Point(i1, i2, i3, rand()) for i1 in 1:n1, i2 in 1:n2, i3 in 1:n3]
-        M = CustomBSplineManifold((P1, P2, P3), a_org)
+        M = CustomBSplineManifold(a_org, (P1, P2, P3))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
         P2′ = expandspace(P2, p₊=1, k₊=KnotVector(rand(2)))
@@ -142,7 +142,7 @@
         P3 = BSplineSpace{p3}(k3)
         n3 = dim(P3)
         a_org = [Point(i1, i2, i3, rand()) for i1 in 1:n1, i2 in 1:n2, i3 in 1:n3]
-        M = CustomBSplineManifold((P1, P2, P3), a_org)
+        M = CustomBSplineManifold(a_org, (P1, P2, P3))
 
         P1′ = expandspace(P1, p₊=1, k₊=KnotVector(rand(2)))
         P2′ = expandspace(P2, p₊=1, k₊=KnotVector(rand(2)))