Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OperationDefs.hh
Go to the documentation of this file.
1 ///
2 /// @file OperationDefs.hh
3 /// @brief Tensor operations helper functions
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #include <string>
13 #include <type_traits>
14 
15 #include "Hammer/Tools/Loki.hh"
16 #include "Hammer/Exceptions.hh"
18 
19 namespace Hammer {
20 
21  namespace MultiDimensional {
22 
23  class IContainer;
24 
25  template <class Executor>
26  using BinaryDispatch = Loki::StaticDoubleDispatcher<Executor, IContainer, TensorDataTypes, false,
28  template <class Executor>
30 
31  template <class Ops, class TensorPtr>
32  TensorPtr calc2(TensorPtr origin, const IContainer& other, Ops op, std::string opName) {
33  IContainer* result = BinaryDispatch<Ops>::Go(*origin, other, op);
34  if (result == nullptr) {
35  throw Error("Unable to "+opName);
36  }
37  if (result != origin.get()) {
38  origin.reset(result);
39  }
40  return origin;
41  }
42 
43  template <class Ops, class TensorPtr>
44  TensorPtr calc1(TensorPtr origin, Ops op, std::string opName) {
45  IContainer* result = UnaryDispatch<Ops>::Go(*origin, op);
46  if (result == nullptr) {
47  throw Error("Unable to " + opName);
48  }
49  if (result != origin.get()) {
50  origin.reset(result);
51  }
52  return origin;
53  }
54  }
55 }
Loki::StaticDoubleDispatcher< Executor, IContainer, TensorDataTypes, false, const IContainer, ConstTensorDataTypes, IContainer * > BinaryDispatch
Loki::TypeList< VectorContainer, SparseContainer, OuterContainer > TensorDataTypes
Definition: Operations.fhh:25
TensorPtr calc1(TensorPtr origin, Ops op, std::string opName)
Loki::TypeList< const VectorContainer, const SparseContainer, const OuterContainer > ConstTensorDataTypes
Definition: Operations.fhh:26
static ResultType Go(BaseLhs &lhs, Executor &exec)
Definition: Loki.hh:137
TensorPtr calc2(TensorPtr origin, const IContainer &other, Ops op, std::string opName)
Hammer exception definitions.
Generic error class.
Definition: Exceptions.hh:23
static ResultType Go(BaseLhs &lhs, BaseRhs &rhs, Executor &exec)
Definition: Loki.hh:104
Tensor operations forward type declarations.
Double dispatcher code based on examples from A.Alexandrescu&#39;s book.