@@ -105,17 +105,28 @@ def vec_transform(
105
105
transformed vectors
106
106
"""
107
107
108
- matrix = np .asarray (matrix )
108
+ matrix = np .asarray (matrix , dtype = "f8" )
109
109
110
110
if projection :
111
- vectors = vec_homogeneous (vectors , w = w , dtype = float )
112
- vectors @= matrix .T
113
- vectors [..., :- 1 ] /= vectors [..., - 1 , None ]
114
- vectors = vectors [..., :- 1 ]
111
+ vectors = vec_homogeneous (vectors , w = w , dtype = "f8" )
112
+ if vectors .ndim == 1 :
113
+ vectors = matrix @ vectors
114
+ vectors [:- 1 ] /= vectors [- 1 ]
115
+ vectors = vectors [:- 1 ]
116
+ elif vectors .ndim == 2 :
117
+ vectors = (matrix @ vectors .T ).T
118
+ vectors = vectors [..., :- 1 ] / vectors [..., - 1 , None ]
119
+ else :
120
+ raise ValueError ("vectors must be a 1D or 2D array" )
115
121
else :
116
- vectors = np .asarray (vectors , dtype = float , copy = True )
117
- vectors @= matrix [:- 1 , :- 1 ].T
118
- vectors += matrix [:- 1 , - 1 ]
122
+ if vectors .ndim == 1 :
123
+ vectors = matrix [:- 1 , :- 1 ] @ vectors + matrix [:- 1 , - 1 ]
124
+ elif vectors .ndim == 2 :
125
+ vectors = vec_homogeneous (vectors , w = w , dtype = "f8" )
126
+ vectors = (matrix @ vectors .T ).T
127
+ vectors = vectors [..., :- 1 ]
128
+ else :
129
+ raise ValueError ("vectors must be a 1D or 2D array" )
119
130
120
131
if out is None :
121
132
out = vectors
0 commit comments