32 #ifndef HERMES_COMMON_SIZE_H
33 #define HERMES_COMMON_SIZE_H
36 #include <type_traits>
47 template<
typename T>
class Size2 {
48 static_assert(std::is_same<T, u8>::value
49 || std::is_same<T, u16>::value ||
50 std::is_same<T, u32>::value || std::is_same<T, u64>::value,
51 "Size2 must hold an unsigned integer type!");
126 return i >= 0 && j >= 0 && i < static_cast<i64>(
width) &&
127 j < static_cast<i64>(
height);
143 static_assert(std::is_same<T, u8>::value
144 || std::is_same<T, u16>::value ||
145 std::is_same<T, u32>::value || std::is_same<T, u64>::value,
146 "Size3 must hold an unsigned integer type!");
238 std::ostream &operator<<(std::ostream &o,
const Size2<T> &s) {
239 o <<
"Size[" << s.
width <<
", " << s.
height <<
"]";
248 std::ostream &operator<<(std::ostream &o,
const Size3<T> &s) {
Holds 2-dimensional size.
Definition: size.h:47
HERMES_DEVICE_CALLABLE T operator[](int i) const
Dimension size const access.
Definition: size.h:76
HERMES_DEVICE_CALLABLE Size2< T > operator+(const Size2< T > &b) const
Addition.
Definition: size.h:87
HERMES_DEVICE_CALLABLE bool operator==(const Size2< T > &b) const
Comparison.
Definition: size.h:106
HERMES_DEVICE_CALLABLE bool operator!=(const Size2< T > &b) const
Comparison.
Definition: size.h:112
HERMES_DEVICE_CALLABLE T & operator[](int i)
Dimension size access.
Definition: size.h:82
HERMES_DEVICE_CALLABLE Size2(T size)
Single value constructor.
Definition: size.h:61
HERMES_DEVICE_CALLABLE Size2()
Default constructor.
Definition: size.h:58
T height
1-th dimension size
Definition: size.h:133
HERMES_DEVICE_CALLABLE bool contains(int i, int j) const
Checks if coordinate is inside half-open range [0, size)
Definition: size.h:125
T width
0-th dimension size
Definition: size.h:132
HERMES_DEVICE_CALLABLE Size2< T > operator/(T n) const
Definition: size.h:93
HERMES_DEVICE_CALLABLE T total() const
Computes total size area.
Definition: size.h:120
HERMES_DEVICE_CALLABLE Size2< T > operator*(T s) const
Scalar multiplication.
Definition: size.h:99
HERMES_DEVICE_CALLABLE Size2(T width, T height)
Constructor.
Definition: size.h:65
Holds 2-dimensional size.
Definition: size.h:142
HERMES_DEVICE_CALLABLE bool operator==(const Size3< T > &b) const
Dimension-wise comparison.
Definition: size.h:197
T width
0-th dimension size
Definition: size.h:224
HERMES_DEVICE_CALLABLE Size3< T > operator-(const Size3< T > &b) const
Subtraction.
Definition: size.h:190
HERMES_DEVICE_CALLABLE Size3(T _width, T _height, T _depth)
Constructor.
Definition: size.h:161
HERMES_DEVICE_CALLABLE T total() const
Computes total size area.
Definition: size.h:211
HERMES_DEVICE_CALLABLE T operator[](int i) const
Dimension size const access.
Definition: size.h:172
HERMES_DEVICE_CALLABLE Size3< T > operator+(const Size3< T > &b) const
Addition.
Definition: size.h:183
T height
1-th dimension size
Definition: size.h:225
HERMES_DEVICE_CALLABLE Size3(T size)
Single value constructor.
Definition: size.h:156
HERMES_DEVICE_CALLABLE T & operator[](int i)
Dimension size access.
Definition: size.h:178
T depth
2-th dimension size
Definition: size.h:226
HERMES_DEVICE_CALLABLE Size3()
Default constructor.
Definition: size.h:153
HERMES_DEVICE_CALLABLE Size2< T > slice(int d1=0, int d2=1) const
Gets 2-dimensional slice.
Definition: size.h:218
HERMES_DEVICE_CALLABLE bool operator!=(const Size3< T > &b) const
Dimension-wise comparison.
Definition: size.h:203
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45