/usr/lib/python2.7/dist-packages/ffc/tensor/tensoroptimization.py is in python-ffc 1.4.0-1.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # Copyright (C) 2010 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/>.
#
# First added: 2010-02-08
# Last changed: 2010-02-08
# Python modules
from numpy import shape
# FFC modules
from ffc.log import warning, info, error
from ffc.utils import product
# Try importing FErari
try:
import ferari
from ferari import binary
except:
ferari = None
def optimize_integral_ir(ir, parameters):
"""
Compute optimized intermediate representation of integral.
Note that this function modifies the given intermediate
representation directly, rather than working on a copy.
"""
# Skip optimization if FErari is not installed
if ferari is None:
warning("FErari not installed, skipping tensor optimizations")
return ir
# Skip optimization if requested
if "no_ferari" in parameters:
warning("Skipping FErari optimizations as requested.")
return ir
# Extract data from intermediate representation
AK = ir["AK"]
integral_type = ir["integral_type"]
num_facets = ir["num_facets"]
rank = ir["rank"]
# Optimize cell integrals
if integral_type == "cell":
for (k, (A0, GK, dummy)) in enumerate(AK):
ir["AK"][k] = (A0, GK, _optimize_tensor_contraction(A0.A0, rank))
# Optimize exterior facet integrals
elif integral_type == "exterior_facet":
for i in range(num_facets):
for (k, (A0, GK, dummy)) in enumerate(AK[i]):
ir["AK"][i][k] = (A0, GK, _optimize_tensor_contraction(A0.A0, rank))
# Optimize interior facet integrals
elif integral_type == "interior_facet":
for i in range(num_facets):
for j in range(num_facets):
for (k, (A0, GK, dummy)) in enumerate(AK[i][j]):
ir["AK"][i][j][k] = (A0, GK, _optimize_tensor_contraction(A0.A0, rank))
# Unhandled integral type
else:
error("Unhandled integral type: " + str(integral_type))
return ir
def _optimize_tensor_contraction(A0, rank):
"Compute optimized tensor contraction for given reference tensor."
# Select FErari optimization algorithm
if rank == 2:
optimize = binary.optimize
elif rank == 1:
optimize = binary.optimize_action
else:
warning("Tensor optimization only available for rank 1 and 2 tensors, skipping optimizations")
return None
# Write a message
info("Calling FErari to optimize tensor of size %s (%d entries)",
" x ".join(str(d) for d in shape(A0)), product(shape(A0)))#
# Compute optimized tensor contraction
return optimize(A0)
|