Conversation
tBuLi
left a comment
There was a problem hiding this comment.
Thanks for this PR! Definitelly something we want to have. I just have some comments.
|
|
||
| # Get shapes of all values | ||
| shapes = [] | ||
| for v in self._values: |
There was a problem hiding this comment.
I would prefer a list comprehension, one concept one line.
|
|
||
| # Broadcast each value to the common shape | ||
| broadcasted_values = [] | ||
| for v in self._values: |
|
|
||
| return self.fromkeysvalues(self.algebra, keys=self._keys, values=broadcasted_values) | ||
|
|
||
| def flatten(self): |
There was a problem hiding this comment.
This should still return a multivector. For example, for a multivector of shape (4, N, M) I would expect flatten to return a multivector of shape (4, M*N). Since multivectors are still iterable there is no difference when using flatten for loops but this also still allows you to do GA operatons on it efficiently.
Moreover, the datatype of _values for the new array should be the same of the old one, when possible.
| :return: List of flattened multivectors. | ||
| """ | ||
| mv = self.broadcast() | ||
| return [mv[i] for i in np.ndindex(mv.shape[1:])] |
There was a problem hiding this comment.
I would rename i to indices because i suggests a single int.
Moreover, we can easily add a depth argument to this method, which should default to a full flatten like numpy does:
def flatten(self, depth=-1):
mv = self.broadcast()
return [mv[i] for i in np.ndindex(mv.shape[1:(len(mv.shape) if depth is None else depth+1)])]Also add a test for this, I might have an of by one error :P.
This in addition to the previous comment, so this function will still have to change more.
|
|
||
| def test_flatten(): | ||
| alg = Algebra(4) | ||
| shape = (len(tuple(alg.indices_for_grade(2))), 3, 4) |
There was a problem hiding this comment.
I dn't think you need to cast to tuple to get the right len?
i am not sure the correct way to do this in full generallity, but it was helpful for plotting arrays-of mv's.