Tenncor
funcarg.hpp
Go to the documentation of this file.
1 
9 #include "teq/itensor.hpp"
10 #include "teq/coord.hpp"
11 
12 #ifndef TEQ_FUNCARG_HPP
13 #define TEQ_FUNCARG_HPP
14 
15 namespace teq
16 {
17 
18 Shape apply_shaper (const CoordptrT& shaper, Shape inshape);
19 
21 struct FuncArg final
22 {
24  FuncArg (TensptrT tensor, CoordptrT shaper) :
25  tensor_(tensor), shaper_(shaper)
26  {
27  if (tensor_ == nullptr)
28  {
29  logs::fatal("cannot map a null tensor");
30  }
31  map_io_ = tensor_->shape().n_elems() > shape().n_elems();
32  if (shaper == identity || map_io_)
33  {
34  coorder_ = shaper;
35  }
36  else
37  {
38  coorder_ = CoordptrT(shaper->reverse());
39  }
40  }
41 
43  FuncArg (TensptrT tensor, CoordptrT shaper,
44  bool map_io, CoordptrT coorder) :
45  tensor_(tensor), shaper_(shaper),
46  map_io_(map_io), coorder_(coorder)
47  {
48  if (tensor_ == nullptr)
49  {
50  logs::fatal("cannot map a null tensor");
51  }
52  }
53 
55  Shape shape (void) const
56  {
57  return apply_shaper(shaper_, tensor_->shape());
58  }
59 
61  TensptrT get_tensor (void) const
62  {
63  return tensor_;
64  }
65 
67  CoordptrT get_shaper (void) const
68  {
69  return shaper_;
70  }
71 
74  bool map_io (void) const
75  {
76  return map_io_;
77  }
78 
80  CoordptrT get_coorder (void) const
81  {
82  return coorder_;
83  }
84 
85 private:
88 
91 
94  bool map_io_;
95 
98 };
99 
101 using ArgsT = std::vector<FuncArg>;
102 
104 FuncArg identity_map (TensptrT tensor);
105 
109 FuncArg reduce_1d_map (TensptrT tensor, RankT rank);
110 
115 FuncArg reduce_map (TensptrT tensor,
116  RankT rank, std::vector<DimT> red);
117 
122 FuncArg extend_map (TensptrT tensor,
123  RankT rank, std::vector<DimT> ext);
124 
128 FuncArg permute_map (TensptrT tensor, std::vector<RankT> order);
129 
131 FuncArg flip_map (TensptrT tensor, RankT dim);
132 
134 ArgsT to_args (TensptrsT tens);
135 
136 }
137 
138 #endif // TEQ_FUNCARG_HPP
FuncArg(TensptrT tensor, CoordptrT shaper)
Construct FuncArg auto deducing coorder_ and map_io_ flag.
Definition: funcarg.hpp:24
FuncArg(TensptrT tensor, CoordptrT shaper, bool map_io, CoordptrT coorder)
Construct FuncArg with specific coorder_ and map_io_ flag.
Definition: funcarg.hpp:43
ArgsT to_args(TensptrsT tens)
Return ArgsT with each tensor in TensptrsT attached to identity mapper.
CoordptrT get_shaper(void) const
Return shaper coord map.
Definition: funcarg.hpp:67
bool map_io_
Definition: funcarg.hpp:94
std::vector< FuncArg > ArgsT
Type of functor arguments.
Definition: funcarg.hpp:101
bool map_io(void) const
Definition: funcarg.hpp:74
uint8_t RankT
Type used for shape rank.
Definition: shape.hpp:23
Definition: shape.hpp:62
Shape shape(void) const
Return shape of tensor filtered through coordinate mapper.
Definition: funcarg.hpp:55
TensptrT get_tensor(void) const
Return tensor being mapped.
Definition: funcarg.hpp:61
std::shared_ptr< iCoordMap > CoordptrT
Type of iCoordMap smartpointer.
Definition: coord.hpp:106
FuncArg reduce_map(TensptrT tensor, RankT rank, std::vector< DimT > red)
TensptrT tensor_
Tensor reference.
Definition: funcarg.hpp:87
CoordptrT get_coorder(void) const
Return coord map for coordinates.
Definition: funcarg.hpp:80
Coordinate mapper and tensor pair.
Definition: funcarg.hpp:21
CoordptrT identity
Identity matrix instance.
CoordptrT shaper_
Shape mapper.
Definition: funcarg.hpp:90
FuncArg extend_map(TensptrT tensor, RankT rank, std::vector< DimT > ext)
FuncArg flip_map(TensptrT tensor, RankT dim)
Return FuncArg that flips input tensor along dimension.
std::shared_ptr< iTensor > TensptrT
Tensor smart pointer.
Definition: itensor.hpp:51
FuncArg permute_map(TensptrT tensor, std::vector< RankT > order)
std::vector< TensptrT > TensptrsT
Vector of tensor smart pointers.
Definition: itensor.hpp:60
Definition: coord.hpp:16
Shape apply_shaper(const CoordptrT &shaper, Shape inshape)
FuncArg reduce_1d_map(TensptrT tensor, RankT rank)
CoordptrT coorder_
Coordinate mapper.
Definition: funcarg.hpp:97
NElemT n_elems(void) const
Return the total number of elements represented by the shape.
Definition: shape.hpp:118
FuncArg identity_map(TensptrT tensor)
Return FuncArg that identity maps input tensor.