Skip to content

Iterating over a multivector #116

@willemj-707

Description

@willemj-707

One can iterate over a multivector to get all values in it (e.g. all points in a point cloud), but this only seems to work if the input are already arrays:

import numpy as np
ALGEBRA = Algebra.fromname("3DPGA")
N = 500
x = np.random.random_sample(N)
y = np.random.random_sample(N)
z = np.random.random_sample(N)
pnt = MultiVector(ALGEBRA, e032=x, e013=y, e021=z, e123=np.ones(N))

for p in pnt:
    print(p)  # works fine

For scalar input, I assumed the iteration would just return the scalar input. Instead, a TypeError is raised.

pnt = MultiVector(ALGEBRA, e032=1.5, e013=6.0, e021=-4.0, e123=1.0)

for p in pnt:  # TypeError
    print(p)  

The above example does work if all are converted to np.ndarray first.

x = np.array([1.5])
y = np.array([6.0])
z = np.array([-4.0])
pnt = MultiVector(ALGEBRA, e032=x, e013=y, e021=z, e123=np.array([1.0]))

for p in pnt:
    print(p)  # works fine

For empty input, I would assume the for loop does not iterate at all (like iterating over an empty list). However, this seems to return an infinite loop.

pnt = MultiVector(ALGEBRA)

for p in pnt:
    print(p)  # infinite sequence of 0's.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions