Skip to content

Commit

Permalink
prep commands now output a nice number of samples by defaul. Fixes is…
Browse files Browse the repository at this point in the history
  • Loading branch information
scottransom committed Jul 14, 2018
1 parent ce435e7 commit 2a72a7d
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 137 deletions.
7 changes: 7 additions & 0 deletions include/misc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
long long next2_to_n(long long x);
/* Return the first value of 2^n >= x */

int is_power_of_10(long long n);
/* Check whether n is a power of 10 or not. Return 0 or 1 */

long long choose_good_N(long long orig_N);
// Choose a time series length that is larger than the input value but
// that is highly factorable.

float invsqrtf(float x);
// See http://en.wikipedia.org/wiki/Fast_inverse_square_root

Expand Down
43 changes: 29 additions & 14 deletions lib/python/psr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def distance(width):
x = Num.resize(x, (width,width))
return Num.sqrt(x + Num.transpose(x))

def is_power_of_10(n):
"""
is_power_of_10(n):
If n is a power of 10, return True.
"""
N = int(n)
while (N > 9 and N % 10 == 0):
N //= 10
return N == 1

def choose_N(orig_N):
"""
choose_N(orig_N):
Expand All @@ -38,31 +48,36 @@ def choose_N(orig_N):
by at least the maximum downsample factor * 2.
Currently, this is 8 * 2 = 16.
"""
# A list of 4-digit numbers that are highly factorable by small primes
goodfactors = [1008, 1024, 1056, 1120, 1152, 1200, 1232, 1280, 1296,
1344, 1408, 1440, 1536, 1568, 1584, 1600, 1680, 1728,
1760, 1792, 1920, 1936, 2000, 2016, 2048, 2112, 2160,
2240, 2304, 2352, 2400, 2464, 2560, 2592, 2640, 2688,
2800, 2816, 2880, 3024, 3072, 3136, 3168, 3200, 3360,
3456, 3520, 3584, 3600, 3696, 3840, 3872, 3888, 3920,
4000, 4032, 4096, 4224, 4320, 4400, 4480, 4608, 4704,
4752, 4800, 4928, 5040, 5120, 5184, 5280, 5376, 5488,
5600, 5632, 5760, 5808, 6000, 6048, 6144, 6160, 6272,
6336, 6400, 6480, 6720, 6912, 7040, 7056, 7168, 7200,
7392, 7680, 7744, 7776, 7840, 7920, 8000, 8064, 8192,
8400, 8448, 8624, 8640, 8800, 8960, 9072, 9216, 9408,
9504, 9600, 9680, 9856]
# A list of 4-dgit numbers that are highly factorable by small primes
goodfactors = [1000, 1008, 1024, 1056, 1120, 1152, 1200, 1232, 1280,
1296, 1344, 1408, 1440, 1536, 1568, 1584, 1600, 1680,
1728, 1760, 1792, 1920, 1936, 2000, 2016, 2048, 2112,
2160, 2240, 2304, 2352, 2400, 2464, 2560, 2592, 2640,
2688, 2800, 2816, 2880, 3024, 3072, 3136, 3168, 3200,
3360, 3456, 3520, 3584, 3600, 3696, 3840, 3872, 3888,
3920, 4000, 4032, 4096, 4224, 4320, 4400, 4480, 4608,
4704, 4752, 4800, 4928, 5040, 5120, 5184, 5280, 5376,
5488, 5600, 5632, 5760, 5808, 6000, 6048, 6144, 6160,
6272, 6336, 6400, 6480, 6720, 6912, 7040, 7056, 7168,
7200, 7392, 7680, 7744, 7776, 7840, 7920, 8000, 8064,
8192, 8400, 8448, 8624, 8640, 8800, 8960, 9072, 9216,
9408, 9504, 9600, 9680, 9856, 10000]
if orig_N < 10000:
return 0
# Get the number represented by the first 4 digits of orig_N
first4 = int(str(orig_N)[:4])
# Now get the number that is just bigger than orig_N
# that has its first 4 digits equal to "factor"
for factor in goodfactors:
if (factor == first4 and
orig_N % factor == 0 and
is_power_of_10(orig_N//factor)): break
if factor > first4: break
new_N = factor
while new_N < orig_N:
new_N *= 10
if new_N == orig_N:
return orig_N
# Finally, compare new_N to the closest power_of_two
# greater than orig_N. Take the closest.
two_N = 2
Expand Down
Loading

0 comments on commit 2a72a7d

Please sign in to comment.