Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get magnitudes in cython for less memory consumption #946

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/urh/cythonext/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import numpy as np
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, int64_t
from libc.stdlib cimport malloc, calloc, free
from cython.parallel import prange
from libc.math cimport log10,pow
from libc.math cimport log10,pow,sqrt
from libcpp cimport bool

from cpython cimport array
Expand Down Expand Up @@ -124,6 +124,17 @@ cpdef uint64_t crc(uint8_t[:] inpt, uint8_t[:] polynomial, uint8_t[:] start_valu

return crc & crc_mask


cpdef np.ndarray[np.double_t, ndim=1] get_magnitudes(IQ arr):
cdef uint64_t i, n = len(arr)

cdef np.ndarray[np.double_t, ndim=1] result = np.zeros(n, dtype = np.double)

for i in range(0, n):
result[i] = sqrt(arr[i][0] * arr[i][0] + arr[i][1] * arr[i][1])

return result

cpdef np.ndarray[np.uint64_t, ndim=1] calculate_cache(uint8_t[:] polynomial, bool reverse_polynomial=False, uint8_t bits=8):
cdef uint8_t j, poly_order = len(polynomial)
cdef uint64_t crc_mask = <uint64_t> pow(2, poly_order - 1) - 1
Expand Down
8 changes: 3 additions & 5 deletions src/urh/signalprocessing/IQArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import numpy as np

from urh.cythonext.util import get_magnitudes


class IQArray(object):
def __init__(self, data: np.ndarray, dtype=None, n=None, skip_conversion=False):
Expand Down Expand Up @@ -75,13 +77,9 @@ def imag(self):
def imag(self, value):
self.__data[:, 1] = value

@property
def magnitudes_squared(self):
return self.real**2.0 + self.imag**2.0

@property
def magnitudes(self):
return np.sqrt(self.magnitudes_squared)
return get_magnitudes(self.__data)

@property
def magnitudes_normalized(self):
Expand Down