Skip to content

Commit 411bda2

Browse files
committed
pep8 compliant
1 parent a20e001 commit 411bda2

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore=E731
3+
max-line-length=160

sdm/__init__.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_config_var(name):
2323
else:
2424
ext = get_config_var('SO')
2525

26-
fullpath = os.path.join(basedir, '_libsdm'+ext)
26+
fullpath = os.path.join(basedir, '_libsdm' + ext)
2727
if not os.path.isfile(fullpath):
2828
fullpath = os.path.join(basedir, '_libsdm.so')
2929

@@ -65,7 +65,7 @@ def _multK(value, K):
6565
def opencl_worksize_mult16(address_space):
6666
local_worksize = _multK(address_space.bs_len, 16)
6767
mcu = address_space.opencl_opts.max_compute_units
68-
global_worksize = _multK(address_space.sample // 20, 2*mcu*local_worksize)
68+
global_worksize = _multK(address_space.sample // 20, 2 * mcu * local_worksize)
6969
return local_worksize, global_worksize
7070

7171

@@ -74,7 +74,7 @@ def opencl_worksize_power2(address_space):
7474
while local_worksize < address_space.bs_len:
7575
local_worksize *= 2
7676
mcu = address_space.opencl_opts.max_compute_units
77-
global_worksize = _multK(address_space.sample // 20, 2*mcu*local_worksize)
77+
global_worksize = _multK(address_space.sample // 20, 2 * mcu * local_worksize)
7878
return local_worksize, global_worksize
7979

8080

@@ -563,19 +563,19 @@ def write(self, addr, datum, radius=None, weight=1):
563563
if isinstance(weight, int):
564564
libsdm.sdm_write2_weighted(pointer(self), addr.bs_data, c_uint(radius), datum.bs_data, c_int(weight))
565565
elif isinstance(weight, (list, tuple)):
566-
assert(self.bits+1 == len(weight))
566+
assert(self.bits + 1 == len(weight))
567567
# See https://docs.python.org/3/library/ctypes.html#type-conversions
568-
weight_buf = (c_int * (self.bits+1))(*weight)
568+
weight_buf = (c_int * (self.bits + 1))(*weight)
569569
libsdm.sdm_write2_weighted_table(pointer(self), addr.bs_data, c_uint(radius), datum.bs_data, weight_buf)
570570
else:
571571
raise NotImplemented
572572

573-
#def write_sub(self, addr, datum, radius=None):
574-
# ''' Write a bitstring to the SDM.
575-
# '''
576-
# if radius is None:
577-
# radius = self.radius
578-
# libsdm.sdm_write_sub(pointer(self), addr.bs_data, c_uint(radius), datum.bs_data)
573+
# def write_sub(self, addr, datum, radius=None):
574+
# ''' Write a bitstring to the SDM.
575+
# '''
576+
# if radius is None:
577+
# radius = self.radius
578+
# libsdm.sdm_write_sub(pointer(self), addr.bs_data, c_uint(radius), datum.bs_data)
579579

580580
def write_random_bitstrings(self, n):
581581
for _ in range(n):

sdm/utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ def div_pow2(x, a):
2121
try:
2222
r = x
2323
for _ in range(a):
24-
r = r/2.0
24+
r = r / 2.0
2525
return r
2626
except OverflowError:
27-
return 2**(log(x)/log(2) - a)
27+
return 2**(log(x) / log(2) - a)
2828

2929

3030
def calculate_probabilities(bits):
3131
from math import factorial
32-
comb = lambda a, b: factorial(a)//factorial(b)//factorial(a-b)
32+
comb = lambda a, b: factorial(a) // factorial(b) // factorial(a - b)
3333
acc = [0]
34-
for i in range(bits+1):
34+
for i in range(bits + 1):
3535
acc.append(acc[-1] + comb(bits, i))
3636
return [div_pow2(x, bits) for x in acc[1:]]
3737

3838

3939
def __calculate_radius(bits, threshold=0.001):
4040
from math import factorial
41-
comb = lambda a, b: factorial(a)//factorial(b)//factorial(a-b)
41+
comb = lambda a, b: factorial(a) // factorial(b) // factorial(a - b)
4242
x = 0
43-
for i in range(bits+1):
43+
for i in range(bits + 1):
4444
x += comb(bits, i)
4545
p = div_pow2(x, bits)
4646
if p >= threshold:
@@ -50,11 +50,11 @@ def __calculate_radius(bits, threshold=0.001):
5050

5151
def calculate_radius(bits, threshold=0.001):
5252
from scipy.stats import norm
53-
return int(bits/2.0 + norm.ppf(threshold)*(bits**0.5)/2.0)
53+
return int(bits / 2.0 + norm.ppf(threshold) * (bits**0.5) / 2.0)
5454

5555
if threshold == 0.001:
5656
# norminv(0.001) = 3.090232306167814
57-
return int(bits/2.0 - 3.090232306167814*(bits**0.5)/2.0)
57+
return int(bits / 2.0 - 3.090232306167814 * (bits**0.5) / 2.0)
5858
return __calculate_radius(bits, threshold)
5959

6060

0 commit comments

Comments
 (0)