COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
Semirings.h
Go to the documentation of this file.
1
2#ifndef _SEMIRINGS_H_
3#define _SEMIRINGS_H_
4
5#include <utility>
6#include <climits>
7#include <cmath>
8#include "promote.h"
9
10template <typename T>
11struct inf_plus{
12 T operator()(const T& a, const T& b) const {
13 T inf = std::numeric_limits<T>::max();
14 if (a == inf || b == inf){
15 return inf;
16 }
17 return a + b;
18 }
19};
20
21
22template <class T1, class T2>
24{
26
27 static T_promote add(const T1 & arg1, const T2 & arg2)
28 {
29 return (static_cast<T_promote>(arg1) +
30 static_cast<T_promote>(arg2) );
31 }
32 static T_promote multiply(const T1 & arg1, const T2 & arg2)
33 {
34 return (static_cast<T_promote>(arg1) *
35 static_cast<T_promote>(arg2) );
36
37 }
38};
39
40
41template <class T1, class T2>
43{
45
46 static T_promote add(const T1 & arg1, const T2 & arg2)
47 {
48 return std::min<T_promote>
49 (static_cast<T_promote>(arg1), static_cast<T_promote>(arg2));
50 }
51 static T_promote multiply(const T1 & arg1, const T2 & arg2)
52 {
54 (static_cast<T_promote>(arg1), static_cast<T_promote>(arg2));
55 }
56};
57
58
59#endif
static T_promote add(const T1 &arg1, const T2 &arg2)
Definition Semirings.h:46
promote_trait< T1, T2 >::T_promote T_promote
Definition Semirings.h:44
static T_promote multiply(const T1 &arg1, const T2 &arg2)
Definition Semirings.h:51
static T_promote multiply(const T1 &arg1, const T2 &arg2)
Definition Semirings.h:32
promote_trait< T1, T2 >::T_promote T_promote
Definition Semirings.h:25
static T_promote add(const T1 &arg1, const T2 &arg2)
Definition Semirings.h:27
T operator()(const T &a, const T &b) const
Definition Semirings.h:12