Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
"""
Creates Gauss kernels on the CPU/GPU and in numpy and compares these.
"""
print('*** Running Test: ' + self.__class__.__name__ + ' function: ' + _getframe().f_code.co_name)
# this test fails with mX = 9 and mY = 8 due to a bug in nvcc that needs more investigation
# for now, skip this test to the build can pass.
# for mY in [1, 2, 3, 8]:
# for mX in [1, 2, 3, 9]:
for mY in [1, 2, 3, 9]:
for mX in [1, 2, 3, 8]:
print "Test case mX = %d and mY = %d." % (mX, mY) # Print parameters of the test case.
op = Gauss2DOp(dimOut=[mY,mX], clear_cache=True)
dataCPU = op.evaluate_c()
dataNPY = gauss2DNp([mY,mX])
assert np.allclose(dataCPU, dataNPY)
if ops.local.cuda_enabled:
dataGPU = op.evaluate_cuda()
assert np.allclose(dataGPU, dataNPY)
def test(self):
"""
Creates Gauss kernels on the CPU/GPU and in numpy and compares these.
"""
print('*** Running Test: ' + self.__class__.__name__ + ' function: ' + _getframe().f_code.co_name)
# this test fails with mX = 9 and mY = 8 due to a bug in nvcc that needs more investigation
# for now, skip this test to the build can pass.
# for mY in [1, 2, 3, 8]:
# for mX in [1, 2, 3, 9]:
for mY in [1, 2, 3, 9]:
for mX in [1, 2, 3, 8]:
print "Test case mX = %d and mY = %d." % (mX, mY) # Print parameters of the test case.
op = Gauss2DOp(dimOut=[mY,mX], clear_cache=True)
dataCPU = op.evaluate_c()
dataNPY = gauss2DNp([mY,mX])
assert np.allclose(dataCPU, dataNPY)
if ops.local.cuda_enabled:
dataGPU = op.evaluate_cuda()
assert np.allclose(dataGPU, dataNPY)
def search():
n_query = len(queries)
diffusion = Diffusion(np.vstack([queries, gallery]), args.cache_dir)
offline = diffusion.get_offline_results(args.truncation_size, args.kd)
features = preprocessing.normalize(offline, norm="l2", axis=1)
scores = features[:n_query] @ features[n_query:].T
ranks = np.argsort(-scores.todense())
evaluate(ranks)
def search_old(gamma=3):
diffusion = Diffusion(gallery, args.cache_dir)
offline = diffusion.get_offline_results(args.truncation_size, args.kd)
time0 = time.time()
print('[search] 1) k-NN search')
sims, ids = diffusion.knn.search(queries, args.kq)
sims = sims ** gamma
qr_num = ids.shape[0]
print('[search] 2) linear combination')
all_scores = np.empty((qr_num, args.truncation_size), dtype=np.float32)
all_ranks = np.empty((qr_num, args.truncation_size), dtype=np.int)
for i in tqdm(range(qr_num), desc='[search] query'):
scores = sims[i] @ offline[ids[i]]
parts = np.argpartition(-scores, args.truncation_size)[:args.truncation_size]
ranks = np.argsort(-scores[parts])
all_scores[i] = scores[parts][ranks]
def initialize(self, input_stream=None):
# If no input file/stream specified, use default (or command line?)
# (or default values?)
if input_stream is None:
input_stream = str(raw_input('Enter name of input file: '))
# Open input file
inputs = ModelParameterDictionary(input_stream)
# Create grid
self.grid = create_and_initialize_grid(inputs)
# Create a diffusion component
self.diffusion_component = diffusion.DiffusionComponent(self.grid)
self.diffusion_component.initialize(input_stream)
# Read parameters
self.run_duration = inputs.get('RUN_DURATION', ptype=float)
self.opt_netcdf_output = inputs.get('OPT_FILE_OUTPUT', ptype='bool')
self.opt_display_output = inputs.get('OPT_DISPLAY_OUTPUT', ptype='bool')
self.setup_output_timing(inputs)