function split(tensor, length, elementShape) {
      let totalLength = 0;
      const cumulativeLengths = length.map(len => {
          totalLength += len;
          return totalLength;
      });
      if (totalLength !== tensor.shape[0]) {
          throw new Error(`Expected sum of lengths to be equal to
          tensor.shape[0], but sum of lengths is
        ${totalLength}, and tensor's shape is: ${tensor.shape}`);
      }
      const elementPerRow = totalLength === 0 ? 0 : tensor.size / totalLength;
      const tensors = tfc.tidy(() => {
          const tensors = [];
          tensor = tfc.reshape(tensor, [1, totalLength, elementPerRow]);
          for (let i = 0; i < length.length; ++i) {
              const previousLength = (i === 0) ? 0 : cumulativeLengths[i - 1];
              const indices = [0, previousLength, 0];
              const sizes = [1, length[i], elementPerRow];
              tensors[i] = tfc.reshape(tfc.slice(tensor, indices, sizes), elementShape);
          }
          tensor.dispose();
          return tensors;
      });
      const list = new TensorList([], elementShape, tensor.dtype, length.length);
      for (let i = 0; i < tensors.length; i++) {
          list.setItem(i, tensors[i]);
      }
      return list;
  }
/**
   * Split the values of a Tensor into a TensorList.
   * @param length the lengths to use when splitting value along
   *    its first dimension.
   * @param tensor the tensor to split.
   * @param elementShape the shape of the future elements of the list
   */
Split the values of a Tensor into a TensorList.
@param length the lengths to use when splitting value along
its first dimension.
@param tensor the tensor to split.
@param elementShape the shape of the future elements of the list
Split the values of a Tensor into a TensorList . @param length the lengths to use when splitting value along its first dimension . @param tensor the tensor to split . @param elementShape the shape of the future elements of the list
function split(tensor, length, elementShape) {
      let totalLength = 0;
      const cumulativeLengths = length.map(len => {
          totalLength += len;
          return totalLength;
      });
      if (totalLength !== tensor.shape[0]) {
          throw new Error(`Expected sum of lengths to be equal to
          tensor.shape[0], but sum of lengths is
        ${totalLength}, and tensor's shape is: ${tensor.shape}`);
      }
      const elementPerRow = totalLength === 0 ? 0 : tensor.size / totalLength;
      const tensors = tfc.tidy(() => {
          const tensors = [];
          tensor = tfc.reshape(tensor, [1, totalLength, elementPerRow]);
          for (let i = 0; i < length.length; ++i) {
              const previousLength = (i === 0) ? 0 : cumulativeLengths[i - 1];
              const indices = [0, previousLength, 0];
              const sizes = [1, length[i], elementPerRow];
              tensors[i] = tfc.reshape(tfc.slice(tensor, indices, sizes), elementShape);
          }
          tensor.dispose();
          return tensors;
      });
      const list = new TensorList([], elementShape, tensor.dtype, length.length);
      for (let i = 0; i < tensors.length; i++) {
          list.setItem(i, tensors[i]);
      }
      return list;
  }
function split ( tensor , length , elementShape ) { let totalLength = 0 ; const cumulativeLengths = length . map ( len => { totalLength += len ; return totalLength ; } ) ; if ( totalLength !== tensor . shape [ 0 ] ) { throw new Error ( ` ${ totalLength } ${ tensor . shape } ` ) ; } const elementPerRow = totalLength === 0 ? 0 : tensor . size / totalLength ; const tensors = tfc . tidy ( ( ) => { const tensors = [ ] ; tensor = tfc . reshape ( tensor , [ 1 , totalLength , elementPerRow ] ) ; for ( let i = 0 ; i < length . length ; ++ i ) { const previousLength = ( i === 0 ) ? 0 : cumulativeLengths [ i - 1 ] ; const indices = [ 0 , previousLength , 0 ] ; const sizes = [ 1 , length [ i ] , elementPerRow ] ; tensors [ i ] = tfc . reshape ( tfc . slice ( tensor , indices , sizes ) , elementShape ) ; } tensor . dispose ( ) ; return tensors ; } ) ; const list = new TensorList ( [ ] , elementShape , tensor . dtype , length . length ) ; for ( let i = 0 ; i < tensors . length ; i ++ ) { list . setItem ( i , tensors [ i ] ) ; } return list ; }
Split the values of a Tensor into a TensorList.
Split the values of a Tensor into a TensorList .