sum([list-of-forms]) doesn't work
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
UFL |
Fix Released
|
Low
|
Martin Sandve Alnæs |
Bug Description
=======
from dolfin import *
mesh = UnitInterval(10)
V = FunctionSpace(mesh, "CG", 1)
M = MixedFunctionSp
tests = TestFunctions(M)
trials = TrialFunctions(M)
a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
=======
fails with:
Traceback (most recent call last):
File "sum-of-forms.py", line 9, in <module>
a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
TypeError: unsupported operand type(s) for +: 'int' and 'Form'
This is because the Python sum() command starts with the integer 0 by default, and 0 + Form is not defined. It does take an optional start argument, but there's no "empty Form" that would make the command work.
Could some SWIG magician please make the __add__ of Forms allow for the addition of 0 onto a Form?
Changed in dolfin: | |
assignee: | nobody → Martin Sandve Alnæs (martinal) |
status: | New → Fix Committed |
affects: | dolfin → ufl |
Changed in ufl: | |
importance: | Undecided → Low |
milestone: | none → 1.1.0-alpha |
Changed in ufl: | |
status: | Fix Committed → Fix Released |
I would like to see that as well.
If you're in need of a fix I currently do:
======= ======= ======= ======= ==
from dolfin import *
import operator
mesh = UnitInterval(10) ace([V, V, V])
V = FunctionSpace(mesh, "CG", 1)
M = MixedFunctionSp
tests = TestFunctions(M) operator. add, [inner(test, trial)*dx for (test, trial) in zip(tests, trials)]) ======= ======= ======= ===
trials = TrialFunctions(M)
a = reduce(
=======
which works, but is not as pretty as sum.
Best regards
Mikael
Den Oct 2, 2012 kl. 8:18 PM skrev Patrick Farrell:
> Public bug reported: ======= ======= ======= ======= ======= ======= = ace([V, V, V]) ======= ======= ======= ======= ======= ======= = /bugs.launchpad .net/bugs/ 1060380 of-forms] ) doesn't work ======= ======= ======= ======= ======= ======= = ace([V, V, V]) ======= ======= ======= ======= ======= ======= = /bugs.launchpad .net/dolfin/ +bug/1060380/ +subscriptions
>
> =======
> from dolfin import *
>
> mesh = UnitInterval(10)
> V = FunctionSpace(mesh, "CG", 1)
> M = MixedFunctionSp
>
> tests = TestFunctions(M)
> trials = TrialFunctions(M)
> a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
> =======
>
> fails with:
>
> Traceback (most recent call last):
> File "sum-of-forms.py", line 9, in <module>
> a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
> TypeError: unsupported operand type(s) for +: 'int' and 'Form'
>
> This is because the Python sum() command starts with the integer 0 by
> default, and 0 + Form is not defined. It does take an optional start
> argument, but there's no "empty Form" that would make the command work.
>
> Could some SWIG magician please make the __add__ of Forms allow for the
> addition of 0 onto a Form?
>
> ** Affects: dolfin
> Importance: Undecided
> Status: New
>
> --
> You received this bug notification because you are a member of DOLFIN
> Team, which is subscribed to DOLFIN.
> https:/
>
> Title:
> sum([list-
>
> Status in DOLFIN:
> New
>
> Bug description:
> =======
> from dolfin import *
>
> mesh = UnitInterval(10)
> V = FunctionSpace(mesh, "CG", 1)
> M = MixedFunctionSp
>
> tests = TestFunctions(M)
> trials = TrialFunctions(M)
> a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
> =======
>
> fails with:
>
> Traceback (most recent call last):
> File "sum-of-forms.py", line 9, in <module>
> a = sum([inner(test, trial)*dx for (test, trial) in zip(tests, trials)])
> TypeError: unsupported operand type(s) for +: 'int' and 'Form'
>
> This is because the Python sum() command starts with the integer 0 by
> default, and 0 + Form is not defined. It does take an optional start
> argument, but there's no "empty Form" that would make the command
> work.
>
> Could some SWIG magician please make the __add__ of Forms allow for
> the addition of 0 onto a Form?
>
> To manage notifications about this bug go to:
> https:/