-
Notifications
You must be signed in to change notification settings - Fork 3
/
minMaxScaler.py
45 lines (36 loc) · 1.29 KB
/
minMaxScaler.py
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 9 14:15:49 2019
@author: Lken
"""
import numpy as np
import ctypes as ct
def cpu_threaded_multichannel_minMaxScaler_32fc(y):
"""
Input the numChans and chanLen as output in the multi-channel WOLA function.
The chanLen is just the product of the inner channels and the time points.
"""
_libmc = np.ctypeslib.load_library("multiChannel_minMaxScaler_32fc", ".")
array_1d_complex_channels = np.ctypeslib.ndpointer(
dtype=np.complex64, ndim=3, flags="CONTIGUOUS"
) # this is ndim 2 since its multichannels
array_1d_single = np.ctypeslib.ndpointer(
dtype=np.float32, ndim=1, flags="CONTIGUOUS"
)
_libmc.multiChan_minMaxScaler_32fc.restype = ct.c_int32
_libmc.multiChan_minMaxScaler_32fc.argtypes = [
array_1d_complex_channels,
ct.c_int32,
ct.c_int32,
array_1d_single,
]
numChans = y.shape[0]
chanLen = y.shape[1] * y.shape[2]
out = np.empty(int(numChans * chanLen), dtype=np.float32) # make the output
retcode = _libmc.multiChan_minMaxScaler_32fc(
y, int(numChans), int(chanLen), out
) # run the dll function
out = out.reshape(
(numChans, y.shape[1], y.shape[2])
) # reshape to channels in columns
return out, retcode