class_docstr: Prune entire (currently unpruned) channels in a tensor at random.
  
  Args:
      amount (int or float): quantity of parameters to prune.
          If ``float``, should be between 0.0 and 1.0 and represent the
          fraction of parameters to prune. If ``int``, it represents the
          absolute number of parameters to prune.
      dim (int, optional): index of the dim along which we define
          channels to prune. Default: -1.
class_docstr_tok: ["Prune","entire","(","currently","unpruned",")","channels","in","a","tensor","at","random",".","Args",":","amount","(","int","or","float",")",":","quantity","of","parameters","to","prune",".","If","``","float","``",",","should","be","between","0.0","and","1.0","and","represent","the","fraction","of","parameters","to","prune",".","If","``","int","``",",","it","represents","the","absolute","number","of","parameters","to","prune",".","dim","(","int",",","optional",")",":","index","of","the","dim","along","which","we","define","channels","to","prune",".","Default",":","-1","."]
docstr: Compute and returns a mask for the input tensor ``t``.
  
  Starting from a base ``default_mask`` (which should be a mask of ones
  if the tensor has not been pruned yet), generate a random mask to
  apply on top of the ``default_mask`` by randomly zeroing out channels
  along the specified dim of the tensor.
  
  Args:
      t (torch.Tensor): tensor representing the parameter to prune
      default_mask (torch.Tensor): Base mask from previous pruning
          iterations, that need to be respected after the new mask is
          applied. Same dims as ``t``.
  
  Returns:
      mask (torch.Tensor): mask to apply to ``t``, of same dims as ``t``
  
  Raises:
      IndexError: if ``self.dim >= len(t.shape)``
docstr_tok: ["Compute","and","returns","a","mask","for","the","input","tensor","``","t","``",".","Starting","from","a","base","``","default_mask","``","(","which","should","be","a","mask","of","ones","if","the","tensor","has","not","been","pruned","yet",")",",","generate","a","random","mask","to","apply","on","top","of","the","``","default_mask","``","by","randomly","zeroing","out","channels","along","the","specified","dim","of","the","tensor",".","Args",":","t","(","torch.Tensor",")",":","tensor","representing","the","parameter","to","prune","default_mask","(","torch.Tensor",")",":","Base","mask","from","previous","pruning","iterations",",","that","need","to","be","respected","after","the","new","mask","is","applied",".","Same","dims","as","``","t","``",".","Returns",":","mask","(","torch.Tensor",")",":","mask","to","apply","to","``","t","``",",","of","same","dims","as","``","t","``","Raises",":","IndexError",":","if","``","self.dim",">","=","len","(","t.shape",")","``"]
code: def compute_mask(self, t, default_mask):
      r"""Compute and returns a mask for the input tensor ``t``.
  
      Starting from a base ``default_mask`` (which should be a mask of ones
      if the tensor has not been pruned yet), generate a random mask to
      apply on top of the ``default_mask`` by randomly zeroing out channels
      along the specified dim of the tensor.
  
      Args:
          t (torch.Tensor): tensor representing the parameter to prune
          default_mask (torch.Tensor): Base mask from previous pruning
              iterations, that need to be respected after the new mask is
              applied. Same dims as ``t``.
  
      Returns:
          mask (torch.Tensor): mask to apply to ``t``, of same dims as ``t``
  
      Raises:
          IndexError: if ``self.dim >= len(t.shape)``
      """
      # Check that tensor has structure (i.e. more than 1 dimension) such
      # that the concept of "channels" makes sense
      _validate_structured_pruning(t)
  
      # Check that self.dim is a valid dim to index t, else raise IndexError
      _validate_pruning_dim(t, self.dim)
  
      # Check that the amount of channels to prune is not > than the number of
      # channels in t along the dim to prune
      tensor_size = t.shape[self.dim]
      # Compute number of units to prune: amount if int,
      # else amount * tensor_size
      nparams_toprune = _compute_nparams_toprune(
          self.amount, tensor_size
      )
      # This should raise an error if the number of units to prune is larger
      # than the number of units in the tensor
      _validate_pruning_amount(nparams_toprune, tensor_size)
  
      # Compute binary mask by initializing it to all 0s and then filling in
      # 1s wherever topk.indices indicates, along self.dim.
      # mask has the same shape as tensor t
      def make_mask(t, dim, nchannels, nchannels_toprune):
          # generate a random number in [0, 1] to associate to each channel
          prob = torch.rand(nchannels)
          # generate mask for each channel by 0ing out the channels that
          # got assigned the k = nchannels_toprune lowest values in prob
          threshold = torch.kthvalue(prob, k=nchannels_toprune).values
          channel_mask = prob > threshold
  
          mask = torch.zeros_like(t)
          slc = [slice(None)] * len(t.shape)
          slc[dim] = channel_mask
          mask[slc] = 1
          return mask
  
      if nparams_toprune == 0:  # k=0 not supported by torch.kthvalue
          mask = default_mask
      else:
          # apply the new structured mask on top of prior (potentially
          # unstructured) mask
          mask = make_mask(t, self.dim, tensor_size, nparams_toprune)
          mask *= default_mask.to(dtype=mask.dtype)
      return mask
  
imports: import numbers
  from abc import ABC, abstractmethod
  from collections.abc import Iterable
  from typing import Tuple
  import torch
label_desc: Use image node_id 2 for calling the RandomStructured obj's underlying member method code with example usage: obj.compute_mask(t, default_mask) and returns: mask, mask