Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
ring.h
Go to the documentation of this file.
1 #ifndef __RING_H__
2 #define __RING_H__
3 
4 #include "../tensor/algstrct.h"
5 
6 namespace CTF {
7 
17  template <typename dtype=double, bool is_ord=CTF_int::get_default_is_ord<dtype>()>
18  class Ring : public Semiring<dtype, is_ord> {
19  public:
20  Ring(Ring const & other) : Semiring<dtype, is_ord>(other) {
21  this->abs = &CTF_int::char_abs< dtype, CTF_int::default_abs<dtype, is_ord> >;
22  }
28  Ring() : Semiring<dtype, is_ord>() {
29  this->abs = &CTF_int::char_abs< dtype, CTF_int::default_abs<dtype, is_ord> >;
30  }
31 
32  virtual CTF_int::algstrct * clone() const {
33  return new Ring<dtype, is_ord>(*this);
34  }
35 
47  Ring(dtype addid_,
48  dtype (*fadd_)(dtype a, dtype b),
49  MPI_Op addmop_,
50  dtype mulid_,
51  dtype (*fmul_)(dtype a, dtype b),
52  void (*gemm_)(char,char,int,int,int,dtype,dtype const*,dtype const*,dtype,dtype*)=NULL,
53  void (*axpy_)(int,dtype,dtype const*,int,dtype*,int)=NULL,
54  void (*scal_)(int,dtype,dtype*,int)=NULL)
55  : Semiring<dtype,is_ord>(addid_, fadd_, mulid_, addmop_, fmul_, gemm_, axpy_, scal_) {
56  this->abs = &CTF_int::char_abs< dtype, CTF_int::default_abs<dtype, is_ord> >;
57  }
58 
59  //treat NULL as mulid
60  void safeaddinv(char const * a, char *& b) const {
61  if (b==NULL) b = (char*)malloc(this->el_size);
62  if (a == NULL){
63 
64  ((dtype*)b)[0] = -this->tmulid;
65  } else {
66  ((dtype*)b)[0] = -((dtype*)a)[0];
67  }
68  }
69 
70  void addinv(char const * a, char * b) const {
71  ((dtype*)b)[0] = -((dtype*)a)[0];
72  }
73 
74  };
79 }
80 
81 #endif
Ring()
default constructor valid for only certain types: bool, int, unsigned int, int64_t, uint64_t, float, double, std::complex<float>, std::complex<double>
Definition: ring.h:28
void safeaddinv(char const *a, char *&b) const
b = -a, with checks for NULL and alloc as necessary
Definition: ring.h:60
Ring class defined by a datatype and addition and multiplicaton functions addition must have an ident...
Definition: ring.h:18
dtype tmulid
Definition: semiring.h:362
Ring(dtype addid_, dtype(*fadd_)(dtype a, dtype b), MPI_Op addmop_, dtype mulid_, dtype(*fmul_)(dtype a, dtype b), void(*gemm_)(char, char, int, int, int, dtype, dtype const *, dtype const *, dtype, dtype *)=NULL, void(*axpy_)(int, dtype, dtype const *, int, dtype *, int)=NULL, void(*scal_)(int, dtype, dtype *, int)=NULL)
constructor for algstrct equipped with * and +
Definition: ring.h:47
Semiring is a Monoid with an addition multiplicaton function addition must have an identity and be as...
Definition: semiring.h:359
Ring(Ring const &other)
Definition: ring.h:20
void(* abs)(char const *a, char *b)
b = max(a,addinv(a))
Definition: algstrct.h:42
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
virtual CTF_int::algstrct * clone() const
&#39;&#39;copy constructor&#39;&#39;
Definition: ring.h:32
void addinv(char const *a, char *b) const
b = -a
Definition: ring.h:70