123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- //
- // Academic License - for use in teaching, academic research, and meeting
- // course requirements at degree granting institutions only. Not for
- // government, commercial, or other organizational use.
- // File: histcounts.cpp
- //
- // MATLAB Coder version : 5.3
- // C/C++ source code generated on : 27-Mar-2023 15:34:32
- //
- // Include Files
- #include "fun10_histcounts.h"
- #include "rt_nonfinite.h"
- #include "coder_array.h"
- #include <cmath>
- #include <cstring>
- #include <math.h>
- // Function Declarations
- static double rt_powd_snf(double u0, double u1);
- // Function Definitions
- //
- // Arguments : double u0
- // double u1
- // Return Type : double
- //
- static double rt_powd_snf(double u0, double u1)
- {
- double y;
- if (std::isnan(u0) || std::isnan(u1)) {
- y = rtNaN;
- } else {
- double d;
- double d1;
- d = std::abs(u0);
- d1 = std::abs(u1);
- if (std::isinf(u1)) {
- if (d == 1.0) {
- y = 1.0;
- } else if (d > 1.0) {
- if (u1 > 0.0) {
- y = rtInf;
- } else {
- y = 0.0;
- }
- } else if (u1 > 0.0) {
- y = 0.0;
- } else {
- y = rtInf;
- }
- } else if (d1 == 0.0) {
- y = 1.0;
- } else if (d1 == 1.0) {
- if (u1 > 0.0) {
- y = u0;
- } else {
- y = 1.0 / u0;
- }
- } else if (u1 == 2.0) {
- y = u0 * u0;
- } else if ((u1 == 0.5) && (u0 >= 0.0)) {
- y = std::sqrt(u0);
- } else if ((u0 < 0.0) && (u1 > std::floor(u1))) {
- y = rtNaN;
- } else {
- y = std::pow(u0, u1);
- }
- }
- return y;
- }
- //
- // Arguments : const ::coder::array<double, 2U> &x
- // double n_data[]
- // int n_size[2]
- // double edges_data[]
- // int edges_size[2]
- // Return Type : void
- //
- namespace coder {
- void histcounts(const ::coder::array<double, 2U> &x, double n_data[],
- int n_size[2], double edges_data[], int edges_size[2])
- {
- double HighLimit;
- double LowLimit;
- double RawBinWidth_tmp;
- double epsxScale;
- double leftEdge;
- double xScale;
- int ni_data[100];
- int high_i;
- int i;
- int k;
- int low_i;
- int low_ip1;
- int mid_i;
- int nx;
- nx = x.size(1);
- k = 0;
- while ((k + 1 <= nx) && (std::isinf(x[k]) || std::isnan(x[k]))) {
- k++;
- }
- if (k + 1 > x.size(1)) {
- LowLimit = 0.0;
- low_i = 0;
- } else {
- LowLimit = x[k];
- low_i = 1;
- }
- HighLimit = LowLimit;
- i = k + 2;
- for (low_ip1 = i; low_ip1 <= nx; low_ip1++) {
- RawBinWidth_tmp = x[low_ip1 - 1];
- if ((!std::isinf(RawBinWidth_tmp)) && (!std::isnan(RawBinWidth_tmp))) {
- if (RawBinWidth_tmp < LowLimit) {
- LowLimit = RawBinWidth_tmp;
- } else if (RawBinWidth_tmp > HighLimit) {
- HighLimit = RawBinWidth_tmp;
- }
- low_i++;
- }
- }
- if (low_i > 0) {
- boolean_T b;
- boolean_T b1;
- xScale = std::fmax(std::abs(LowLimit), std::abs(HighLimit));
- b = !std::isinf(xScale);
- b1 = !std::isnan(xScale);
- if (b && b1) {
- if (xScale <= 2.2250738585072014E-308) {
- epsxScale = 4.94065645841247E-324;
- } else {
- frexp(xScale, &high_i);
- epsxScale = std::ldexp(1.0, high_i - 53);
- }
- } else {
- epsxScale = rtNaN;
- }
- RawBinWidth_tmp = HighLimit - LowLimit;
- leftEdge = std::fmax(RawBinWidth_tmp / 100.0, epsxScale);
- if (RawBinWidth_tmp >
- std::fmax(std::sqrt(epsxScale), 2.2250738585072014E-308)) {
- xScale = rt_powd_snf(10.0, std::floor(std::log10(leftEdge)));
- epsxScale = xScale * std::floor(leftEdge / xScale);
- leftEdge = std::fmax(
- std::fmin(epsxScale * std::floor(LowLimit / epsxScale), LowLimit),
- -1.7976931348623157E+308);
- xScale = (HighLimit - leftEdge) / 100.0;
- epsxScale = rt_powd_snf(
- 10.0, std::floor(std::log10((HighLimit - leftEdge) / 99.0 - xScale)));
- epsxScale *= std::ceil(xScale / epsxScale);
- xScale = std::fmin(std::fmax(leftEdge + 100.0 * epsxScale, HighLimit),
- 1.7976931348623157E+308);
- } else {
- if (b && b1) {
- if (xScale <= 2.2250738585072014E-308) {
- xScale = 4.94065645841247E-324;
- } else {
- frexp(xScale, &mid_i);
- xScale = std::ldexp(1.0, mid_i - 53);
- }
- } else {
- xScale = rtNaN;
- }
- xScale = std::fmax(1.0, std::ceil(100.0 * xScale));
- leftEdge = std::floor(2.0 * (LowLimit - xScale / 4.0)) / 2.0;
- xScale = std::ceil(2.0 * (HighLimit + xScale / 4.0)) / 2.0;
- epsxScale = (xScale - leftEdge) / 100.0;
- }
- if ((!std::isinf(epsxScale)) && (!std::isnan(epsxScale))) {
- edges_size[0] = 1;
- edges_size[1] = 101;
- std::memset(&edges_data[0], 0, 101U * sizeof(double));
- edges_data[0] = leftEdge;
- for (low_i = 0; low_i < 99; low_i++) {
- edges_data[low_i + 1] =
- leftEdge + (static_cast<double>(low_i) + 1.0) * epsxScale;
- }
- edges_data[100] = xScale;
- } else {
- edges_size[0] = 1;
- edges_size[1] = 101;
- edges_data[100] = xScale;
- edges_data[0] = leftEdge;
- if (leftEdge == -xScale) {
- xScale /= 100.0;
- for (k = 0; k < 99; k++) {
- edges_data[k + 1] =
- (2.0 * (static_cast<double>(k) + 2.0) - 102.0) * xScale;
- }
- edges_data[50] = 0.0;
- } else if (((leftEdge < 0.0) != (xScale < 0.0)) &&
- ((std::abs(leftEdge) > 8.9884656743115785E+307) ||
- (std::abs(xScale) > 8.9884656743115785E+307))) {
- epsxScale = leftEdge / 100.0;
- xScale /= 100.0;
- for (k = 0; k < 99; k++) {
- edges_data[k + 1] =
- (leftEdge + xScale * (static_cast<double>(k) + 1.0)) -
- epsxScale * (static_cast<double>(k) + 1.0);
- }
- } else {
- epsxScale = (xScale - leftEdge) / 100.0;
- for (k = 0; k < 99; k++) {
- edges_data[k + 1] =
- leftEdge + (static_cast<double>(k) + 1.0) * epsxScale;
- }
- }
- }
- } else {
- edges_size[0] = 1;
- edges_size[1] = 101;
- for (k = 0; k < 101; k++) {
- edges_data[k] = k;
- }
- }
- std::memset(&ni_data[0], 0, 100U * sizeof(int));
- nx = x.size(1);
- leftEdge = edges_data[0];
- xScale = edges_data[1] - edges_data[0];
- for (k = 0; k < nx; k++) {
- RawBinWidth_tmp = x[k];
- if ((RawBinWidth_tmp >= leftEdge) && (RawBinWidth_tmp <= edges_data[100])) {
- boolean_T guard1{false};
- epsxScale = std::ceil((RawBinWidth_tmp - leftEdge) / xScale);
- guard1 = false;
- if ((epsxScale >= 1.0) && (epsxScale < 101.0)) {
- i = static_cast<int>(epsxScale);
- if ((RawBinWidth_tmp >= edges_data[i - 1]) &&
- (RawBinWidth_tmp < edges_data[i])) {
- ni_data[i - 1]++;
- } else {
- guard1 = true;
- }
- } else {
- guard1 = true;
- }
- if (guard1) {
- low_i = 1;
- low_ip1 = 2;
- high_i = 101;
- while (high_i > low_ip1) {
- mid_i = (low_i >> 1) + (high_i >> 1);
- if (((low_i & 1) == 1) && ((high_i & 1) == 1)) {
- mid_i++;
- }
- if (x[k] >= edges_data[mid_i - 1]) {
- low_i = mid_i;
- low_ip1 = mid_i + 1;
- } else {
- high_i = mid_i;
- }
- }
- ni_data[low_i - 1]++;
- }
- }
- }
- n_size[0] = 1;
- n_size[1] = 100;
- for (i = 0; i < 100; i++) {
- n_data[i] = ni_data[i];
- }
- }
- } // namespace coder
- //
- // File trailer for histcounts.cpp
- //
- // [EOF]
- //
|