Tenncor
functor.hpp
Go to the documentation of this file.
1 
9 #include "teq/ifunctor.hpp"
10 
11 #ifndef TEQ_FUNCTOR_HPP
12 #define TEQ_FUNCTOR_HPP
13 
14 namespace teq
15 {
16 
18 struct Functor final : public iFunctor
19 {
21  static Functor* get (Opcode opcode, ArgsT args)
22  {
23  if (0 == args.size())
24  {
25  logs::fatalf("cannot perform `%s` with no arguments",
26  opcode.name_.c_str());
27  }
28 
29  Shape shape = args[0].shape();
30  for (size_t i = 1, n = args.size(); i < n; ++i)
31  {
32  Shape ishape = args[i].shape();
33  if (false == ishape.compatible_after(shape, 0))
34  {
35  logs::fatalf("cannot perform `%s` with incompatible shapes %s "
36  "and %s", opcode.name_.c_str(), shape.to_string().c_str(),
37  ishape.to_string().c_str());
38  }
39  }
40  return new Functor(opcode, shape, args);
41  }
42 
43  static Functor* get (const Functor& other)
44  {
45  return new Functor(other);
46  }
47 
48  static Functor* get (Functor&& other)
49  {
50  return new Functor(std::move(other));
51  }
52 
53  Functor& operator = (const Functor& other) = delete;
54 
55  Functor& operator = (Functor&& other) = delete;
56 
58  const Shape& shape (void) const override
59  {
60  return shape_;
61  }
62 
64  std::string to_string (void) const override
65  {
66  return opcode_.name_;
67  }
68 
70  Opcode get_opcode (void) const override
71  {
72  return opcode_;
73  }
74 
76  const ArgsT& get_children (void) const override
77  {
78  return args_;
79  }
80 
82  void update_child (FuncArg arg, size_t index) override
83  {
84  logs::warn("teq::Functor does not allow editing of children");
85  }
86 
87 private:
89  opcode_(opcode), shape_(shape), args_(args) {}
90 
91  Functor (const Functor& other) = default;
92 
93  Functor (Functor&& other) = default;
94 
97 
100 
103 };
104 
105 }
106 
107 #endif // TEQ_FUNCTOR_HPP
std::string to_string(void) const
Return string representation of shape.
Definition: shape.hpp:148
args
Definition: csv_to_png.py:105
Encoding of operation.
Definition: ifunctor.hpp:18
Interface of iOperation-defined operation node.
Definition: ifunctor.hpp:28
const ArgsT & get_children(void) const override
Implementation of iFunctor.
Definition: functor.hpp:76
std::vector< FuncArg > ArgsT
Type of functor arguments.
Definition: funcarg.hpp:101
Functor(Opcode opcode, Shape shape, ArgsT args)
Definition: functor.hpp:88
Definition: shape.hpp:62
bool compatible_after(const Shape &other, RankT idx) const
Definition: shape.hpp:136
std::string name_
String representation of operation.
Definition: ifunctor.hpp:21
void update_child(FuncArg arg, size_t index) override
Implementation of iFunctor.
Definition: functor.hpp:82
Opcode opcode_
Operation encoding.
Definition: functor.hpp:96
Functor & operator=(const Functor &other)=delete
Coordinate mapper and tensor pair.
Definition: funcarg.hpp:21
const Shape & shape(void) const override
Implementation of iTensor.
Definition: functor.hpp:58
Shape shape_
Shape info built at construction time according to arguments.
Definition: functor.hpp:99
ArgsT args_
Tensor arguments (and children)
Definition: functor.hpp:102
std::string to_string(void) const override
Implementation of iTensor.
Definition: functor.hpp:64
Definition: coord.hpp:16
NElemT index(Shape shape, CoordT coord)
Functor of the graph mapping to operators specified by opcode argument.
Definition: functor.hpp:18
Opcode get_opcode(void) const override
Implementation of iFunctor.
Definition: functor.hpp:70