123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // File: std.cpp
- //
- // MATLAB Coder version : 5.2
- // C/C++ source code generated on : 10-Mar-2023 11:08:29
- //
- // Include Files
- #include "fun8_2_std.h"
- #include "rt_nonfinite.h"
- #include "coder_array.h"
- #include <cmath>
- // Function Definitions
- //
- // Arguments : const ::coder::array<double, 2U> &x
- // Return Type : double
- //
- namespace coder {
- double b_std_8_2(const ::coder::array<double, 2U> &x)
- {
- array<double, 1U> absdiff;
- double y;
- int n;
- n = x.size(1);
- if (x.size(1) == 0) {
- y = rtNaN;
- } else if (x.size(1) == 1) {
- if ((!std::isinf(x[0])) && (!std::isnan(x[0]))) {
- y = 0.0;
- } else {
- y = rtNaN;
- }
- } else {
- double bsum;
- double xbar;
- int firstBlockLength;
- int k;
- int lastBlockLength;
- int nblocks;
- if (x.size(1) <= 1024) {
- firstBlockLength = x.size(1);
- lastBlockLength = 0;
- nblocks = 1;
- } else {
- firstBlockLength = 1024;
- nblocks = x.size(1) / 1024;
- lastBlockLength = x.size(1) - (nblocks << 10);
- if (lastBlockLength > 0) {
- nblocks++;
- } else {
- lastBlockLength = 1024;
- }
- }
- xbar = x[0];
- for (k = 2; k <= firstBlockLength; k++) {
- xbar += x[k - 1];
- }
- for (int ib{2}; ib <= nblocks; ib++) {
- int hi;
- firstBlockLength = (ib - 1) << 10;
- bsum = x[firstBlockLength];
- if (ib == nblocks) {
- hi = lastBlockLength;
- } else {
- hi = 1024;
- }
- for (k = 2; k <= hi; k++) {
- bsum += x[(firstBlockLength + k) - 1];
- }
- xbar += bsum;
- }
- xbar /= static_cast<double>(x.size(1));
- absdiff.set_size(x.size(1));
- for (k = 0; k < n; k++) {
- absdiff[k] = std::abs(x[k] - xbar);
- }
- n = x.size(1);
- y = 0.0;
- xbar = 3.3121686421112381E-170;
- for (k = 0; k < n; k++) {
- if (absdiff[k] > xbar) {
- bsum = xbar / absdiff[k];
- y = y * bsum * bsum + 1.0;
- xbar = absdiff[k];
- } else {
- bsum = absdiff[k] / xbar;
- y += bsum * bsum;
- }
- }
- y = xbar * std::sqrt(y);
- y /= std::sqrt(static_cast<double>(x.size(1)) - 1.0);
- }
- return y;
- }
- } // namespace coder
- //
- // File trailer for std.cpp
- //
- // [EOF]
- //
|