function confusionMatrix_(labels, predictions, numClasses) {
    const $labels = (0, _tensorUtilEnv.convertToTensor)(labels, "labels", "confusionMatrix");
    const $predictions = (0, _tensorUtilEnv.convertToTensor)(predictions, "predictions", "confusionMatrix");
    _util.assert(numClasses == null || numClasses > 0 && Number.isInteger(numClasses), ()=>`If provided, numClasses must be a positive integer, ` + `but got ${numClasses}`);
    _util.assert($labels.rank === 1, ()=>`Expected the rank of labels to be 1, but got ${$labels.rank}`);
    _util.assert($predictions.rank === 1, ()=>`Expected the rank of predictions to be 1, ` + `but got ${$predictions.rank}`);
    _util.assert($labels.shape[0] === $predictions.shape[0], ()=>`Mismatch in the number of examples: ` + `${$labels.shape[0]} vs. ${$predictions.shape[0]}. ` + `Labels and predictions should have the same number of elements.`);
    _util.assert(numClasses > 0 && Number.isInteger(numClasses), ()=>`numClasses is required to be a positive integer, but got ` + `${numClasses}`);
    // TODO(cais): In the future, if oneHot supports tensors inputs for
    //   `numClasses`, `confusionMatrix` can make `numClasses` optional.
    const oneHotLabels = (0, _oneHot.oneHot)((0, _cast.cast)($labels, "int32"), numClasses);
    const oneHotPredictions = (0, _oneHot.oneHot)((0, _cast.cast)($predictions, "int32"), numClasses);
    const oneHotLabelsT = (0, _transpose.transpose)(oneHotLabels);
    const product = (0, _matMul.matMul)(oneHotLabelsT, oneHotPredictions);
    return (0, _cast.cast)(product, "int32");
}
Computes the confusion matrix from true labels and predicted labels.

```js
const labels = tf.tensor1d([0, 1, 2, 1, 0], 'int32');
const predictions = tf.tensor1d([0, 2, 2, 1, 0], 'int32');
const numClasses = 3;
const out = tf.math.confusionMatrix(labels, predictions, numClasses);
out.print();
// Expected output matrix:
// [[2, 0, 0],
//  [0, 1, 1],
//  [0, 0, 1]]
```

@param labels The target labels, assumed to be 0-based integers
  for the classes. The shape is `[numExamples]`, where
  `numExamples` is the number of examples included.
@param predictions The predicted classes, assumed to be
  0-based integers for the classes. Must have the same shape as `labels`.
@param numClasses Number of all classes, as an integer.
  Its value must be larger than the largest element in `labels` and
  `predictions`.
@returns The confusion matrix as a int32-type 2D tensor. The value at
  row `r` and column `c` is the number of times examples of actual class
  `r` were predicted as class `c`.

@doc {heading: 'Operations', subheading: 'Evaluation'}