forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
THCTensorMathCompare.cuh
85 lines (67 loc) · 2.25 KB
/
THCTensorMathCompare.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef THC_TENSORMATH_COMPARE_CUH
#define THC_TENSORMATH_COMPARE_CUH
#include "THCTensorMath.h"
#include "THCGeneral.h"
#include "THCTensorCopy.h"
#include "THCApply.cuh"
#include "THCNumerics.cuh"
template <typename T, typename TOut>
struct TensorLTValueOp {
TensorLTValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::lt(*in, value));
}
const T value;
};
template <typename T, typename TOut>
struct TensorGTValueOp {
TensorGTValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::gt(*in, value));
}
const T value;
};
template <typename T, typename TOut>
struct TensorLEValueOp {
TensorLEValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::le(*in, value));
}
const T value;
};
template <typename T, typename TOut>
struct TensorGEValueOp {
TensorGEValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::ge(*in, value));
}
const T value;
};
template <typename T, typename TOut>
struct TensorEQValueOp {
TensorEQValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::eq(*in, value));
}
const T value;
};
template <typename T, typename TOut>
struct TensorNEValueOp {
TensorNEValueOp(T v) : value(v) {}
__device__ __forceinline__ void operator()(TOut* out, T* in) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::ne(*in, value));
}
const T value;
};
template<typename ScalarTypeOut, typename ScalarType, typename TensorTypeOut, typename TensorType, class Op>
void THC_logicalValue(THCState *state,
TensorTypeOut *self_,
TensorType *src,
Op op) {
THCTensor_resize(state, self_, src->sizes(), {});
if (!THC_pointwiseApply2<ScalarTypeOut, ScalarType>(state, self_, src, op)) {
THArgCheck(false, 2, CUTORCH_DIM_WARNING);
}
THCudaCheck(cudaGetLastError());
}
#endif // THC_TENSORMATH_COMPARE_CUH