Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
group.h
Go to the documentation of this file.
1 #ifndef __GROUP_H__
2 #define __GROUP_H__
3 
4 #include "../tensor/algstrct.h"
5 
6 namespace CTF {
15  template <typename dtype=double, bool is_ord=CTF_int::get_default_is_ord<dtype>()>
16  class Group : public Monoid<dtype, is_ord> {
17  public:
18  Group(Group const & other) : Monoid<dtype, is_ord>(other) { }
19 
20  virtual CTF_int::algstrct * clone() const {
21  return new Group<dtype, is_ord>(*this);
22  }
23 
24  Group() : Monoid<dtype, is_ord>() {
25  this->abs = &CTF_int::char_abs< dtype, CTF_int::default_abs<dtype, is_ord> >;
26  }
27 
28  Group(dtype taddid_,
29  dtype (*fadd_)(dtype a, dtype b),
30  MPI_Op addmop_)
31  : Monoid<dtype, is_ord>(taddid_, fadd_, addmop_) {
32  this->abs = &CTF_int::char_abs< dtype, CTF_int::default_abs<dtype, is_ord> >;
33  }
34 
35  //treat NULL as mulid
36  void safeaddinv(char const * a, char *& b) const {
37  if (a == NULL){
38  printf("CTF ERROR: unfortunately additive inverse functionality for groups is currently limited, as it is done for rings via scaling by the inverse of the multiplicative identity, which groups don't have. Use the tensor addinv function rather than an indexed expression.\n");
39  double * ptr = NULL;
40  ptr[0]=3.;
41  assert(0);
42  } else {
43  if (b==NULL) b = (char*)malloc(this->el_size);
44  ((dtype*)b)[0] = -((dtype*)a)[0];
45  }
46  }
47 
48  void addinv(char const * a, char * b) const {
49  ((dtype*)b)[0] = -((dtype*)a)[0];
50  }
51  };
52 
56 }
57 #include "semiring.h"
58 #endif
Group(dtype taddid_, dtype(*fadd_)(dtype a, dtype b), MPI_Op addmop_)
Definition: group.h:28
virtual CTF_int::algstrct * clone() const
&#39;&#39;copy constructor&#39;&#39;
Definition: group.h:20
void addinv(char const *a, char *b) const
b = -a
Definition: group.h:48
Group is a Monoid with operator &#39;-&#39; defined special case (parent) of a ring.
Definition: group.h:16
void(* abs)(char const *a, char *b)
b = max(a,addinv(a))
Definition: algstrct.h:42
Group()
Definition: group.h:24
int el_size
size of each element of algstrct in bytes
Definition: algstrct.h:16
algstrct (algebraic structure) defines the elementwise operations computed in each tensor contraction...
Definition: algstrct.h:34
Definition: apsp.cxx:17
A Monoid is a Set equipped with a binary addition operator &#39;+&#39; or a custom function addition must hav...
Definition: monoid.h:69
void safeaddinv(char const *a, char *&b) const
b = -a, with checks for NULL and alloc as necessary
Definition: group.h:36
Group(Group const &other)
Definition: group.h:18