← Back to team overview

ffc team mailing list archive

Re: [Branch ~ffc-core/ffc/main] Rev 1765: Some minor Python updates.

 

Note that code such as this:
        if "additional_includes_set" in code:
             s.update(code["additional_includes_set"])

involves two hashmap lookups, so this construct is more efficient:
        tmp = code.get("additional_includes_set")
        if tmp:
             s.update(tmp)

Not sure if "if tmp is not None" is faster than "if tmp".

Martin



On 31 December 2012 16:43, <noreply@xxxxxxxxxxxxx> wrote:

> ------------------------------------------------------------
> revno: 1765
> committer: Garth N. Wells <gnw20@xxxxxxxxx>
> branch nick: ffc
> timestamp: Mon 2012-12-31 15:42:28 +0000
> message:
>   Some minor Python updates.
> modified:
>   ffc/evaluatebasis.py
>   ffc/formatting.py
>   ffc/quadrature/quadraturegenerator.py
>   ffc/quadrature/quadratureutils.py
>
>
> --
> lp:ffc
> https://code.launchpad.net/~ffc-core/ffc/main
>
> Your team FFC Core Team is subscribed to branch lp:ffc.
> To unsubscribe from this branch go to
> https://code.launchpad.net/~ffc-core/ffc/main/+edit-subscription
>
> === modified file 'ffc/evaluatebasis.py'
> --- ffc/evaluatebasis.py        2011-10-14 12:24:42 +0000
> +++ ffc/evaluatebasis.py        2012-12-31 15:42:28 +0000
> @@ -654,7 +654,7 @@
>          code += [f_assign(f_component(f_basisvalue, 0), f_float(1.0))]
>
>          def _idx2d(p, q):
> -            return (p+q)*(p+q+1)/2 + q
> +            return (p + q)*(p + q + 1)//2 + q
>
>          # Only continue if the embedded degree is larger than zero.
>          if embedded_degree > 0:
>
> === modified file 'ffc/formatting.py'
> --- ffc/formatting.py   2011-10-23 21:41:51 +0000
> +++ ffc/formatting.py   2012-12-31 15:42:28 +0000
> @@ -156,7 +156,7 @@
>  def _generate_additional_includes(codes):
>      s = set()
>      for code in codes:
> -        if code.has_key("additional_includes_set"):
> +        if "additional_includes_set" in code:
>              s.update(code["additional_includes_set"])
>      if s:
>          return "\n".join(list(s)) + "\n"
>
> === modified file 'ffc/quadrature/quadraturegenerator.py'
> --- ffc/quadrature/quadraturegenerator.py       2011-11-28 14:18:37 +0000
> +++ ffc/quadrature/quadraturegenerator.py       2012-12-31 15:42:28 +0000
> @@ -23,6 +23,7 @@
>  # Last changed: 2011-11-28
>
>  # Python modules.
> +import functools
>  import numpy
>
>  # UFL modules.
> @@ -178,7 +179,7 @@
>      if prim_idims == []:
>          common += [f_assign(f_A(f_int(0)), f_float(0))]
>      else:
> -        dim = reduce(lambda v,u: v*u, prim_idims)
> +        dim = functools.reduce(lambda v,u: v*u, prim_idims)
>          common += f_loop([f_assign(f_A(f_r), f_float(0))], [(f_r, 0,
> dim)])
>
>      # Create the constant geometry declarations (only generated if
> simplify expressions are enabled).
> @@ -426,7 +427,7 @@
>      # Write all the loops of basis functions.
>      for loop, ops_lines in loops.items():
>          ops, lines = ops_lines
> -        prim_ops = reduce(lambda i, j: i*j, [ops] + [l[2] for l in loop])
> +        prim_ops = functools.reduce(lambda i, j: i*j, [ops] + [l[2] for l
> in loop])
>          # Add number of operations for current loop to total count.
>          num_ops += prim_ops
>          code += ["", f_comment("Number of operations for primary indices:
> %d" % prim_ops)]
>
> === modified file 'ffc/quadrature/quadratureutils.py'
> --- ffc/quadrature/quadratureutils.py   2011-06-02 19:41:46 +0000
> +++ ffc/quadrature/quadratureutils.py   2012-12-31 15:42:28 +0000
> @@ -63,7 +63,7 @@
>          elem_dict = tables[point]
>          element_map[point] = {}
>          # Loop all elements and get all their tables.
> -        for elem in sorted(elem_dict.keys(), lambda x, y: cmp(str(x),
> str(y))):
> +        for elem in sorted(elem_dict.keys(), key=lambda x: str(x)):
>              facet_tables = elem_dict[elem]
>              element_map[point][elem] = counter
>              for facet in sorted(facet_tables.keys()):
>
>
>