-
Notifications
You must be signed in to change notification settings - Fork 94
/
vector_operations.h
52 lines (50 loc) · 1.46 KB
/
vector_operations.h
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
/* vim: ft=cpp
* */
#pragma once
#include <vector_types.h> // float4
#include "config.h"
//__device__ float4 operator*(float4 a, float4 b);
//__device__ float4 operator-(float4 a, float4 b);
//__device__ float4 operator-(float4 a);
//__device__ float4 operator+(float4 a, float4 b);
//__device__ float4 operator/(float4 a, float k);
static __device__ float4 operator*(float4 a, float4 b) {
return make_float4(a.x*b.x,
a.y*b.y,
a.z*b.z,
0);
}
static __device__ float4 operator-(float4 a, float4 b) {
return make_float4(a.x-b.x,
a.y-b.y,
a.z-b.z,
0);
}
static __device__ float4 operator-(float4 a) {
return make_float4(-a.x,
-a.y,
-a.z,
0);
}
static __device__ float4 operator+(float4 a, float4 b) {
return make_float4(a.x+b.x,
a.y+b.y,
a.z+b.z,
0);
}
static __device__ float4 operator/(float4 a, float k) {
return make_float4(a.x/k,
a.y/k,
a.z/k,
0);
}
static __device__ float l1_float4 (float4 a) {
return ( fabsf (a.x) +
fabsf (a.y) +
fabsf (a.z))*0.3333333f;
}
static __device__ float l2_float4 (float4 a) {
return sqrtf( pow2 (a.x) +
pow2 (a.y) +
pow2 (a.z));
}