/usr/lib/python2.7/dist-packages/ffc/utils.py is in python-ffc 1.6.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # Copyright (C) 2005-2014 Anders Logg
#
# This file is part of FFC.
#
# FFC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Kristian B. Oelgaard, 2009
# Modified by Martin Alnaes 2014
# Python modules.
import operator
import functools
import itertools
# FFC modules.
from .log import error
from ufl.utils.sequences import product
def all_equal(sequence):
"Check that all items in list are equal."
return sequence[:-1] == sequence[1:]
def pick_first(sequence):
"Check that all values are equal and return the value."
if not all_equal(sequence):
error("Values differ: " + str(sequence))
return sequence[0]
def listcopy(sequence):
"""Create a copy of the list, calling the copy constructor on each
object in the list (problems when using copy.deepcopy)."""
if not sequence:
return []
else:
return [object.__class__(object) for object in sequence]
def compute_permutations(k, n, skip = []):
"""Compute all permutations of k elements from (0, n) in rising order.
Any elements that are contained in the list skip are not included."""
if k == 1:
return [(i,) for i in range(n) if not i in skip]
pp = compute_permutations(k - 1, n, skip)
permutations = []
for i in range(n):
if i in skip:
continue
for p in pp:
if i < p[0]:
permutations += [(i, ) + p]
return permutations
|