Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_prop(layer: torch.nn.Module, prop: Any):
"""Low-level function for getting `prop` from `layer`."""
training_state = get_training_state(layer)
if prop in ('train_eig_vals', 'eval_eig_vals'):
layer_history = get_layer_prop(layer,
f'{training_state}_layer_history')
# calculate eigenvalues
if hasattr(layer, 'conv_method'):
eig_vals = latent_iterative_pca(layer,
layer_history,
conv_method=layer.conv_method)
else:
eig_vals = latent_iterative_pca(layer, layer_history)
return eig_vals
elif prop == 'param_eig_vals':
layer_svd = get_layer_prop(layer, 'layer_svd')
return layer_svd
def get_prop(layer: torch.nn.Module, prop: Any):
"""Low-level function for getting `prop` from `layer`."""
training_state = get_training_state(layer)
if prop in ('train_eig_vals', 'eval_eig_vals'):
layer_history = get_layer_prop(layer,
f'{training_state}_layer_history')
# calculate eigenvalues
if hasattr(layer, 'conv_method'):
eig_vals = latent_iterative_pca(layer,
layer_history,
conv_method=layer.conv_method)
else:
eig_vals = latent_iterative_pca(layer, layer_history)
return eig_vals
elif prop == 'param_eig_vals':
layer_svd = get_layer_prop(layer, 'layer_svd')
return layer_svd