Skip to content

Commit 1f29bb2

Browse files
committed
[BugFixes] Add deconstructor for python classes.
1 parent a9e2786 commit 1f29bb2

6 files changed

+60
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.so
22
build/
33
python/*.cpp
4+
python/dist
5+
python/*.egg-info
46
build-vscode/
57
build-deb/
68
.vscode/

python/sample_entropy_calculator.pxd

+12-12
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ cdef extern from "sample_entropy_calculator_kd.h" namespace "sampen":
3333
double get_entropy()
3434
long long get_a()
3535
long long get_b()
36-
long long get_a_norm()
37-
long long get_b_norm()
36+
double get_a_norm()
37+
double get_b_norm()
3838
string get_method_name()
3939
void ComputeSampleEntropy()
4040

@@ -44,8 +44,8 @@ cdef extern from "sample_entropy_calculator_kd.h" namespace "sampen":
4444
double get_entropy()
4545
long long get_a()
4646
long long get_b()
47-
long long get_a_norm()
48-
long long get_b_norm()
47+
double get_a_norm()
48+
double get_b_norm()
4949
string get_method_name()
5050
void ComputeSampleEntropy()
5151

@@ -56,8 +56,8 @@ cdef extern from "sample_entropy_calculator_direct.h" namespace "sampen":
5656
double get_entropy()
5757
long long get_a()
5858
long long get_b()
59-
long long get_a_norm()
60-
long long get_b_norm()
59+
double get_a_norm()
60+
double get_b_norm()
6161
string get_method_name()
6262
void ComputeSampleEntropy()
6363

@@ -67,8 +67,8 @@ cdef extern from "sample_entropy_calculator_direct.h" namespace "sampen":
6767
double get_entropy()
6868
long long get_a()
6969
long long get_b()
70-
long long get_a_norm()
71-
long long get_b_norm()
70+
double get_a_norm()
71+
double get_b_norm()
7272
string get_method_name()
7373
void ComputeSampleEntropy()
7474

@@ -78,8 +78,8 @@ cdef extern from "sample_entropy_calculator_direct.h" namespace "sampen":
7878
double get_entropy()
7979
long long get_a()
8080
long long get_b()
81-
long long get_a_norm()
82-
long long get_b_norm()
81+
double get_a_norm()
82+
double get_b_norm()
8383
string get_method_name()
8484
void ComputeSampleEntropy()
8585

@@ -94,8 +94,8 @@ cdef extern from "sample_entropy_calculator_direct.h" namespace "sampen":
9494
double get_entropy()
9595
long long get_a()
9696
long long get_b()
97-
long long get_a_norm()
98-
long long get_b_norm()
97+
double get_a_norm()
98+
double get_b_norm()
9999
vector[long long] get_a_vec()
100100
vector[long long] get_b_vec()
101101
string get_method_name()

python/sample_entropy_calculator.pyx

+21-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ cdef class SampEnSKD:
3232
def __cinit__(self, const vector[double] &data, double r, unsigned m,
3333
OutputLevel level):
3434
self.c_ = new SampleEntropyCalculatorMao[double](data, r, m, level)
35-
35+
36+
def __dealloc__(self):
37+
if self.c_ != NULL:
38+
del self.c_
39+
3640
def method_name(self):
3741
return self.c_.get_method_name()
3842

@@ -65,6 +69,10 @@ cdef class SampEnRKD:
6569
OutputLevel level):
6670
self.c_ = new SampleEntropyCalculatorRKD[double](data, r, m, level)
6771

72+
def __dealloc__(self):
73+
if self.c_ != NULL:
74+
del self.c_
75+
6876
def method_name(self):
6977
return self.c_.get_method_name()
7078

@@ -97,6 +105,10 @@ cdef class SampEnFD:
97105
OutputLevel level):
98106
self.c_ = new SampleEntropyCalculatorFastDirect[double](data, r, m, level)
99107

108+
def __dealloc__(self):
109+
if self.c_ != NULL:
110+
del self.c_
111+
100112
def method_name(self):
101113
return self.c_.get_method_name()
102114

@@ -129,6 +141,10 @@ cdef class SampEnD:
129141
OutputLevel level):
130142
self.c_ = new SampleEntropyCalculatorDirect[double](data, r, m, level)
131143

144+
def __dealloc__(self):
145+
if self.c_ != NULL:
146+
del self.c_
147+
132148
def method_name(self):
133149
return self.c_.get_method_name()
134150

@@ -168,6 +184,10 @@ cdef class SampEnSamplingD:
168184
real_entropy, real_a_norm, real_b_norm,
169185
random_type, random_, presort, level)
170186

187+
def __dealloc__(self):
188+
if self.c_ != NULL:
189+
del self.c_
190+
171191
def method_name(self):
172192
return self.c_.get_method_name()
173193

python/setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from Cython.Build import cythonize
44
import platform
55

6+
description = 'Fast computation (or estimation) of sample entropy.'
67
extra_compile_args = ['-std=c++11']
78
if platform.system() == 'Darwin':
89
extra_compile_args += ['-mmacosx-version-min=10.7', '-stdlib=libc++']
910

10-
setup(ext_modules=cythonize([Extension('sampen',
11+
setup(name='sampen',
12+
description=description,
13+
version='1.0.0',
14+
ext_modules=cythonize([Extension('sampen',
1115
sources=[
1216
'sample_entropy_calculator.pyx',
1317
],

script/run_2dkq256.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/bash
2+
3+
r=0.2
4+
m=2
5+
INPUT_DIR=$HOME/workspace/entropy/2d/generation_dataset_kq_256
6+
OUTPUT_DIR=$HOME/workspace/entropy/2d/kd_256_result_r"$r"_m"$m"
7+
8+
for folder in `ls "$INPUT_DIR"`; do
9+
echo "Processing folder $folder..."
10+
mkdir -p "$OUTPUT_DIR"/"$folder" 2>/dev/null
11+
for f in `ls "$INPUT_DIR"/"$folder"`; do
12+
echo "Processing file "$folder"/$f ..."
13+
build/bin/sampen2d -r $r -m $m --multiscale-depth 10\
14+
--multiscale-factor 0.8\
15+
--input "$INPUT_DIR"/"$folder"/"$f"\
16+
> "$OUTPUT_DIR"/"$folder"/"$f".txt
17+
done
18+
done

script/run_ex_convergence_n0_kdtreemc_norr.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ r=0.15
4747
line_offset=100000
4848
n=1000010
4949
sample_num=1 # N1
50-
sample_size_array=$(seq -s',' 2000 2000 100000)
50+
sample_size_array=$(seq -s',' 5000 5000 50000)
5151
output_level=1
52-
subdir=convergence_n0_kdtreemc_m${m}_r${r}_220308
52+
subdir=convergence_n0_kdtreemc/m${m}_r${r}_220322
5353
mkdir -p result/$subdir 2>/dev/null
5454
for f in ${input_files[@]}; do
5555
input_file=${INPUT_DIR}/$f

0 commit comments

Comments
 (0)