class_docstr: This class represents a particular config for a set of signal
  processing based sparsification functions on tensors. This can
  be used both on weights, gradients and other tensors like the
  optimizer state.
  
  During initialization, this class requires a value for one of
  `sst_top_k_element` or `sst_top_k_percent` and also requires a
  value for one of `dst_top_k_element` or `dst_top_k_percent`.
  
  This class only handles tensor inputs and outputs. We leave
  state_dict type of data handling to upper layer functions.
  
  Args:
      algo (Algo):
          The algorithm used. Default: FFT
      sst_top_k_dim (int, optional):
          The dimension on which the top-k is done for SST.
          E.g. -1 is the last dim. None means flatten and top-k on all dims.
          There is no way to specify multiple dims other than None.
          Default: -1
      sst_top_k_element (int, optional):
          Number of top-k elements to retain for SST. Default: None
      sst_top_k_percent (float, optional):
          Percent of top-k elements to retain for SST. Default: None
      dst_top_k_dim (int, optional):
          The dimension on which the top-k is done for DST.
          E.g. -1 is the last dim. None means flatten and top-k on all dims.
          There is no way to specify multiple dims other than None.
          Default: None
      dst_top_k_element (int, optional):
          Number of top-k elements to retain for DST. Default: None
      dst_top_k_percent (float, optional):
          Percent of top-k elements to retain for DST. Default: None
  
  Example:
      .. code-block:: python
  
          2d_sparser = SignalSparsity(sst_top_k_element=10, dst_top_k_element=1)
          sst = 2d_sparser.dense_to_sst(linear.weight.data)
  
          3d_sparser = SingalSparsity(algo=Algo.FFT, sst_top_k_dim=None, dst_top_k_dim=-1, sst_top_k_percent=10, dst_top_k_element=100)
          conv.weight.data, _, _ = 3d_sparser.lossy_compress(conv.weight.data)
docstr: Get Signal Sparse Tensor (SST) from a dense tensor
  
  Dense -> fft -> top-k -> results.
  
  The input dense tensor is transformed using a transform algorithm according to the `algo`
  initialization argument. The SST is then generated from the top_k_elements
  (or the top_k_percentage) of values from the transformed tensor along the 'sst_top_k_dim'.
  
  Args:
      dense (Tensor):
          Input dense tensor (no zeros).
  
  Returns:
      (Tensor, optional):
          Same shaped tensor as the input dense tensor, still in dense format but in frequency
          domain (complex valued) and has zeros.
docstr_tok: ["Get","Signal","Sparse","Tensor","(","SST",")","from","a","dense","tensor","Dense","-",">","fft","-",">","top-k","-",">","results",".","The","input","dense","tensor","is","transformed","using","a","transform","algorithm","according","to","the","`","algo","`","initialization","argument",".","The","SST","is","then","generated","from","the","top_k_elements","(","or","the","top_k_percentage",")","of","values","from","the","transformed","tensor","along","the","'sst_top_k_dim","'",".","Args",":","dense","(","Tensor",")",":","Input","dense","tensor","(","no","zeros",")",".","Returns",":","(","Tensor",",","optional",")",":","Same","shaped","tensor","as","the","input","dense","tensor",",","still","in","dense","format","but","in","frequency","domain","(","complex","valued",")","and","has","zeros","."]
code: def dense_to_sst(self, dense: Tensor) -> Optional[Tensor]:
      """Get Signal Sparse Tensor (SST) from a dense tensor
  
      Dense -> fft -> top-k -> results.
  
      The input dense tensor is transformed using a transform algorithm according to the `algo`
      initialization argument. The SST is then generated from the top_k_elements
      (or the top_k_percentage) of values from the transformed tensor along the 'sst_top_k_dim'.
  
      Args:
          dense (Tensor):
              Input dense tensor (no zeros).
  
      Returns:
          (Tensor, optional):
              Same shaped tensor as the input dense tensor, still in dense format but in frequency
              domain (complex valued) and has zeros.
      """
      if not self._sst_enabled:
          # Special case, SST is simply None, which represents an all-zero tensor.
          return None
  
      top_k_total_size = _top_k_total_size(dense, self._sst_top_k_dim)
      k = _get_k_for_topk(
          self._sst_top_k_percent,
          self._sst_top_k_element,
          top_k_total_size,
      )
      dense_freq = self._transform(dense, dim=self._sst_top_k_dim)
  
      # NOTE: real_dense_freq can potentially be magnitude of complex frequency components
      # or DCT transformed components when using DCT (currently not implemented).
      # TODO: In case of the FFT, the imaginary part can perhaps be quantized or pruning can be
      # done on the smaller phases.
      real_dense_freq = dense_freq.real.abs()
      return _scatter_topk_to_sparse_tensor(
          real_dense_freq, dense_freq, k, dim=self._sst_top_k_dim
      )
  
imports: from enum import Enum
  from typing import Optional, Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 5 for calling the SignalSparsity obj's underlying member method code with example usage: obj.dense_to_sst(dense) and returns: _scatter_topk_to_sparse_tensor, None