1212
1313_numtypes = (int , np .int64 , float , np .float64 )
1414
15+
1516class BasePoseList (UserList , ABC ):
1617 """
1718 List properties for spatial math classes
1819
1920 Each of the spatial math classes behaves like a regular Python object and
20- an instance contains a value of a particular type, for example an SE(3)
21+ an instance contains a value of a particular type, for example an SE(3)
2122 matrix, a unit quaternion, a twist etc.
2223
2324 This class adds list-like capabilities to each of spatial math classes. This
24- means that an instance is not limited to holding just a single value (a
25- singleton instance), it can hold a list of values. That list can contain
25+ means that an instance is not limited to holding just a single value (a
26+ singleton instance), it can hold a list of values. That list can contain
2627 zero or more items. This is helpful for:
27-
28+
2829 - storing sequences (trajectories) where it is important to know that all
2930 elements in the sequence are of the same time and have valid values
3031 - arrays of the same type to enable C++ like programming patterns
@@ -86,7 +87,7 @@ def _import(self, x, check=True):
8687 def Empty (cls ):
8788 """
8889 Construct an empty instance (BasePoseList superclass method)
89-
90+
9091 :return: pose instance with zero values
9192
9293 Example::
@@ -117,7 +118,7 @@ def Alloc(cls, n=1):
117118 can be referenced ``X[i]`` or assigned to ``X[i] = ...``.
118119
119120 .. note:: The default value depends on the pose class and is the result
120- of the empty constructor. For ``SO2``,
121+ of the empty constructor. For ``SO2``,
121122 ``SE2``, ``SO3``, ``SE3`` it is an identity matrix, for a
122123 twist class ``Twist2`` or ``Twist3`` it is a zero vector,
123124 for a ``UnitQuaternion`` or ``Quaternion`` it is a zero
@@ -195,10 +196,16 @@ def arghandler(self, arg, convertfrom=(), check=True):
195196
196197 elif type (arg [0 ]) == type (self ):
197198 # possibly a list of objects of same type
198- assert all (map (lambda x : type (x ) == type (self ), arg )), 'elements of list are incorrect type'
199+ assert all (
200+ map (lambda x : type (x ) == type (self ), arg )
201+ ), "elements of list are incorrect type"
199202 self .data = [x .A for x in arg ]
200203
201- elif argcheck .isnumberlist (arg ) and len (self .shape ) == 1 and len (arg ) == self .shape [0 ]:
204+ elif (
205+ argcheck .isnumberlist (arg )
206+ and len (self .shape ) == 1
207+ and len (arg ) == self .shape [0 ]
208+ ):
202209 self .data = [np .array (arg )]
203210
204211 else :
@@ -215,7 +222,9 @@ def arghandler(self, arg, convertfrom=(), check=True):
215222 # get method to convert from arg to self types
216223 converter = getattr (arg .__class__ , type (self ).__name__ )
217224 except AttributeError :
218- raise ValueError ('argument has no conversion method to this type' ) from None
225+ raise ValueError (
226+ "argument has no conversion method to this type"
227+ ) from None
219228 self .data = [converter (arg ).A ]
220229
221230 else :
@@ -245,11 +254,11 @@ def A(self):
245254 :return: NumPy array value of this instance
246255 :rtype: ndarray
247256
248- - ``X.A`` is a NumPy array that represents the value of this instance,
257+ - ``X.A`` is a NumPy array that represents the value of this instance,
249258 and has a shape given by ``X.shape``.
250259
251260 .. note:: This assumes that ``len(X)`` == 1, ie. it is a single-valued
252- instance.
261+ instance.
253262 """
254263
255264 if len (self .data ) == 1 :
@@ -270,9 +279,9 @@ def __getitem__(self, i):
270279 :raises IndexError: if the element is out of bounds
271280
272281 Note that only a single index is supported, slices are not.
273-
282+
274283 Example::
275-
284+
276285 >>> x = X.Alloc(10)
277286 >>> len(x)
278287 10
@@ -296,14 +305,19 @@ def __getitem__(self, i):
296305 else :
297306 # stop is positive, use it directly
298307 end = i .stop
299- return self .__class__ ([self .data [k ] for k in range (i .start or 0 , end , i .step or 1 )])
308+ return self .__class__ (
309+ [self .data [k ] for k in range (i .start or 0 , end , i .step or 1 )]
310+ )
300311 else :
301- return self .__class__ (self .data [i ], check = False )
302-
312+ ret = self .__class__ (self .data [i ], check = False )
313+ # ret.__array_interface__ = self.data[i].__array_interface__
314+ return ret
315+ # return self.__class__(self.data[i], check=False)
316+
303317 def __setitem__ (self , i , value ):
304318 """
305319 Assign a value to an instance (BasePoseList superclass method)
306-
320+
307321 :param i: index of element to assign to
308322 :type i: int
309323 :param value: the value to insert
@@ -312,7 +326,7 @@ def __setitem__(self, i, value):
312326
313327 Assign the argument to an element of the object's internal list of values.
314328 This supports the assignement operator, for example::
315-
329+
316330 >>> x = X.Alloc(10)
317331 >>> len(x)
318332 10
@@ -324,7 +338,9 @@ def __setitem__(self, i, value):
324338 if not type (self ) == type (value ):
325339 raise ValueError ("can't insert different type of object" )
326340 if len (value ) > 1 :
327- raise ValueError ("can't insert a multivalued element - must have len() == 1" )
341+ raise ValueError (
342+ "can't insert a multivalued element - must have len() == 1"
343+ )
328344 self .data [i ] = value .A
329345
330346 # flag these binary operators as being not supported
@@ -343,7 +359,7 @@ def __ge__(self, other):
343359 def append (self , item ):
344360 """
345361 Append a value to an instance (BasePoseList superclass method)
346-
362+
347363 :param x: the value to append
348364 :type x: Quaternion or UnitQuaternion instance
349365 :raises ValueError: incorrect type of appended object
@@ -361,18 +377,17 @@ def append(self, item):
361377
362378 where ``X`` is any of the SMTB classes.
363379 """
364- #print('in append method')
380+ # print('in append method')
365381 if not type (self ) == type (item ):
366382 raise ValueError ("can't append different type of object" )
367383 if len (item ) > 1 :
368384 raise ValueError ("can't append a multivalued instance - use extend" )
369385 super ().append (item .A )
370-
371386
372387 def extend (self , iterable ):
373388 """
374389 Extend sequence of values in an instance (BasePoseList superclass method)
375-
390+
376391 :param x: the value to extend
377392 :type x: instance of same type
378393 :raises ValueError: incorrect type of appended object
@@ -390,7 +405,7 @@ def extend(self, iterable):
390405
391406 where ``X`` is any of the SMTB classes.
392407 """
393- #print('in extend method')
408+ # print('in extend method')
394409 if not type (self ) == type (iterable ):
395410 raise ValueError ("can't append different type of object" )
396411 super ().extend (iterable ._A )
@@ -427,9 +442,11 @@ def insert(self, i, item):
427442 if not type (self ) == type (item ):
428443 raise ValueError ("can't insert different type of object" )
429444 if len (item ) > 1 :
430- raise ValueError ("can't insert a multivalued instance - must have len() == 1" )
445+ raise ValueError (
446+ "can't insert a multivalued instance - must have len() == 1"
447+ )
431448 super ().insert (i , item ._A )
432-
449+
433450 def pop (self , i = - 1 ):
434451 """
435452 Pop value from an instance (BasePoseList superclass method)
@@ -442,7 +459,7 @@ def pop(self, i=-1):
442459
443460 Removes a value from the value list and returns it. The original
444461 instance is modified.
445-
462+
446463 Example::
447464
448465 >>> x = X.Alloc(10)
@@ -462,7 +479,7 @@ def pop(self, i=-1):
462479 def binop (self , right , op , op2 = None , list1 = True ):
463480 """
464481 Perform binary operation
465-
482+
466483 :param left: left operand
467484 :type left: BasePoseList subclass
468485 :param right: right operand
@@ -523,7 +540,7 @@ def binop(self, right, op, op2=None, list1=True):
523540
524541 # class * class
525542 if len (left ) == 1 :
526- # singleton *
543+ # singleton *
527544 if argcheck .isscalar (right ):
528545 if list1 :
529546 return [op (left ._A , right )]
@@ -539,7 +556,7 @@ def binop(self, right, op, op2=None, list1=True):
539556 # singleton * non-singleton
540557 return [op (left .A , x ) for x in right .A ]
541558 else :
542- # non-singleton *
559+ # non-singleton *
543560 if argcheck .isscalar (right ):
544561 return [op (x , right ) for x in left .A ]
545562 elif len (right ) == 1 :
@@ -549,12 +566,12 @@ def binop(self, right, op, op2=None, list1=True):
549566 # non-singleton * non-singleton
550567 return [op (x , y ) for (x , y ) in zip (left .A , right .A )]
551568 else :
552- raise ValueError (' length of lists to == must be same length' )
569+ raise ValueError (" length of lists to == must be same length" )
553570
554571 # if isinstance(right, left.__class__):
555572 # # class * class
556573 # if len(left) == 1:
557- # # singleton *
574+ # # singleton *
558575 # if len(right) == 1:
559576 # # singleton * singleton
560577 # if list1:
@@ -565,7 +582,7 @@ def binop(self, right, op, op2=None, list1=True):
565582 # # singleton * non-singleton
566583 # return [op(left.A, x) for x in right.A]
567584 # else:
568- # # non-singleton *
585+ # # non-singleton *
569586 # if len(right) == 1:
570587 # # non-singleton * singleton
571588 # return [op(x, right.A) for x in left.A]
@@ -587,7 +604,7 @@ def binop(self, right, op, op2=None, list1=True):
587604 def unop (self , op , matrix = False ):
588605 """
589606 Perform unary operation
590-
607+
591608 :param self: operand
592609 :type self: BasePoseList subclass
593610 :param op: unnary operation
@@ -598,7 +615,7 @@ def unop(self, op, matrix=False):
598615 :rtype: list or NumPy array
599616
600617 The is a helper method for implementing unary operations where the
601- operand has multiple value. This method computes the value of
618+ operand has multiple value. This method computes the value of
602619 the operation for all input values and returns the result as either
603620 a list or as a matrix which vertically stacks the results.
604621
@@ -613,7 +630,7 @@ def unop(self, op, matrix=False):
613630 ========= ==== ===================================
614631
615632 The result is:
616-
633+
617634 - a list of values if ``matrix==False``, or
618635 - a 2D NumPy stack of values if ``matrix==True``, it is assumed
619636 that the value is a 1D array.
@@ -623,4 +640,3 @@ def unop(self, op, matrix=False):
623640 return np .vstack ([op (x ) for x in self .data ])
624641 else :
625642 return [op (x ) for x in self .data ]
626-
0 commit comments