class_docstr: This transform works for each ``const`` op if:
  
  - ``_is_deprecated=True`` and the ``op_selector`` returns ``True``.
  - ``_is_deprecated=False`` and the ``const`` value size ``> weight_threshold``.
  
  The transform performs the following:
  
  - The fraction of values with the least absolute value are zeroed out (self.sparsity).
  - If ``fake_compression=False``, the zeroed-out value is encoded using the ``constexpr_sparse_to_dense`` op.
  - If ``fake_compression=True``, the zeroed-out value is encoded using the ``const`` op.
  - Old ``const`` is replaced by a new operation with zeroed-out value.
class_docstr_tok: ["This","transform","works","for","each","``","const","``","op","if",":","-","``","_is_deprecated=True","``","and","the","``","op_selector","``","returns","``","True","``",".","-","``","_is_deprecated=False","``","and","the","``","const","``","value","size","``",">","weight_threshold","``",".","The","transform","performs","the","following",":","-","The","fraction","of","values","with","the","least","absolute","value","are","zeroed","out","(","self.sparsity",")",".","-","If","``","fake_compression=False","``",",","the","zeroed-out","value","is","encoded","using","the","``","constexpr_sparse_to_dense","``","op",".","-","If","``","fake_compression=True","``",",","the","zeroed-out","value","is","encoded","using","the","``","const","``","op",".","-","Old","``","const","``","is","replaced","by","a","new","operation","with","zeroed-out","value","."]
code: def transform_op(self, op: Operation):
      op_config = self.config._get_const_op_config(op)
      if op_config is None:
          return
      if not self.need_compress_const(
          op, self.config._is_deprecated, op_config.weight_threshold
      ):
          return
  
      if not isinstance(op.outputs[0].val, (np.ndarray, np.generic)):
          raise ValueError("Only numpy arrays are supported")
  
      if isinstance(op_config, OpThresholdPrunerConfig):
          sparse_params = self.compress_by_threshold(
              val=op.outputs[0].val,
              threshold=op_config.threshold,
              minimum_sparsity_percentile=op_config.minimum_sparsity_percentile,
          )
      elif isinstance(op_config, OpMagnitudePrunerConfig):
          # Structural sparsity can only be applied to conv / linear weight
          # For non applicable constant, we skip the compression,
          # we do allow the user to do structural pruning for non applicable constant,
          # if it is explicitly set by set_op_name,
          if not op_config._check_const_op_is_valid(op):
              if op.name not in self.config.op_name_configs:
                  logger.warning(
                      f"op named {op.name} not applicable for {OpMagnitudePrunerConfig} configuration. Skipped."
                  )
                  return
  
          if op_config.target_sparsity is not None:
              sparse_params = self.compress_by_magnitude(
                  val=op.outputs[0].val,
                  target_sparsity=op_config.target_sparsity,
                  block_size=op_config.block_size,
                  dim=op_config.dim,
              )
          elif op_config.n_m_ratio is not None:
              sparse_params = self.compress_by_nm_sparsity(
                  val=op.outputs[0].val,
                  n_m_ratio=op_config.n_m_ratio,
                  dim=op_config.dim,
              )
  
      if sparse_params is None:
          return
  
      if not self.fake_compression:
          new_var = mb.constexpr_sparse_to_dense(
              nonzero_data=sparse_params.nonzero_data,
              mask=sparse_params.mask,
              shape=np.uint32(sparse_params.shape),
              before_op=op,
              name=op.name + "_sparsified",
          )
      else:
          decompressed_val = self.decompress(sparse_params)
          new_var = mb.const(
              val=decompressed_val,
              before_op=op,
              name=op.name + "_fake_sparsified",
          )
  
      op.enclosing_block.replace_uses_of_var_after_op(
          anchor_op=op,
          old_var=op.outputs[0],
          new_var=new_var,
          no_check_var_types=True,
      )
  
      op.enclosing_block.remove_ops([op])
  
imports: from typing import Callable, Optional, Tuple
  import numpy
  from tqdm import tqdm
  from coremltools import _logger
  from coremltools.converters.mil._deployment_compatibility import AvailableTarget
  from coremltools.converters.mil.backend.mil.load import should_use_weight_file
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Operation, Program, types
  from coremltools.converters.mil.mil.block import is_current_opset_version_compatible_with
  from coremltools.converters.mil.mil.ops.defs._utils import pack_elements_into_bits
  from coremltools.converters.mil.mil.ops.defs.iOS16 import constexpr_affine_dequantize, constexpr_lut_to_dense, constexpr_sparse_to_dense
  from coremltools.converters.mil.mil.passes.defs.quantization import AbstractQuantizationPass
  from coremltools.converters.mil.mil.passes.helper import block_context_manager
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
  from coremltools.converters.mil.mil.types.type_mapping import nptype_from_builtin
  from coremltools.models.neural_network.quantization_utils import _get_kmeans_lookup_table_and_weight
  from coremltools.optimize.coreml._config import OpLinearQuantizerConfig, OpMagnitudePrunerConfig, OpPalettizerConfig, OpThresholdPrunerConfig, OptimizationConfig
label_desc: Use image node_id 7 for calling the prune_weights obj's underlying member method code with example usage: obj.transform_op(op) without return types