forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTHCTensorMathCompareT.cuh
72 lines (60 loc) · 2.08 KB
/
THCTensorMathCompareT.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
#ifndef THC_TENSORMATH_COMPARET_CUH
#define THC_TENSORMATH_COMPARET_CUH
#include "THCTensorMath.h"
#include "THCGeneral.h"
#include "THCTensorCopy.h"
#include "THCApply.cuh"
#include "THCNumerics.cuh"
#include "THCReduce.cuh"
template <typename T, typename TOut>
struct TensorLTOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::lt(*a, *b));
}
};
template <typename T, typename TOut>
struct TensorGTOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::gt(*a, *b));
}
};
template <typename T, typename TOut>
struct TensorLEOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::le(*a, *b));
}
};
template <typename T, typename TOut>
struct TensorGEOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::ge(*a, *b));
}
};
template <typename T, typename TOut>
struct TensorEQOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::eq(*a, *b));
}
};
template <typename T, typename TOut>
struct TensorNEOp {
__device__ inline void operator()(TOut* out, T* a, T* b) {
*out = ScalarConvert<bool, TOut>::to(THCNumerics<T>::ne(*a, *b));
}
};
template<typename ScalarTypeOut, typename ScalarType, typename TensorTypeOut, typename TensorType, typename Op>
void THC_logicalTensor(THCState *state,
TensorTypeOut *self_,
TensorType *src1,
TensorType *src2,
Op op) {
THCTensor_resize(state, self_, src1->sizes(), {});
THArgCheck(THCTensor_nElement(state, src1) ==
THCTensor_nElement(state, src2), 3,
"sizes do not match");
if (!THC_pointwiseApply3<ScalarTypeOut, ScalarType, ScalarType>(state, self_, src1, src2, op)) {
THArgCheck(false, 2, CUTORCH_DIM_WARNING);
}
THCudaCheck(cudaGetLastError());
}
#endif // THC_TENSORMATH_COMPARET_CUH