def testPartitionedVariableMasking(self):
    partitioner = partitioned_variables.variable_axis_size_partitioner(40)
    with self.cached_session() as session:
        with variable_scope.variable_scope('', partitioner=partitioner):
            sparsity = variables.VariableV1(0.5, name='Sparsity')
            weights = variable_scope.get_variable('weights', initializer=math_ops.linspace(1.0, 100.0, 100))
            masked_weights = pruning.apply_mask(weights, scope=variable_scope.get_variable_scope())
        p = pruning.Pruning(sparsity=sparsity)
        p._spec.threshold_decay = 0.0
        mask_update_op = p.mask_update_op()
        variables.global_variables_initializer().run()
        masked_weights_val = masked_weights.eval()
        session.run(mask_update_op)
        masked_weights_val = masked_weights.eval()
        self.assertAllEqual(np.count_nonzero(masked_weights_val), 50)
def testPartitionedVariableMasking(self):
    partitioner = partitioned_variables.variable_axis_size_partitioner(40)
    with self.cached_session() as session:
        with variable_scope.variable_scope(, partitioner=partitioner):
            sparsity = variables.VariableV1(0.5, name='Sparsity')
            weights = variable_scope.get_variable('weights', initializer=math_ops.linspace(1.0, 100.0, 100))
            masked_weights = pruning.apply_mask(weights, scope=variable_scope.get_variable_scope())
        p = pruning.Pruning(sparsity=sparsity)
        p._spec.threshold_decay = 0.0
        mask_update_op = p.mask_update_op()
        variables.global_variables_initializer().run()
        masked_weights_val = masked_weights.eval()
        session.run(mask_update_op)
        masked_weights_val = masked_weights.eval()
        self.assertAllEqual(np.count_nonzero(masked_weights_val), 50)