error setting scalar component X.set_coef(0, 0, value)
The scalar component of a multi-vector can not be set with X.set_coef(igrade=0, ibase, value) for any value of ibase . Reason: The first element of self.Ga.blades or self.Ga.bases is the empty list []. Any index ibase into this empty list will throw an error.
Example code:
x = 1 + a1 + a2 + a1*a2
x.set_coef(0, 0, 42)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/galgebra/mv.py in set_coef(self, igrade, ibase, value)
1174 def set_coef(self, igrade, ibase, value):
1175 if self.blade_rep:
-> 1176 base = self.Ga.blades[igrade][ibase]
1177 else:
1178 base = self.Ga.bases[igrade][ibase]
IndexError: list index out of range
What version are you using? I think I already fixed this.
I am using version ‘0.4.5’ from the repository.
On 15 Jan 2020, at 8:53 am, Eric Wieser [email protected] wrote:
What version are you using? I think I already fixed this.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Darn, well that was worth a try. I'm not really a fan of that function at all, it's the only one that mutates state.
I'll see if I can fix this in the next few days, but I think the API is just poorly designed here
I agree. But if you remove the set_coefs function, what is then the canonical way to create a multivector from an iterable (list, numpy.array etc.) of Sympy expression components?
As an example, assume vector space dimension 2, and given Sympy variables r, s, t, u = symbols(‘r, s, t, u’), I want to define my own coefficients = [r, s, t, u] (or numpy.array([r, s, t, u]) etc.) and then create_base_multivector(coefficients) resulting in a multivector: r + sa1 + ta2 + ua1a2 or create_blade_multivector(coefficients) resulting in a multivector: r + sa1 + ta2 + u*a1^a2 (note the wedge in the last term)
For full metric, those two multivectors are not the same (as you are surely aware) because a1a2 = uQ_12 + a1^a2 (and Q_12 is the inner product of a1 and a2).
what is then the canonical way to create a multivector from an iterable (list, numpy.array etc.) of Sympy expression components?
I've been doing something like:
def vector(ga, components):
basis = ga.mv()
return sum([components[i] * e for i, e in enumerate(basis)])
The above is just for vectors, but the idea applies to multivectors.