@@ -61,11 +61,12 @@ def vec_homogeneous(vectors, /, *, w=1, out=None, dtype=None) -> np.ndarray:
61
61
ndarray, [..., 4]
62
62
The list of vectors with appended homogeneous value.
63
63
"""
64
- vectors = np .asarray (vectors )
65
- shape = list (vectors .shape )
66
- shape [- 1 ] += 1
64
+
67
65
if out is None :
68
- out = np .empty_like (vectors , shape = shape , dtype = dtype )
66
+ vectors = np .asarray (vectors )
67
+ shape = list (vectors .shape )
68
+ shape [- 1 ] += 1
69
+ out = np .empty (shape , dtype = dtype )
69
70
out [..., - 1 ] = w
70
71
out [..., :- 1 ] = vectors
71
72
return out
@@ -99,18 +100,19 @@ def vec_transform(vectors, matrix, /, *, w=1, out=None, dtype=None) -> np.ndarra
99
100
transformed vectors
100
101
"""
101
102
102
- vectors = np .asarray (vectors , dtype = float )
103
- matrix = np .asarray (matrix , dtype = float )
103
+ matrix = np .asarray (matrix )
104
104
105
- vectors = vec_homogeneous (vectors , w = w )
105
+ vectors = vec_homogeneous (vectors , w = w , dtype = float )
106
106
result = matrix @ vectors [..., None ]
107
107
result /= result [..., - 1 , :][..., None , :]
108
108
result = result [..., :- 1 , 0 ]
109
109
110
110
if out is not None :
111
111
out [:] = result
112
112
else :
113
- out = result .astype (dtype , copy = False )
113
+ out = result
114
+ if dtype is not None :
115
+ out = out .astype (dtype , copy = False )
114
116
115
117
return out
116
118
@@ -302,7 +304,9 @@ def vec_dist(vector_a, vector_b, /, *, out=None, dtype=None) -> np.ndarray:
302
304
303
305
shape = vector_a .shape [:- 1 ]
304
306
if out is None :
305
- out = np .linalg .norm (vector_a - vector_b , axis = - 1 ).astype (dtype , copy = False )
307
+ out = np .linalg .norm (vector_a - vector_b , axis = - 1 )
308
+ if dtype is not None :
309
+ out = out .astype (dtype , copy = False )
306
310
elif len (shape ) >= 0 :
307
311
out [:] = np .linalg .norm (vector_a - vector_b , axis = - 1 )
308
312
else :
@@ -353,7 +357,9 @@ def vec_angle(vector_a, vector_b, /, *, out=None, dtype=None) -> np.ndarray:
353
357
)
354
358
355
359
if out is None :
356
- out = np .arccos (the_cos ).astype (dtype , copy = False )
360
+ out = np .arccos (the_cos )
361
+ if dtype is not None :
362
+ out = out .astype (dtype , copy = False )
357
363
elif len (shape ) >= 0 :
358
364
out [:] = np .arccos (the_cos )
359
365
else :
@@ -387,12 +393,14 @@ def mat_decompose_translation(
387
393
388
394
"""
389
395
390
- homogeneous_matrix = np .asarray (homogeneous_matrix , dtype = float )
396
+ homogeneous_matrix = np .asarray (homogeneous_matrix )
391
397
392
398
if out is None :
393
- out = np .empty ((* homogeneous_matrix .shape [:- 2 ], 3 ), dtype = dtype )
394
-
395
- out [:] = homogeneous_matrix [..., :- 1 , - 1 ]
399
+ out = homogeneous_matrix [..., :- 1 , - 1 ]
400
+ if dtype is not None :
401
+ out = out .astype (dtype , copy = False )
402
+ else :
403
+ out [:] = homogeneous_matrix [..., :- 1 , - 1 ]
396
404
397
405
return out
398
406
0 commit comments