Commit dcf51f9030a10d20fc6b41e151508cba51a5afc6

Authored by Brice COLOMBIER
1 parent 4f7d40276a
Exists in master

Clean imports

Showing 1 changed file with 10 additions and 11 deletions

preprocessing.py View file @ dcf51f9
1 1 # Imports for processing
2 2 import numpy as np
3   -import scipy.special
4 3 from skimage.util.shape import view_as_windows
5   -import itertools
6 4  
7 5 # Imports for parallel processing
8 6 from multiprocessing import Pool, current_process
9 7  
10 8  
... ... @@ -117,14 +115,13 @@
117 115  
118 116  
119 117 # Generate fake data for testing purposes
120   - data_set_width = 2000
121   - data_set_height = 1000
  118 + fake_nb_samples = 1000
  119 + fake_nb_traces = 1000
122 120 # test_array = np.array([xrange(i, i+data_set_width-data_set_height) for i in xrange(data_set_height)])
123   - test_array = np.random.rand(data_set_height, data_set_width)
  121 + test_array = np.random.rand(fake_nb_traces, fake_nb_samples)
124 122 traces = test_array
125 123 # Load traces from file
126 124 # traces = np.load(args.traces_name)
127   -
128 125 # Shorten the traces to split them into equally-sized chunks
129 126 shortened = 0
130 127 while int(np.shape(traces)[1] + (args.ncores - 1)*(args.window_size - 1))%args.ncores != 0:
... ... @@ -135,7 +132,8 @@
135 132 nb_samples = np.shape(traces)[1]
136 133  
137 134 # Perform non-parallel preprocessing
138   - preprocessed_traces, indexes = pairwise_operation(traces, args.window_size, args.min_dist, operation, dtype, args.verbose)
  135 + preprocessed_traces = []
  136 + # preprocessed_traces, indexes = pairwise_operation(traces, args.window_size, args.min_dist, operation, dtype, args.verbose)
139 137  
140 138 # Init pool of workers for parallel preprocessing
141 139 pool = Pool(args.ncores)
142 140  
... ... @@ -153,10 +151,11 @@
153 151 preprocessed_traces_parallel, indexes_parallel = parallel_processing_results[::2], parallel_processing_results[1::2]
154 152 preprocessed_traces_parallel = np.concatenate(preprocessed_traces_parallel, axis=1)
155 153 indexes_parallel = np.concatenate(indexes_parallel, axis=1)
156   -
  154 +
157 155 # Compare normal and parallel processing
158   - if np.all(preprocessed_traces.sort()==preprocessed_traces_parallel.sort()):
159   - if np.all(indexes.sort()==indexes_parallel.sort()):
160   - print "###\nGreat, sequential and\nparallel processing\nreturned the same result\n###"
  156 + if preprocessed_traces:
  157 + if np.all(preprocessed_traces.sort()==preprocessed_traces_parallel.sort()):
  158 + if np.all(indexes.sort()==indexes_parallel.sort()):
  159 + print "###\nGreat, sequential and\nparallel processing\nreturned the same result\n###"
161 160 np.save("preprocessed_masked_traces.npy", preprocessed_traces_parallel)