code: def map_pianoroll(
      pianoroll,
      mapping_name,
      reduce_mode,
      min_pitch=constants.MIN_MIDI_PITCH,
  ):
      """Return a mapped pianoroll.
  
      The given mapping is a list of pitch classes, each with a base pitch. The
      pianoroll is a tensor of prediction of the form frame X pitch. All pitches are
      mapped to the base pitches in the provided mapping, and all other pitches are
      zeroed out.
  
      Args:
        pianoroll: A tensor of onset predictions of the form frame X pitch.
        mapping_name: Which mapping from HIT_MAPS to use.
        reduce_mode: If 'any', treats values as booleans and uses reduce_any. 'any'
          is appropriate for mapping note pianorolls. If 'max', treats values as
          floats and uses reduce_max. 'max' is appropriate for mapping velocity
          pianorolls.
        min_pitch: Used to offset MIDI pitches for the pianoroll.
  
      Returns:
        mapped_onset_predictions: The mapped onset_predictions.
      """
      mapping = []
      for m in HIT_MAPS[mapping_name]:
          mapping.append([p - min_pitch for p in m])
  
      mapped_pitches = {pitches[0]: pitches for pitches in mapping}
      mapped_predictions = []
      for pitch in range(pianoroll.shape[1]):
          if pitch in mapped_pitches:
              if reduce_mode == "any":
                  mapped_predictions.append(
                      tf.cast(
                          tf.math.reduce_any(
                              tf.cast(
                                  tf.gather(
                                      pianoroll,
                                      mapped_pitches[pitch],
                                      axis=1,
                                  ),
                                  tf.bool,
                              ),
                              axis=1,
                          ),
                          pianoroll.dtype,
                      )
                  )
              elif reduce_mode == "max":
                  mapped_predictions.append(
                      tf.math.reduce_max(
                          tf.gather(
                              pianoroll, mapped_pitches[pitch], axis=1
                          ),
                          axis=1,
                      )
                  )
              else:
                  raise ValueError(
                      "Unknown reduce_mode: {}".format(reduce_mode)
                  )
          else:
              mapped_predictions.append(
                  tf.zeros_like(pianoroll[:, pitch])
              )
      return tf.stack(mapped_predictions, axis=1)
  
imports: from magenta.models.onsets_frames_transcription import constants
  from note_seq.protobuf import music_pb2
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: map_pianoroll(pianoroll, mapping_name, reduce_mode, min_pitch) and returns: tf