- if hasattr(x, 'list'):
- # Easy case...
- return x.list()
- else:
- # But what if it's a tuple or something else? This has to
- # handle cartesian products of cartesian products, too; that's
- # why it's recursive.
- return sum( map(_all2list,x), [] )
+ if hasattr(x, 'to_vector'):
+ # This works on matrices of e.g. octonions directly, without
+ # first needing to convert them to a list of octonions and
+ # then recursing down into the list. It also avoids the wonky
+ # list(x) when x is an element of a CFM. I don't know what it
+ # returns but it aint the coordinates. This will fall through
+ # to the iterable case the next time around.
+ return _all2list(x.to_vector())
+
+ try:
+ xl = list(x)
+ except TypeError: # x is not iterable
+ return [x]
+
+ if len(xl) == 1:
+ # Avoid the retardation of list(QQ(1)) == [1].
+ return xl
+
+ return sum(list( map(_all2list, xl) ), [])
+
+