Example #1
0
double entropy(const tensor<double, dim, device>& tensor, double totalSum = 1.0) {
  if (totalSum == 1.0) {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_double(), 0.0, thrust::plus<double>());
  } else {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_double_norm(totalSum), 0.0, thrust::plus<double>());
  }
}
Example #2
0
float entropy(const tensor<float, dim, device>& tensor, float totalSum = 1.f) {
  if (totalSum == 1.f) {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float(), 0.f, thrust::plus<float>());
  } else {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float_norm(totalSum), 0.f, thrust::plus<float>());
  }
}