Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AddAt.cc
Go to the documentation of this file.
1 ///
2 /// @file AddAt.cc
3 /// @brief Sub-tensor block insertion algorithm
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++ -*-
17 #include "Hammer/Exceptions.hh"
18 #include "Hammer/Tools/Utils.hh"
19 #include "Hammer/Math/Utils.hh"
20 
21 using namespace std;
22 
23 namespace Hammer {
24 
25  namespace MultiDimensional {
26 
30  using Base = IContainer;
31 
32  namespace Ops {
33 
34  AddAt::AddAt(IndexType position, IndexType coord) : _position{position}, _coord{coord} {
35 
36  }
37 
39  for (size_t index = 0; index < b.numValues(); ++index) {
40  const PositionType newpos = a.getIndexing().extendPosition(index, _position, _coord);
41  a[newpos] += b[index];
42  }
43  return static_cast<Base*>(&a);
44  }
45 
47  for (auto it = b.begin(); it != b.end(); ++it) {
48  const PositionType newpos = a.getIndexing().extendPosition(b.getIndexing().alignedPosToPos(it->first), _position, _coord);
49  a[newpos] += it->second;
50  }
51  return static_cast<Base*>(&a);
52  }
53 
55  for (auto it = b.begin(); it != b.end(); ++it) {
56  const PositionType newpos =
57  a.getIndexing().extendAlignedPosition(it->first, _position, _coord);
58  a[newpos] += it->second;
59  }
60  return static_cast<Base*>(&a);
61  }
62 
64  auto tmpStride = _position > 0 ? b.getIndexing().stride(static_cast<IndexType>(_position - 1)) : b.getIndexing().numValues();
65  for (size_t index = 0; index < b.numValues(); ++index) {
66  const PositionType newpos = a.getIndexing().extendPosition(index, tmpStride, _position, _coord);
67  a[newpos] += b[index];
68  }
69  return static_cast<Base*>(&a);
70  }
71 
73  return error(a, b);
74  }
75 
77  BruteForceIterator bf{b.dims()};
78  SequentialIndexing seq{b.dims()};
79  for (auto it = bf.begin(); it != bf.end(); ++it) {
80  const PositionType newpos =
81  a.getIndexing().extendPosition(seq.indicesToPos(*it), _position, _coord);
82  a[newpos] += b.value(*it);
83  }
84  return static_cast<Base*>(&a);
85  }
86 
88  BruteForceIterator bf{b.dims()};
89  AlignedIndexing ali{b.dims()};
90  for (auto it = bf.begin(); it != bf.end(); ++it) {
91  const PositionType newpos = a.getIndexing().extendAlignedPosition(ali.indicesToPos(*it), _position, _coord);
92  a[newpos] += b.value(*it);
93  }
94  return static_cast<Base*>(&a);
95  }
96 
97  Base* AddAt::operator()(Base& a, const Base& b) {
98  return error(a, b);
99  }
100 
101  Base* AddAt::error(Base&, const Base&) {
102  throw Error("Invalid data types for tensor AddAt");
103  }
104  } // namespace Ops
105 
106 
107  } // namespace MultiDimensional
108 
109 } // namespace Hammer
IContainer * error(IContainer &, const IContainer &)
Definition: AddAt.cc:101
const LabeledIndexing< SequentialIndexing > & getIndexing() const
const LabeledIndexing< AlignedIndexing > & getIndexing() const
IContainer * operator()(VectorContainer &first, const VectorContainer &second)
Definition: AddAt.cc:38
size_t PositionType
Non-sparse tensor data container.
uint16_t IndexType
Sub-tensor block insertion algorithm.
(Sum of) Outer product tensor data container
Hammer exception definitions.
Sparse tensor data container.
IndexList dims() const override
Generic error class.
Definition: Exceptions.hh:23
Generic tensor indexing iterator.
ElementType value(const IndexList &indices) const