blob: e167ad7ad15e3c123ada1c670e4740cbb1042d27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
from cython.parallel cimport parallel, prange
cimport cython
from libc.math cimport sqrt
@cython.boundscheck(False)
@cython.wraparound(False)
def normalize(double[:] x):
cdef Py_ssize_t i
cdef double total = 0
cdef double norm
with nogil, parallel():
for i in prange(x.shape[0]):
total += x[i]*x[i]
norm = sqrt(total)
for i in prange(x.shape[0]):
x[i] /= norm
|