class_docstr: Helper to scale `scales` before quantizing if to integer indices.
  
  Log quantization grid that aligns woth how scales are distributed
docstr: Convert `scale` in [0, scales_max] to an index.
docstr_tok: ["Convert","`","scale","`","in","[","0",",","scales_max","]","to","an","index","."]
code: def to_scale_idx(
      self, scales: Tensor, training: bool = True
  ) -> Tensor:
      """Convert `scale` in [0, scales_max] to an index."""
      if self.verify_valid_scales:
          assert (scales > 0.0).all(), "Error!"
  
      scales = scales + self.scales_min
  
      # [log(scales_min), log(scales_max + scales_min)]
      idx = torch.log(scales)
      # [0, log(scales_max + scales_min) - log(scales_min)]
      idx = idx - math.log(self.scales_min)
      normalizer = self.scales_max / self.scales_min  # [0, 1]
      normalizer = (
          normalizer + 1
      )  # log(max + min) - log(min) = log(max/min + 1)
      idx = idx / math.log(normalizer)
      # [0, num_bins-1]
      idx = idx * (self.num_bins - 1)
      if not training:
          idx = torch.round(idx)
      return idx
  
imports: import math
  from typing import Any, List, Optional, Tuple
  import scipy.stats
  import torch
  import torch.nn
  from compressai.entropy_models import EntropyModel
  from compressai.ops import LowerBound
  from torch import Tensor
label_desc: Use image node_id 2 for calling the Scaler obj's underlying member method code with example usage: obj.to_scale_idx(scales, training) and returns: idx