@@ -882,6 +882,7 @@ def test_as_euler_degenerate_compare_algorithms(seq_tuple, intrinsic):
882
882
def test_inv ():
883
883
rnd = np .random .RandomState (0 )
884
884
n = 10
885
+ # preserve use of old random_state during SPEC 7 transition
885
886
p = Rotation .random (num = n , random_state = rnd )
886
887
q = p .inv ()
887
888
@@ -898,8 +899,8 @@ def test_inv():
898
899
899
900
900
901
def test_inv_single_rotation ():
901
- rnd = np .random .RandomState ( 0 )
902
- p = Rotation .random (random_state = rnd )
902
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
903
+ p = Rotation .random (rng = rng )
903
904
q = p .inv ()
904
905
905
906
p_mat = p .as_matrix ()
@@ -912,7 +913,7 @@ def test_inv_single_rotation():
912
913
assert_array_almost_equal (res1 , eye )
913
914
assert_array_almost_equal (res2 , eye )
914
915
915
- x = Rotation .random (num = 1 , random_state = rnd )
916
+ x = Rotation .random (num = 1 , rng = rng )
916
917
y = x .inv ()
917
918
918
919
x_matrix = x .as_matrix ()
@@ -940,7 +941,7 @@ def test_single_identity_magnitude():
940
941
941
942
def test_identity_invariance ():
942
943
n = 10
943
- p = Rotation .random (n , random_state = 0 )
944
+ p = Rotation .random (n , rng = 0 )
944
945
945
946
result = p * Rotation .identity (n )
946
947
assert_array_almost_equal (p .as_quat (), result .as_quat ())
@@ -951,7 +952,7 @@ def test_identity_invariance():
951
952
952
953
def test_single_identity_invariance ():
953
954
n = 10
954
- p = Rotation .random (n , random_state = 0 )
955
+ p = Rotation .random (n , rng = 0 )
955
956
956
957
result = p * Rotation .identity ()
957
958
assert_array_almost_equal (p .as_quat (), result .as_quat ())
@@ -980,9 +981,9 @@ def test_magnitude_single_rotation():
980
981
981
982
982
983
def test_approx_equal ():
983
- rng = np .random .RandomState ( 0 )
984
- p = Rotation .random (10 , random_state = rng )
985
- q = Rotation .random (10 , random_state = rng )
984
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
985
+ p = Rotation .random (10 , rng = rng )
986
+ q = Rotation .random (10 , rng = rng )
986
987
r = p * q .inv ()
987
988
r_mag = r .magnitude ()
988
989
atol = np .median (r_mag ) # ensure we get mix of Trues and Falses
@@ -1046,10 +1047,10 @@ def test_reduction_none_indices():
1046
1047
1047
1048
1048
1049
def test_reduction_scalar_calculation ():
1049
- rng = np .random .RandomState ( 0 )
1050
- l = Rotation .random (5 , random_state = rng )
1051
- r = Rotation .random (10 , random_state = rng )
1052
- p = Rotation .random (7 , random_state = rng )
1050
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
1051
+ l = Rotation .random (5 , rng = rng )
1052
+ r = Rotation .random (10 , rng = rng )
1053
+ p = Rotation .random (7 , rng = rng )
1053
1054
reduced , left_best , right_best = p .reduce (l , r , return_indices = True )
1054
1055
1055
1056
# Loop implementation of the vectorized calculation in Rotation.reduce
@@ -1201,23 +1202,23 @@ def test_setitem_single():
1201
1202
1202
1203
1203
1204
def test_setitem_slice ():
1204
- rng = np .random .RandomState ( seed = 0 )
1205
- r1 = Rotation .random (10 , random_state = rng )
1206
- r2 = Rotation .random (5 , random_state = rng )
1205
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
1206
+ r1 = Rotation .random (10 , rng = rng )
1207
+ r2 = Rotation .random (5 , rng = rng )
1207
1208
r1 [1 :6 ] = r2
1208
1209
assert_equal (r1 [1 :6 ].as_quat (), r2 .as_quat ())
1209
1210
1210
1211
1211
1212
def test_setitem_integer ():
1212
- rng = np .random .RandomState ( seed = 0 )
1213
- r1 = Rotation .random (10 , random_state = rng )
1214
- r2 = Rotation .random (random_state = rng )
1213
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
1214
+ r1 = Rotation .random (10 , rng = rng )
1215
+ r2 = Rotation .random (rng = rng )
1215
1216
r1 [1 ] = r2
1216
1217
assert_equal (r1 [1 ].as_quat (), r2 .as_quat ())
1217
1218
1218
1219
1219
1220
def test_setitem_wrong_type ():
1220
- r = Rotation .random (10 , random_state = 0 )
1221
+ r = Rotation .random (10 , rng = 0 )
1221
1222
with pytest .raises (TypeError , match = 'Rotation object' ):
1222
1223
r [0 ] = 1
1223
1224
@@ -1241,12 +1242,12 @@ def test_n_rotations():
1241
1242
1242
1243
1243
1244
def test_random_rotation_shape ():
1244
- rnd = np .random .RandomState ( 0 )
1245
- assert_equal (Rotation .random (random_state = rnd ).as_quat ().shape , (4 ,))
1246
- assert_equal (Rotation .random (None , random_state = rnd ).as_quat ().shape , (4 ,))
1245
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
1246
+ assert_equal (Rotation .random (rng = rng ).as_quat ().shape , (4 ,))
1247
+ assert_equal (Rotation .random (None , rng = rng ).as_quat ().shape , (4 ,))
1247
1248
1248
- assert_equal (Rotation .random (1 , random_state = rnd ).as_quat ().shape , (1 , 4 ))
1249
- assert_equal (Rotation .random (5 , random_state = rnd ).as_quat ().shape , (5 , 4 ))
1249
+ assert_equal (Rotation .random (1 , rng = rng ).as_quat ().shape , (1 , 4 ))
1250
+ assert_equal (Rotation .random (5 , rng = rng ).as_quat ().shape , (5 , 4 ))
1250
1251
1251
1252
1252
1253
def test_align_vectors_no_rotation ():
@@ -1259,9 +1260,9 @@ def test_align_vectors_no_rotation():
1259
1260
1260
1261
1261
1262
def test_align_vectors_no_noise ():
1262
- rnd = np .random .RandomState ( 0 )
1263
- c = Rotation .random (random_state = rnd )
1264
- b = rnd .normal (size = (5 , 3 ))
1263
+ rng = np .random .default_rng ( 14697284569885399755764481408308808739 )
1264
+ c = Rotation .random (rng = rng )
1265
+ b = rng .normal (size = (5 , 3 ))
1265
1266
a = c .apply (b )
1266
1267
1267
1268
est , rssd = Rotation .align_vectors (a , b )
@@ -1296,8 +1297,8 @@ def test_align_vectors_rssd_sensitivity():
1296
1297
1297
1298
def test_align_vectors_scaled_weights ():
1298
1299
n = 10
1299
- a = Rotation .random (n , random_state = 0 ).apply ([1 , 0 , 0 ])
1300
- b = Rotation .random (n , random_state = 1 ).apply ([1 , 0 , 0 ])
1300
+ a = Rotation .random (n , rng = 0 ).apply ([1 , 0 , 0 ])
1301
+ b = Rotation .random (n , rng = 1 ).apply ([1 , 0 , 0 ])
1301
1302
scale = 2
1302
1303
1303
1304
est1 , rssd1 , cov1 = Rotation .align_vectors (a , b , np .ones (n ), True )
@@ -1309,17 +1310,17 @@ def test_align_vectors_scaled_weights():
1309
1310
1310
1311
1311
1312
def test_align_vectors_noise ():
1312
- rnd = np .random .RandomState ( 0 )
1313
+ rng = np .random .default_rng ( 146972845698875399755764481408308808739 )
1313
1314
n_vectors = 100
1314
- rot = Rotation .random (random_state = rnd )
1315
- vectors = rnd .normal (size = (n_vectors , 3 ))
1315
+ rot = Rotation .random (rng = rng )
1316
+ vectors = rng .normal (size = (n_vectors , 3 ))
1316
1317
result = rot .apply (vectors )
1317
1318
1318
1319
# The paper adds noise as independently distributed angular errors
1319
1320
sigma = np .deg2rad (1 )
1320
1321
tolerance = 1.5 * sigma
1321
1322
noise = Rotation .from_rotvec (
1322
- rnd .normal (
1323
+ rng .normal (
1323
1324
size = (n_vectors , 3 ),
1324
1325
scale = sigma
1325
1326
)
@@ -1433,7 +1434,7 @@ def test_align_vectors_near_inf():
1433
1434
n = 100
1434
1435
mats = []
1435
1436
for i in range (6 ):
1436
- mats .append (Rotation .random (n , random_state = 10 + i ).as_matrix ())
1437
+ mats .append (Rotation .random (n , rng = 10 + i ).as_matrix ())
1437
1438
1438
1439
for i in range (n ):
1439
1440
# Get random pairs of 3-element vectors
@@ -1491,7 +1492,7 @@ def test_align_vectors_antiparallel():
1491
1492
assert_allclose (R .apply (b [0 ]), a [0 ], atol = atol )
1492
1493
1493
1494
# Test exact rotations near 180 deg
1494
- Rs = Rotation .random (100 , random_state = 0 )
1495
+ Rs = Rotation .random (100 , rng = 0 )
1495
1496
dRs = Rotation .from_rotvec (Rs .as_rotvec ()* 1e-4 ) # scale down to small angle
1496
1497
a = [[ 1 , 0 , 0 ], [0 , 1 , 0 ]]
1497
1498
b = [[- 1 , 0 , 0 ], [0 , 1 , 0 ]]
@@ -1506,8 +1507,8 @@ def test_align_vectors_antiparallel():
1506
1507
1507
1508
def test_align_vectors_primary_only ():
1508
1509
atol = 1e-12
1509
- mats_a = Rotation .random (100 , random_state = 0 ).as_matrix ()
1510
- mats_b = Rotation .random (100 , random_state = 1 ).as_matrix ()
1510
+ mats_a = Rotation .random (100 , rng = 0 ).as_matrix ()
1511
+ mats_b = Rotation .random (100 , rng = 1 ).as_matrix ()
1511
1512
for mat_a , mat_b in zip (mats_a , mats_b ):
1512
1513
# Get random 3-element unit vectors
1513
1514
a = mat_a [0 ]
@@ -1658,16 +1659,16 @@ def test_slerp_call_scalar_time():
1658
1659
1659
1660
1660
1661
def test_multiplication_stability ():
1661
- qs = Rotation .random (50 , random_state = 0 )
1662
- rs = Rotation .random (1000 , random_state = 1 )
1662
+ qs = Rotation .random (50 , rng = 0 )
1663
+ rs = Rotation .random (1000 , rng = 1 )
1663
1664
for q in qs :
1664
1665
rs *= q * rs
1665
1666
assert_allclose (np .linalg .norm (rs .as_quat (), axis = 1 ), 1 )
1666
1667
1667
1668
1668
1669
def test_pow ():
1669
1670
atol = 1e-14
1670
- p = Rotation .random (10 , random_state = 0 )
1671
+ p = Rotation .random (10 , rng = 0 )
1671
1672
p_inv = p .inv ()
1672
1673
# Test the short-cuts and other integers
1673
1674
for n in [- 5 , - 2 , - 1 , 0 , 1 , 2 , 5 ]:
@@ -1703,14 +1704,14 @@ def test_pow():
1703
1704
1704
1705
1705
1706
def test_pow_errors ():
1706
- p = Rotation .random (random_state = 0 )
1707
+ p = Rotation .random (rng = 0 )
1707
1708
with pytest .raises (NotImplementedError , match = 'modulus not supported' ):
1708
1709
pow (p , 1 , 1 )
1709
1710
1710
1711
1711
1712
def test_rotation_within_numpy_array ():
1712
- single = Rotation .random (random_state = 0 )
1713
- multiple = Rotation .random (2 , random_state = 1 )
1713
+ single = Rotation .random (rng = 0 )
1714
+ multiple = Rotation .random (2 , rng = 1 )
1714
1715
1715
1716
array = np .array (single )
1716
1717
assert_equal (array .shape , ())
@@ -1762,7 +1763,7 @@ def test_as_euler_contiguous():
1762
1763
1763
1764
1764
1765
def test_concatenate ():
1765
- rotation = Rotation .random (10 , random_state = 0 )
1766
+ rotation = Rotation .random (10 , rng = 0 )
1766
1767
sizes = [1 , 2 , 3 , 1 , 3 ]
1767
1768
starts = [0 ] + list (np .cumsum (sizes ))
1768
1769
split = [rotation [i :i + n ] for i , n in zip (starts , sizes )]
0 commit comments