class_docstr: Convert a sparse univariate time series to the `interval-size` format,
  i.e., a two dimensional time series where the first dimension corresponds
  to the time since last positive value (1-indexed), and the second dimension
  corresponds to the size of the demand. This format is used often in the
  intermittent demand literature, where predictions are performed on this
  "dense" time series, e.g., as in Croston's method.
  
  As an example, the time series `[0, 0, 1, 0, 3, 2, 0, 4]` is converted into
  the 2-dimensional time series `[[3, 2, 1, 2], [1, 3, 2, 4]]`, with a
  shape (2, M) where M denotes the number of non-zero items in the time
  series.
  
  Parameters
  ----------
  target_field
      The target field to be converted, containing a univariate and sparse
      time series
  drop_empty
      If True, all-zero time series will be dropped.
  discard_first
      If True, the first element in the converted dense series will be
      dropped, replacing the target with a (2, M-1) tet instead. This can be
      used when the first 'inter-demand' time is not well-defined. e.g.,
      when the true starting index of the time series is not known.
class_docstr_tok: ["Convert","a","sparse","univariate","time","series","to","the","`","interval-size","`","format",",","i.e.",",","a","two","dimensional","time","series","where","the","first","dimension","corresponds","to","the","time","since","last","positive","value","(","1-indexed",")",",","and","the","second","dimension","corresponds","to","the","size","of","the","demand",".","This","format","is","used","often","in","the","intermittent","demand","literature",",","where","predictions","are","performed","on","this","''","dense","''","time","series",",","e.g.",",","as","in","Croston","'s","method",".","As","an","example",",","the","time","series","`","[","0",",","0",",","1",",","0",",","3",",","2",",","0",",","4","]","`","is","converted","into","the","2-dimensional","time","series","`","[","[","3",",","2",",","1",",","2","]",",","[","1",",","3",",","2",",","4","]","]","`",",","with","a","shape","(","2",",","M",")","where","M","denotes","the","number","of","non-zero","items","in","the","time","series",".","Parameters","--","--","--","--","--","target_field","The","target","field","to","be","converted",",","containing","a","univariate","and","sparse","time","series","drop_empty","If","True",",","all-zero","time","series","will","be","dropped",".","discard_first","If","True",",","the","first","element","in","the","converted","dense","series","will","be","dropped",",","replacing","the","target","with","a","(","2",",","M-1",")","tet","instead",".","This","can","be","used","when","the","first","'inter-demand","'","time","is","not","well-defined",".","e.g.",",","when","the","true","starting","index","of","the","time","series","is","not","known","."]
code: def flatmap_transform(
      self, data: DataEntry, is_train: bool
  ) -> Iterator[DataEntry]:
      target = data[self.target_field]
  
      times, sizes = self._process_sparse_time_sample(target)
  
      if len(times) > 0 or not self.drop_empty:
          data[self.target_field] = [times, sizes]
          yield data
  
imports: from typing import Callable, Iterator, List, Optional, Tuple, Type
  import numpy
  from toolz import valmap
  from gluonts.core.component import validated, tensor_to_numpy
  from gluonts.dataset.common import DataEntry
  from gluonts.exceptions import assert_data_error
  from ._base import FlatMapTransformation, MapTransformation, SimpleTransformation
label_desc: Use image node_id 3 for calling the ToIntervalSizeFormat obj's underlying member method code with example usage: obj.flatmap_transform(data, is_train) without return types