1
1
import copy
2
+ import warnings
2
3
from typing import Optional , Union , TypeVar , Literal , Sequence , NamedTuple # mypy 1.11, overload
3
4
4
5
import numpy as np
6
+ import numpy .typing as npt
5
7
6
8
from ._typehints import FloatSequence , IntSequence , CrystalFamily , BravaisLattice , NumpyRngSeed
7
9
from . import Rotation
@@ -156,9 +158,8 @@ def __copy__(self: MyType,
156
158
copy = __copy__
157
159
158
160
159
-
160
- def __eq__ (self ,
161
- other : object ) -> bool :
161
+ def __eq__ (self , # type: ignore[override]
162
+ other : object ) -> npt .NDArray [np .bool_ ]:
162
163
"""
163
164
Return self==other.
164
165
@@ -177,8 +178,8 @@ def __eq__(self,
177
178
self .parameters == other .parameters
178
179
return np .logical_and (matching_type ,super (self .__class__ ,self .reduced ).__eq__ (other .reduced ))
179
180
180
- def __ne__ (self ,
181
- other : object ) -> bool :
181
+ def __ne__ (self , # type: ignore[override]
182
+ other : object ) -> npt . NDArray [ np . bool_ ] :
182
183
"""
183
184
Return self!=other.
184
185
@@ -190,14 +191,14 @@ def __ne__(self,
190
191
Orientation to check for equality.
191
192
192
193
"""
193
- return np .logical_not (self == other ) if isinstance ( other , Orientation ) else NotImplemented
194
+ return np .logical_not (self == other )
194
195
195
196
196
197
def isclose (self : MyType ,
197
198
other : MyType ,
198
199
rtol : float = 1e-5 ,
199
200
atol : float = 1e-8 ,
200
- equal_nan : bool = True ) -> bool :
201
+ equal_nan : bool = True ) -> np . ndarray :
201
202
"""
202
203
Report where values are approximately equal to corresponding ones of other Orientation.
203
204
@@ -223,13 +224,11 @@ def isclose(self: MyType,
223
224
self .parameters == other .parameters
224
225
return np .logical_and (matching_type ,super (self .__class__ ,self .reduced ).isclose (other .reduced ))
225
226
226
-
227
-
228
227
def allclose (self : MyType ,
229
228
other : MyType ,
230
229
rtol : float = 1e-5 ,
231
230
atol : float = 1e-8 ,
232
- equal_nan : bool = True ) -> bool :
231
+ equal_nan : bool = True ) -> np . bool_ :
233
232
"""
234
233
Test whether all values are approximately equal to corresponding ones of other Orientation.
235
234
@@ -250,7 +249,7 @@ def allclose(self: MyType,
250
249
Whether all values are close between both orientations.
251
250
252
251
"""
253
- return bool ( np .all (self .isclose (other ,rtol ,atol ,equal_nan ) ))
252
+ return np .all (self .isclose (other ,rtol ,atol ,equal_nan ))
254
253
255
254
256
255
def __mul__ (self : MyType ,
@@ -1359,15 +1358,16 @@ def average(self: MyType,
1359
1358
# mypy 1.11
1360
1359
#@overload
1361
1360
#def to_SST(self, vector: FloatSequence, proper: bool = False, # noqa
1362
- # return_operators : Literal[False] = False) -> np.ndarray: ...
1361
+ # return_operator : Literal[False] = False) -> np.ndarray: ...
1363
1362
#@overload
1364
1363
#def to_SST(self, vector: FloatSequence, proper: bool = False, # noqa
1365
- # return_operators : Literal[True] = True) -> Tuple[np.ndarray,np.ndarray]: ...
1364
+ # return_operator : Literal[True] = True) -> Tuple[np.ndarray,np.ndarray]: ...
1366
1365
def to_SST (self ,
1367
1366
vector : FloatSequence ,
1368
1367
proper : bool = False ,
1368
+ return_operator : bool = False ,
1369
1369
# return_operators: bool = False) -> Union[np.ndarray,Tuple[np.ndarray,np.ndarray]]:
1370
- return_operator : bool = False ) -> Union [np .ndarray , ToSSTTuple ]:
1370
+ return_operators : bool = False ) -> Union [np .ndarray , ToSSTTuple ]:
1371
1371
"""
1372
1372
Rotate lab frame vector to ensure it falls into (improper or proper) standard stereographic triangle of crystal symmetry.
1373
1373
@@ -1392,6 +1392,8 @@ def to_SST(self,
1392
1392
Index of the symmetrically equivalent orientation that rotated vector to SST.
1393
1393
1394
1394
"""
1395
+ if return_operators :
1396
+ warnings .warn ('"return_operators" is deprecated, use "return_operator".' ,DeprecationWarning ,stacklevel = 2 )
1395
1397
vector_ = np .array (vector ,float )
1396
1398
if vector_ .shape [- 1 ] != 3 :
1397
1399
raise ValueError ('input is not a field of three-dimensional vectors' )
@@ -1520,13 +1522,13 @@ def IPF_color(self,
1520
1522
components_improper = np .around (np .einsum ('...ji,...i' ,
1521
1523
np .broadcast_to (self .standard_triangle ['improper' ], vector_ .shape + (3 ,)),
1522
1524
vector_ ), 12 )
1523
- in_SST_ = np .all (components_proper >= 0.0 ,axis = - 1 ) \
1524
- | np .all (components_improper >= 0.0 ,axis = - 1 )
1525
- components = np .where ((in_SST_ & np .all (components_proper >= 0.0 ,axis = - 1 ))[...,np .newaxis ],
1525
+ in_SST_ = np .logical_or ( np . all (components_proper >= 0.0 ,axis = - 1 ),
1526
+ np .all (components_improper >= 0.0 ,axis = - 1 ) )
1527
+ components = np .where ((np . logical_and ( in_SST_ , np .all (components_proper >= 0.0 ,axis = - 1 ) ))[...,np .newaxis ],
1526
1528
components_proper ,components_improper )
1527
1529
else :
1528
1530
components = np .around (np .einsum ('...ji,...i' ,
1529
- np .broadcast_to (self .standard_triangle ['improper' ], vector_ .shape + (3 ,)),
1531
+ np .broadcast_to (self .standard_triangle ['improper' ], vector_ .shape + (3 ,)),
1530
1532
np .block ([vector_ [...,:2 ],np .abs (vector_ [...,2 :3 ])])), 12 )
1531
1533
1532
1534
in_SST_ = np .all (components >= 0.0 ,axis = - 1 )
0 commit comments