Exemplo n.º 1
0
def transpose(backend,
              wrapping,
              online_backend,
              online_wrapping,
              AdditionalIsFunction=None,
              ConvertAdditionalFunctionTypes=None,
              AdditionalIsVector=None,
              ConvertAdditionalVectorTypes=None,
              AdditionalIsMatrix=None,
              ConvertAdditionalMatrixTypes=None):

    basic_transpose_instance = basic_transpose(
        backend, wrapping, online_backend, online_wrapping,
        AdditionalIsFunction, ConvertAdditionalFunctionTypes,
        AdditionalIsVector, ConvertAdditionalVectorTypes, AdditionalIsMatrix,
        ConvertAdditionalMatrixTypes)

    # Define a functor first, for symmetry with basic implementation
    class _Transpose_Functor(object):
        def __call__(self, arg):
            return _Transpose_Class(arg)

    # Define the actual class which will carry out the multiplication
    class _Transpose_Class(object):
        @overload(
            wrapping.DelayedTransposeWithArithmetic, )
        def __init__(self, arg):
            self.basic_transpose_instance_call = basic_transpose_instance(
                arg.evaluate())

        @overload(
            object, )
        def __init__(self, arg):
            self.basic_transpose_instance_call = basic_transpose_instance(arg)

        @overload(
            wrapping.DelayedTransposeWithArithmetic, )
        def __mul__(self, other):
            return self.basic_transpose_instance_call * other.evaluate()

        @overload(
            object, )
        def __mul__(self, other):
            return self.basic_transpose_instance_call * other

    return _Transpose_Functor()
Exemplo n.º 2
0
#
# RBniCS 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 RBniCS. If not, see <http://www.gnu.org/licenses/>.
#

from rbnics.backends.basic import transpose as basic_transpose
from rbnics.backends.online.numpy.basis_functions_matrix import BasisFunctionsMatrix
from rbnics.backends.online.numpy.function import Function
from rbnics.backends.online.numpy.functions_list import FunctionsList
from rbnics.backends.online.numpy.matrix import Matrix
from rbnics.backends.online.numpy.non_affine_expansion_storage import NonAffineExpansionStorage
from rbnics.backends.online.numpy.tensors_list import TensorsList
from rbnics.backends.online.numpy.vector import Vector
from rbnics.backends.online.numpy.wrapping import function_to_vector, matrix_mul_vector, vector_mul_vector, vectorized_matrix_inner_vectorized_matrix
from rbnics.utils.decorators import backend_for, ModuleWrapper

backend = ModuleWrapper(BasisFunctionsMatrix, Function, FunctionsList, Matrix, NonAffineExpansionStorage, TensorsList, Vector)
wrapping = ModuleWrapper(function_to_vector, matrix_mul_vector, vector_mul_vector, vectorized_matrix_inner_vectorized_matrix)
online_backend = ModuleWrapper(OnlineMatrix=Matrix, OnlineVector=Vector)
online_wrapping = ModuleWrapper()
transpose_base = basic_transpose(backend, wrapping, online_backend, online_wrapping)

@backend_for("numpy", inputs=((BasisFunctionsMatrix, Function.Type(), FunctionsList, TensorsList, Vector.Type()), ))
def transpose(arg):
    return transpose_base(arg)
Exemplo n.º 3
0
def AdditionalIsFunction(arg):
    return isinstance(arg, Operator)


def ConvertAdditionalFunctionTypes(arg):
    assert isinstance(arg, Operator)
    return function_from_ufl_operators(arg)


backend = ModuleWrapper(BasisFunctionsMatrix, evaluate, Function,
                        FunctionsList, Matrix, NonAffineExpansionStorage,
                        ParametrizedTensorFactory, TensorsList, Vector)
wrapping = ModuleWrapper(function_to_vector, matrix_mul_vector,
                         vector_mul_vector,
                         vectorized_matrix_inner_vectorized_matrix)
online_backend = ModuleWrapper(OnlineMatrix=OnlineMatrix,
                               OnlineVector=OnlineVector)
online_wrapping = ModuleWrapper()
transpose_base = basic_transpose(backend, wrapping, online_backend,
                                 online_wrapping, AdditionalIsFunction,
                                 ConvertAdditionalFunctionTypes)


@backend_for("dolfin",
             inputs=((BasisFunctionsMatrix, Function.Type(), FunctionsList,
                      Matrix.Type(), Operator, ParametrizedTensorFactory,
                      TensorsList, Vector.Type()), ))
def transpose(arg):
    return transpose_base(arg)