Cutlass
CUDA Templates for Linear Algebra Subroutines and Solvers
pair.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  **************************************************************************************************/
25 
30 #pragma once
31 
32 namespace cutlass {
33 namespace platform {
34 
36 
38 template <typename T1, typename T2>
39 struct Pair {
40 
41  typedef T1 first_type;
42  typedef T2 second_type;
43 
44  //
45  // Data members
46  //
47 
48  T1 first;
49  T1 second;
50 
51  //
52  // Methods
53  //
54 
57  Pair() { }
58 
61  Pair(T1 const &first_, T2 const &second_): first(first_), second(second_) { }
62 };
63 
65 template <typename T1, typename T2>
66 Pair<T1, T2> make_Pair(T1 const &first, T2 const &second) {
67  return Pair<T1, T2>(first, second);
68 }
69 
71 template <typename T1, typename T2>
73 bool operator==(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
74  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
75 }
76 
78 template <typename T1, typename T2>
80 bool operator!=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
81  return !(lhs == rhs);
82 }
83 
85 template <typename T1, typename T2>
87 bool operator<(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
88  if (lhs.first < rhs.first) {
89  return true;
90  }
91  else if (rhs.first < lhs.first) {
92  return false;
93  }
94  else if (rhs.second < rhs.second) {
95  return false;
96  }
97  return false;
98 }
99 
101 template <typename T1, typename T2>
103 bool operator<=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
104  return !(rhs < lhs);
105 }
106 
108 template <typename T1, typename T2>
110 bool operator>(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
111  return (rhs < lhs);
112 }
113 
115 template <typename T1, typename T2>
117 bool operator>=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
118  return !(lhs < rhs);
119 }
120 
122 
123 } // namespace platform
124 } // namespace cutlass
Definition: convert.h:33
CUTLASS_HOST_DEVICE bool operator==(complex< T > const &lhs, complex< T > const &rhs)
Equality operator.
Definition: complex.h:224
Pair< T1, T2 > make_Pair(T1 const &first, T2 const &second)
Constructs a pair and deduces types.
Definition: pair.h:66
CUTLASS_HOST_DEVICE Pair()
Default constructor.
Definition: pair.h:57
CUTLASS_HOST_DEVICE bool operator>(Pair< T1, T2 > const &lhs, Pair< T1, T2 > const &rhs)
Lexical comparison.
Definition: pair.h:110
T1 first_type
Definition: pair.h:41
T2 second_type
Definition: pair.h:42
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
T1 second
Definition: pair.h:49
CUTLASS_HOST_DEVICE bool operator!=(complex< T > const &lhs, complex< T > const &rhs)
Inequality operator.
Definition: complex.h:232
CUTLASS_HOST_DEVICE Pair(T1 const &first_, T2 const &second_)
Constructs a pair.
Definition: pair.h:61
Constructs an iterator from a pair of iterators.
Definition: pair.h:39
T1 first
Definition: pair.h:48
CUTLASS_HOST_DEVICE bool operator>=(Pair< T1, T2 > const &lhs, Pair< T1, T2 > const &rhs)
Lexical comparison.
Definition: pair.h:117