function computeHistogramCat(data, bins) {
  // parse the overloaded bins argument
  let categories;

  if (bins === undefined) {
    categories = Array.from(new Set(data));
  } else if (Array.isArray(bins) && bins.length) {
    categories = bins;
  } else {
    throw '`bins` must be an non-empty array';
  }

  const nBins = categories.length;
  const indices = tf.tensor1d(data.map(d => categories.indexOf(d))).toInt();
  const binIds = tf.linspace(0, nBins - 1, nBins).toInt();

  const hist = binCount(indices, binIds);
  return [Array.from(hist.dataSync()), categories];
}
@param {Array} data - 1-D array of data points
@param {Array} bins - (optional) categories
@returns [{Array}] an array of 2 arrays:
0: hist, values of the histogram; 1: categories, length = hist.length.