-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyXOR.pyx
36 lines (28 loc) · 913 Bytes
/
myXOR.pyx
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
from libcpp.vector cimport vector
from libcpp cimport bool
import pickle
import os
import numpy as np
cimport numpy as np
cdef extern from "stdint.h" nogil:
ctypedef unsigned char uint8_t
cdef extern from "myXor.hpp":
void std_vec_xor(uint8_t *, uint8_t *, int)
void std_vec_minus(float *, float *, float, int);
def myXOR(vec1, vec2, factor, dtype='float64'):
if dtype == 'uint8':
return mySTDXOR(vec1, vec2)
else:
assert dtype == 'float32'
return myMinus(vec1, vec2, factor)
def mySTDXOR(vec1, vec2):
cdef np.ndarray[uint8_t, mode="c"] a = vec1
cdef np.ndarray[uint8_t, mode="c"] b = vec2
std_vec_xor(&a[0], &b[0], len(vec1))
return a
# return a
def myMinus(vec1, vec2, factor):
cdef np.ndarray[float, mode="c"] a = vec1
cdef np.ndarray[float, mode="c"] b = vec2
std_vec_minus(&a[0], &b[0], factor, len(vec1))
return a