141 #include "allheaders.h" 172 l_float32 val1, val2;
174 PROCNAME(
"numaArithOp");
177 return (
NUMA *)ERROR_PTR(
"na1, na2 not both defined", procName, nad);
180 return (
NUMA *)ERROR_PTR(
"na1, na2 sizes differ", procName, nad);
181 if (nad && nad != na1)
182 return (
NUMA *)ERROR_PTR(
"nad defined but not in-place", procName, nad);
183 if (op != L_ARITH_ADD && op != L_ARITH_SUBTRACT &&
184 op != L_ARITH_MULTIPLY && op != L_ARITH_DIVIDE)
185 return (
NUMA *)ERROR_PTR(
"invalid op", procName, nad);
186 if (op == L_ARITH_DIVIDE) {
187 for (i = 0; i < n; i++) {
190 return (
NUMA *)ERROR_PTR(
"na2 has 0 element", procName, nad);
198 for (i = 0; i < n; i++) {
205 case L_ARITH_SUBTRACT:
208 case L_ARITH_MULTIPLY:
215 fprintf(stderr,
" Unknown arith op: %d\n", op);
251 l_int32 i, n, val1, val2, val;
253 PROCNAME(
"numaLogicalOp");
256 return (
NUMA *)ERROR_PTR(
"na1, na2 not both defined", procName, nad);
259 return (
NUMA *)ERROR_PTR(
"na1, na2 sizes differ", procName, nad);
260 if (nad && nad != na1)
261 return (
NUMA *)ERROR_PTR(
"nad defined; not in-place", procName, nad);
262 if (op != L_UNION && op != L_INTERSECTION &&
263 op != L_SUBTRACTION && op != L_EXCLUSIVE_OR)
264 return (
NUMA *)ERROR_PTR(
"invalid op", procName, nad);
270 for (i = 0; i < n; i++) {
273 val1 = (val1 == 0) ? 0 : 1;
274 val2 = (val2 == 0) ? 0 : 1;
277 val = (val1 || val2) ? 1 : 0;
281 val = (val1 && val2) ? 1 : 0;
285 val = (val1 && !val2) ? 1 : 0;
289 val = (val1 != val2) ? 1 : 0;
293 fprintf(stderr,
" Unknown logical op: %d\n", op);
324 PROCNAME(
"numaInvert");
327 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, nad);
328 if (nad && nad != nas)
329 return (
NUMA *)ERROR_PTR(
"nad defined; not in-place", procName, nad);
334 for (i = 0; i < n; i++) {
370 l_float32 val1, val2;
372 PROCNAME(
"numaSimilar");
375 return ERROR_INT(
"&similar not defined", procName, 1);
378 return ERROR_INT(
"na1 and na2 not both defined", procName, 1);
379 maxdiff = L_ABS(maxdiff);
384 for (i = 0; i < n; i++) {
387 if (L_ABS(val1 - val2) > maxdiff)
return 0;
419 PROCNAME(
"numaAddToNumber");
422 return ERROR_INT(
"na not defined", procName, 1);
424 if (index < 0 || index >= n)
425 return ERROR_INT(
"index not in {0...n - 1}", procName, 1);
427 na->
array[index] += val;
448 l_int32 i, n, iminloc;
449 l_float32 val, minval;
451 PROCNAME(
"numaGetMin");
453 if (!pminval && !piminloc)
454 return ERROR_INT(
"nothing to do", procName, 1);
455 if (pminval) *pminval = 0.0;
456 if (piminloc) *piminloc = 0;
458 return ERROR_INT(
"na not defined", procName, 1);
460 minval = +1000000000.;
463 for (i = 0; i < n; i++) {
471 if (pminval) *pminval = minval;
472 if (piminloc) *piminloc = iminloc;
490 l_int32 i, n, imaxloc;
491 l_float32 val, maxval;
493 PROCNAME(
"numaGetMax");
495 if (!pmaxval && !pimaxloc)
496 return ERROR_INT(
"nothing to do", procName, 1);
497 if (pmaxval) *pmaxval = 0.0;
498 if (pimaxloc) *pimaxloc = 0;
500 return ERROR_INT(
"na not defined", procName, 1);
502 maxval = -1000000000.;
505 for (i = 0; i < n; i++) {
513 if (pmaxval) *pmaxval = maxval;
514 if (pimaxloc) *pimaxloc = imaxloc;
533 PROCNAME(
"numaGetSum");
536 return ERROR_INT(
"na not defined", procName, 1);
538 return ERROR_INT(
"&sum not defined", procName, 1);
542 for (i = 0; i < n; i++) {
572 PROCNAME(
"numaGetPartialSums");
575 return (
NUMA *)ERROR_PTR(
"na not defined", procName, NULL);
580 for (i = 0; i < n; i++) {
604 l_int32 i, n, truelast;
607 PROCNAME(
"numaGetSumOnInterval");
610 return ERROR_INT(
"na not defined", procName, 1);
612 return ERROR_INT(
"&sum not defined", procName, 1);
619 truelast = L_MIN(last, n - 1);
621 for (i = first; i <= truelast; i++) {
652 PROCNAME(
"numaHasOnlyIntegers");
655 return ERROR_INT(
"&allints not defined", procName, 1);
658 return ERROR_INT(
"na not defined", procName, 1);
661 return ERROR_INT(
"na empty", procName, 1);
665 incr = (l_int32)((n + maxsamples - 1) / maxsamples);
666 for (i = 0; i < n; i += incr) {
668 if (val != (l_int32)val) {
693 PROCNAME(
"numaSubsample");
696 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
698 return (
NUMA *)ERROR_PTR(
"subfactor < 1", procName, NULL);
702 for (i = 0; i < n; i++) {
703 if (i % subfactor != 0)
continue;
722 l_int32 i, n, prev, cur;
725 PROCNAME(
"numaMakeDelta");
728 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
732 for (i = 1; i < n; i++) {
758 PROCNAME(
"numaMakeSequence");
761 return (
NUMA *)ERROR_PTR(
"na not made", procName, NULL);
763 for (i = 0; i < size; i++) {
764 val = startval + i * increment;
803 PROCNAME(
"numaMakeAbsValue");
806 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
807 if (nad && nad != nas)
808 return (
NUMA *)ERROR_PTR(
"nad and not in-place", procName, NULL);
813 for (i = 0; i < n; i++) {
815 nad->
array[i] = L_ABS(val);
838 l_float32 startx, delx;
839 l_float32 *fas, *fad;
842 PROCNAME(
"numaAddBorder");
845 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
846 if (left < 0) left = 0;
847 if (right < 0) right = 0;
848 if (left == 0 && right == 0)
852 len = n + left + right;
858 for (i = 0; i < n; i++)
859 fad[left + i] = fas[i];
884 PROCNAME(
"numaAddSpecifiedBorder");
887 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
888 if (left < 0) left = 0;
889 if (right < 0) right = 0;
890 if (left == 0 && right == 0)
893 return (
NUMA *)ERROR_PTR(
"invalid type", procName, NULL);
896 return (
NUMA *)ERROR_PTR(
"border too large", procName, NULL);
902 for (i = 0; i < left; i++)
904 for (i = n - right; i < n; i++)
905 fa[i] = fa[n - right - 1];
907 for (i = 0; i < left; i++)
908 fa[i] = fa[2 * left - 1 - i];
909 for (i = 0; i < right; i++)
910 fa[n - right + i] = fa[n - right - i - 1];
931 l_float32 startx, delx;
932 l_float32 *fas, *fad;
935 PROCNAME(
"numaRemoveBorder");
938 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
939 if (left < 0) left = 0;
940 if (right < 0) right = 0;
941 if (left == 0 && right == 0)
945 if ((len = n - left - right) < 0)
946 return (
NUMA *)ERROR_PTR(
"len < 0 after removal", procName, NULL);
952 for (i = 0; i < len; i++)
953 fad[i] = fas[left + i];
970 l_int32 n, i, val, count, inrun;
972 PROCNAME(
"numaCountNonzeroRuns");
975 return ERROR_INT(
"&count not defined", procName, 1);
978 return ERROR_INT(
"na not defined", procName, 1);
982 for (i = 0; i < n; i++) {
984 if (!inrun && val > 0) {
987 }
else if (inrun && val == 0) {
1011 l_int32 n, i, found;
1014 PROCNAME(
"numaGetNonzeroRange");
1016 if (pfirst) *pfirst = 0;
1017 if (plast) *plast = 0;
1018 if (!pfirst || !plast)
1019 return ERROR_INT(
"pfirst and plast not both defined", procName, 1);
1021 return ERROR_INT(
"na not defined", procName, 1);
1024 for (i = 0; i < n; i++) {
1038 for (i = n - 1; i >= 0; i--) {
1061 l_int32 n, i, count;
1064 PROCNAME(
"numaGetCountRelativeToZero");
1067 return ERROR_INT(
"&count not defined", procName, 1);
1070 return ERROR_INT(
"na not defined", procName, 1);
1072 for (i = 0, count = 0; i < n; i++) {
1109 l_int32 n, i, truelast;
1110 l_float32 val, startx, delx;
1113 PROCNAME(
"numaClipToInterval");
1116 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1118 return (
NUMA *)ERROR_PTR(
"range not valid", procName, NULL);
1122 return (
NUMA *)ERROR_PTR(
"no elements in range", procName, NULL);
1123 truelast = L_MIN(last, n - 1);
1124 if ((nad =
numaCreate(truelast - first + 1)) == NULL)
1125 return (
NUMA *)ERROR_PTR(
"nad not made", procName, NULL);
1126 for (i = first; i <= truelast; i++) {
1161 PROCNAME(
"numaMakeThresholdIndicator");
1164 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1167 for (i = 0; i < n; i++) {
1173 if (fval < thresh) ival = 1;
1176 if (fval > thresh) ival = 1;
1179 if (fval <= thresh) ival = 1;
1182 if (fval >= thresh) ival = 1;
1186 return (
NUMA *)ERROR_PTR(
"invalid type", procName, NULL);
1212 l_int32 n, i, j, ileft, iright;
1213 l_float32 left, right, binsize, lfract, rfract, sum, startx, delx;
1217 PROCNAME(
"numaUniformSampling");
1220 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1222 return (
NUMA *)ERROR_PTR(
"nsamp must be > 0", procName, NULL);
1227 binsize = (l_float32)n / (l_float32)nsamp;
1231 for (i = 0; i < nsamp; i++) {
1233 right = left + binsize;
1234 ileft = (l_int32)left;
1235 lfract = 1.0 - left + ileft;
1238 iright = (l_int32)right;
1239 rfract = right - iright;
1240 iright = L_MIN(iright, n - 1);
1241 if (ileft == iright) {
1242 sum += (lfract + rfract - 1.0) * array[ileft];
1244 if (lfract > 0.0001)
1245 sum += lfract * array[ileft];
1246 if (rfract > 0.0001)
1247 sum += rfract * array[iright];
1248 for (j = ileft + 1; j < iright; j++)
1278 l_float32 val1, val2;
1280 PROCNAME(
"numaReverse");
1283 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1284 if (nad && nas != nad)
1285 return (
NUMA *)ERROR_PTR(
"nad defined but != nas", procName, NULL);
1289 for (i = 0; i < n / 2; i++) {
1297 for (i = n - 1; i >= 0; i--) {
1333 l_int32 n, i, inrun;
1334 l_float32 maxval, threshval, fval, startx, delx, x0, x1;
1337 PROCNAME(
"numaLowPassIntervals");
1340 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1341 if (thresh < 0.0 || thresh > 1.0)
1342 return (
NUMA *)ERROR_PTR(
"invalid thresh", procName, NULL);
1352 threshval = thresh * maxval;
1358 for (i = 0; i < n; i++) {
1360 if (fval < threshval && inrun == FALSE) {
1362 x0 = startx + i * delx;
1363 }
else if (fval > threshval && inrun == TRUE) {
1365 x1 = startx + i * delx;
1370 if (inrun == TRUE) {
1371 x1 = startx + (n - 1) * delx;
1410 l_int32 n, i, istart, inband, output, sign;
1411 l_int32 startbelow, below, above, belowlast, abovelast;
1412 l_float32 maxval, threshval1, threshval2, fval, startx, delx, x0, x1;
1415 PROCNAME(
"numaThresholdEdges");
1418 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
1419 if (thresh1 < 0.0 || thresh1 > 1.0 || thresh2 < 0.0 || thresh2 > 1.0)
1420 return (
NUMA *)ERROR_PTR(
"invalid thresholds", procName, NULL);
1421 if (thresh2 < thresh1)
1422 return (
NUMA *)ERROR_PTR(
"thresh2 < thresh1", procName, NULL);
1434 threshval1 = thresh1 * maxval;
1435 threshval2 = thresh2 * maxval;
1442 for (i = 0; i < n; i++) {
1445 belowlast = (fval < threshval1) ? TRUE : FALSE;
1446 abovelast = (fval > threshval2) ? TRUE : FALSE;
1447 if (belowlast == TRUE || abovelast == TRUE)
1458 startbelow = belowlast;
1460 x0 = startx + istart * delx;
1461 for (i = istart + 1; i < n; i++) {
1463 below = (fval < threshval1) ? TRUE : FALSE;
1464 above = (fval > threshval2) ? TRUE : FALSE;
1465 if (!inband && belowlast && above) {
1466 x1 = startx + i * delx;
1470 }
else if (!inband && abovelast && below) {
1471 x1 = startx + i * delx;
1475 }
else if (inband && startbelow && above) {
1476 x1 = startx + i * delx;
1481 }
else if (inband && !startbelow && below) {
1483 x1 = startx + i * delx;
1488 }
else if (inband && !startbelow && above) {
1489 x0 = startx + i * delx;
1491 }
else if (inband && startbelow && below) {
1492 x0 = startx + i * delx;
1494 }
else if (!inband && !above && !below) {
1496 startbelow = belowlast;
1497 }
else if (!inband && (above || below)) {
1498 x0 = startx + i * delx;
1507 x0 = startx + i * delx;
1532 PROCNAME(
"numaGetSpanValues");
1535 return ERROR_INT(
"na not defined", procName, 1);
1538 return ERROR_INT(
"n is not odd", procName, 1);
1540 if (nspans < 0 || span >= nspans)
1541 return ERROR_INT(
"invalid span", procName, 1);
1569 PROCNAME(
"numaGetEdgeValues");
1572 return ERROR_INT(
"na not defined", procName, 1);
1575 return ERROR_INT(
"n % 3 is not 1", procName, 1);
1576 nedges = (n - 1) / 3;
1577 if (edge < 0 || edge >= nedges)
1578 return ERROR_INT(
"invalid edge", procName, 1);
1625 l_int32 i, n, i1, i2, i3;
1626 l_float32 x1, x2, x3, fy1, fy2, fy3, d1, d2, d3, del, fi, maxx;
1629 PROCNAME(
"numaInterpolateEqxVal");
1632 return ERROR_INT(
"&yval not defined", procName, 1);
1635 return ERROR_INT(
"nay not defined", procName, 1);
1637 return ERROR_INT(
"deltax not > 0", procName, 1);
1639 return ERROR_INT(
"invalid interp type", procName, 1);
1642 return ERROR_INT(
"not enough points", procName, 1);
1645 L_WARNING(
"only 2 points; using linear interp\n", procName);
1647 maxx = startx + deltax * (n - 1);
1648 if (xval < startx || xval > maxx)
1649 return ERROR_INT(
"xval is out of bounds", procName, 1);
1652 fi = (xval - startx) / deltax;
1661 *pyval = fa[i] + del * (fa[i + 1] - fa[i]);
1666 d1 = d3 = 0.5 / (deltax * deltax);
1677 x1 = startx + i1 * deltax;
1678 x2 = startx + i2 * deltax;
1679 x3 = startx + i3 * deltax;
1683 *pyval = fy1 * (xval - x2) * (xval - x3) +
1684 fy2 * (xval - x1) * (xval - x3) +
1685 fy3 * (xval - x1) * (xval - x2);
1717 l_int32 i, im, nx, ny, i1, i2, i3;
1718 l_float32 delu, dell, fract, d1, d2, d3;
1719 l_float32 minx, maxx;
1720 l_float32 *fax, *fay;
1722 PROCNAME(
"numaInterpolateArbxVal");
1725 return ERROR_INT(
"&yval not defined", procName, 1);
1728 return ERROR_INT(
"nax not defined", procName, 1);
1730 return ERROR_INT(
"nay not defined", procName, 1);
1732 return ERROR_INT(
"invalid interp type", procName, 1);
1736 return ERROR_INT(
"nax and nay not same size arrays", procName, 1);
1738 return ERROR_INT(
"not enough points", procName, 1);
1741 L_WARNING(
"only 2 points; using linear interp\n", procName);
1745 if (xval < minx || xval > maxx)
1746 return ERROR_INT(
"xval is out of bounds", procName, 1);
1754 if (xval == fax[0]) {
1760 for (i = 1; i < nx; i++) {
1761 delu = fax[i] - xval;
1768 dell = xval - fax[im];
1772 fract = dell / (fax[i] - fax[im]);
1775 *pyval = fay[i] + fract * (fay[i + 1] - fay[i]);
1789 d1 = (fax[i1] - fax[i2]) * (fax[i1] - fax[i3]);
1790 d2 = (fax[i2] - fax[i1]) * (fax[i2] - fax[i3]);
1791 d3 = (fax[i3] - fax[i1]) * (fax[i3] - fax[i2]);
1792 *pyval = fay[i1] * (xval - fax[i2]) * (xval - fax[i3]) / d1 +
1793 fay[i2] * (xval - fax[i1]) * (xval - fax[i3]) / d2 +
1794 fay[i3] * (xval - fax[i1]) * (xval - fax[i2]) / d3;
1839 l_float32 x, yval, maxx, delx;
1842 PROCNAME(
"numaInterpolateEqxInterval");
1844 if (pnax) *pnax = NULL;
1846 return ERROR_INT(
"&nay not defined", procName, 1);
1849 return ERROR_INT(
"nasy not defined", procName, 1);
1851 return ERROR_INT(
"deltax not > 0", procName, 1);
1853 return ERROR_INT(
"invalid interp type", procName, 1);
1857 L_WARNING(
"only 2 points; using linear interp\n", procName);
1859 maxx = startx + deltax * (n - 1);
1860 if (x0 < startx || x1 > maxx || x1 <= x0)
1861 return ERROR_INT(
"[x0 ... x1] is not valid", procName, 1);
1863 return ERROR_INT(
"npts < 3", procName, 1);
1864 delx = (x1 - x0) / (l_float32)(npts - 1);
1867 return ERROR_INT(
"nay not made", procName, 1);
1875 for (i = 0; i < npts; i++) {
1925 l_int32 i, im, j, nx, ny, i1, i2, i3, sorted;
1927 l_float32 del, xval, yval, excess, fract, minx, maxx, d1, d2, d3;
1928 l_float32 *fax, *fay;
1929 NUMA *nasx, *nasy, *nadx, *nady;
1931 PROCNAME(
"numaInterpolateArbxInterval");
1933 if (pnadx) *pnadx = NULL;
1935 return ERROR_INT(
"&nady not defined", procName, 1);
1938 return ERROR_INT(
"nay not defined", procName, 1);
1940 return ERROR_INT(
"nax not defined", procName, 1);
1942 return ERROR_INT(
"invalid interp type", procName, 1);
1944 return ERROR_INT(
"x0 > x1", procName, 1);
1948 return ERROR_INT(
"nax and nay not same size arrays", procName, 1);
1950 return ERROR_INT(
"not enough points", procName, 1);
1953 L_WARNING(
"only 2 points; using linear interp\n", procName);
1957 if (x0 < minx || x1 > maxx)
1958 return ERROR_INT(
"xval is out of bounds", procName, 1);
1963 L_WARNING(
"we are sorting nax in increasing order\n", procName);
1974 if ((index = (l_int32 *)LEPT_CALLOC(npts,
sizeof(l_int32))) == NULL) {
1977 return ERROR_INT(
"ind not made", procName, 1);
1979 del = (x1 - x0) / (npts - 1.0);
1980 for (i = 0, j = 0; j < nx && i < npts; i++) {
1981 xval = x0 + i * del;
1982 while (j < nx - 1 && xval > fax[j])
1985 index[i] = L_MIN(j, nx - 1);
1987 index[i] = L_MAX(j - 1, 0);
1997 for (i = 0; i < npts; i++) {
1998 xval = x0 + i * del;
2002 excess = xval - fax[im];
2003 if (excess == 0.0) {
2007 fract = excess / (fax[im + 1] - fax[im]);
2010 yval = fay[im] + fract * (fay[im + 1] - fay[im]);
2025 d1 = (fax[i1] - fax[i2]) * (fax[i1] - fax[i3]);
2026 d2 = (fax[i2] - fax[i1]) * (fax[i2] - fax[i3]);
2027 d3 = (fax[i3] - fax[i1]) * (fax[i3] - fax[i2]);
2028 yval = fay[i1] * (xval - fax[i2]) * (xval - fax[i3]) / d1 +
2029 fay[i2] * (xval - fax[i1]) * (xval - fax[i3]) / d2 +
2030 fay[i3] * (xval - fax[i1]) * (xval - fax[i2]) / d3;
2085 l_float32 x1, x2, x3, y1, y2, y3, c1, c2, c3, a, b, xmax, ymax;
2087 PROCNAME(
"numaFitMax");
2089 if (pmaxval) *pmaxval = 0.0;
2090 if (pmaxloc) *pmaxloc = 0.0;
2092 return ERROR_INT(
"na not defined", procName, 1);
2094 return ERROR_INT(
"&maxval not defined", procName, 1);
2096 return ERROR_INT(
"&maxloc not defined", procName, 1);
2101 return ERROR_INT(
"na and naloc of unequal size", procName, 1);
2106 if (imaxloc == 0 || imaxloc == n - 1) {
2138 if (x1 == x2 || x1 == x3 || x2 == x3) {
2145 c1 = y1 / ((x1 - x2) * (x1 - x3));
2146 c2 = y2 / ((x2 - x1) * (x2 - x3));
2147 c3 = y3 / ((x3 - x1) * (x3 - x2));
2149 b = c1 * (x2 + x3) + c2 * (x1 + x3) + c3 * (x1 + x2);
2151 ymax = c1 * (xmax - x2) * (xmax - x3) +
2152 c2 * (xmax - x1) * (xmax - x3) +
2153 c3 * (xmax - x1) * (xmax - x2);
2191 l_float32 minx, maxx, der, invdel;
2195 PROCNAME(
"numaDifferentiateInterval");
2197 if (pnadx) *pnadx = NULL;
2199 return ERROR_INT(
"&nady not defined", procName, 1);
2202 return ERROR_INT(
"nay not defined", procName, 1);
2204 return ERROR_INT(
"nax not defined", procName, 1);
2206 return ERROR_INT(
"x0 > x1", procName, 1);
2210 return ERROR_INT(
"nax and nay not same size arrays", procName, 1);
2212 return ERROR_INT(
"not enough points", procName, 1);
2215 if (x0 < minx || x1 > maxx)
2216 return ERROR_INT(
"xval is out of bounds", procName, 1);
2218 return ERROR_INT(
"npts < 2", procName, 1);
2222 npts, pnadx, &naiy))
2223 return ERROR_INT(
"interpolation failed", procName, 1);
2227 invdel = 0.5 * ((l_float32)npts - 1.0) / (x1 - x0);
2231 der = 0.5 * invdel * (fay[1] - fay[0]);
2233 for (i = 1; i < npts - 1; i++) {
2234 der = invdel * (fay[i + 1] - fay[i - 1]);
2237 der = 0.5 * invdel * (fay[npts - 1] - fay[npts - 2]);
2273 l_float32 minx, maxx, sum, del;
2277 PROCNAME(
"numaIntegrateInterval");
2280 return ERROR_INT(
"&sum not defined", procName, 1);
2283 return ERROR_INT(
"nay not defined", procName, 1);
2285 return ERROR_INT(
"nax not defined", procName, 1);
2287 return ERROR_INT(
"x0 > x1", procName, 1);
2289 return ERROR_INT(
"npts < 2", procName, 1);
2293 return ERROR_INT(
"nax and nay not same size arrays", procName, 1);
2295 return ERROR_INT(
"not enough points", procName, 1);
2298 if (x0 < minx || x1 > maxx)
2299 return ERROR_INT(
"xval is out of bounds", procName, 1);
2304 return ERROR_INT(
"interpolation failed", procName, 1);
2306 del = (x1 - x0) / ((l_float32)npts - 1.0);
2310 sum = 0.5 * (fay[0] + fay[npts - 1]);
2311 for (i = 1; i < npts - 1; i++)
2379 PROCNAME(
"numaSortGeneral");
2382 return ERROR_INT(
"na not defined", procName, 1);
2384 return ERROR_INT(
"invalid sort order", procName, 1);
2386 return ERROR_INT(
"invalid sort type", procName, 1);
2387 if (!pnasort && !pnaindex && !pnainvert)
2388 return ERROR_INT(
"nothing to do", procName, 1);
2389 if (pnasort) *pnasort = NULL;
2390 if (pnaindex) *pnaindex = NULL;
2391 if (pnainvert) *pnainvert = NULL;
2403 *pnaindex = naindex;
2429 PROCNAME(
"numaSortAutoSelect");
2432 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2434 return (
NUMA *)ERROR_PTR(
"invalid sort order", procName, NULL);
2438 return numaSort(NULL, nas, sortorder);
2442 return (
NUMA *)ERROR_PTR(
"invalid sort type", procName, NULL);
2465 PROCNAME(
"numaSortIndexAutoSelect");
2468 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2470 return (
NUMA *)ERROR_PTR(
"invalid sort order", procName, NULL);
2478 return (
NUMA *)ERROR_PTR(
"invalid sort type", procName, NULL);
2499 l_float32 minval, maxval;
2501 PROCNAME(
"numaChooseSortType");
2504 return ERROR_INT(
"nas not defined", procName, UNDEF);
2510 if (minval < 0.0 || n < 200) {
2511 L_INFO(
"Shell sort chosen\n", procName);
2520 if (n * log((l_float32)n) < 0.003 * maxval) {
2522 L_INFO(
"Shell sort chosen\n", procName);
2525 L_INFO(
"Bin sort chosen\n", procName);
2551 l_int32 i, n, gap, j;
2555 PROCNAME(
"numaSort");
2558 return (
NUMA *)ERROR_PTR(
"nain not defined", procName, NULL);
2560 return (
NUMA *)ERROR_PTR(
"invalid sort order", procName, NULL);
2565 else if (nain != naout)
2566 return (
NUMA *)ERROR_PTR(
"invalid: not in-place", procName, NULL);
2567 array = naout->
array;
2571 for (gap = n/2; gap > 0; gap = gap / 2) {
2572 for (i = gap; i < n; i++) {
2573 for (j = i - gap; j >= 0; j -= gap) {
2575 array[j] > array[j + gap]) ||
2577 array[j] < array[j + gap]))
2580 array[j] = array[j + gap];
2581 array[j + gap] = tmp;
2614 PROCNAME(
"numaBinSort");
2617 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2619 return (
NUMA *)ERROR_PTR(
"invalid sort order", procName, NULL);
2640 l_int32 i, n, gap, j;
2646 PROCNAME(
"numaGetSortIndex");
2649 return (
NUMA *)ERROR_PTR(
"na not defined", procName, NULL);
2651 return (
NUMA *)ERROR_PTR(
"invalid sortorder", procName, NULL);
2655 return (
NUMA *)ERROR_PTR(
"array not made", procName, NULL);
2656 if ((iarray = (l_float32 *)LEPT_CALLOC(n,
sizeof(l_float32))) == NULL) {
2658 return (
NUMA *)ERROR_PTR(
"iarray not made", procName, NULL);
2660 for (i = 0; i < n; i++)
2664 for (gap = n/2; gap > 0; gap = gap / 2) {
2665 for (i = gap; i < n; i++) {
2666 for (j = i - gap; j >= 0; j -= gap) {
2668 array[j] > array[j + gap]) ||
2670 array[j] < array[j + gap]))
2673 array[j] = array[j + gap];
2674 array[j + gap] = tmp;
2676 iarray[j] = iarray[j + gap];
2677 iarray[j + gap] = tmp;
2684 for (i = 0; i < n; i++)
2716 l_int32 i, n, isize, ival, imax;
2718 NUMA *na, *nai, *nad;
2721 PROCNAME(
"numaGetBinSortIndex");
2724 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2726 return (
NUMA *)ERROR_PTR(
"invalid sort order", procName, NULL);
2737 isize = (l_int32)size;
2738 if (isize > 1000000)
2739 L_WARNING(
"large array: %d elements\n", procName, isize);
2742 for (i = 0; i < n; i++) {
2758 for (i = 0; i <= imax; i++) {
2765 for (i = imax; i >= 0; i--) {
2789 l_int32 i, n, index;
2793 PROCNAME(
"numaSortByIndex");
2796 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2798 return (
NUMA *)ERROR_PTR(
"naindex not defined", procName, NULL);
2802 for (i = 0; i < n; i++) {
2833 l_float32 prevval, val;
2835 PROCNAME(
"numaIsSorted");
2838 return ERROR_INT(
"&sorted not defined", procName, 1);
2841 return ERROR_INT(
"nas not defined", procName, 1);
2843 return ERROR_INT(
"invalid sortorder", procName, 1);
2847 for (i = 1; i < n; i++) {
2884 PROCNAME(
"numaSortPair");
2886 if (pnasx) *pnasx = NULL;
2887 if (pnasy) *pnasy = NULL;
2888 if (!pnasx || !pnasy)
2889 return ERROR_INT(
"&nasx and/or &nasy not defined", procName, 1);
2891 return ERROR_INT(
"nax not defined", procName, 1);
2893 return ERROR_INT(
"nay not defined", procName, 1);
2895 return ERROR_INT(
"invalid sortorder", procName, 1);
2898 if (sorted == TRUE) {
2928 l_int32 i, n, val, error;
2932 PROCNAME(
"numaInvertMap");
2935 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
2939 test = (l_int32 *)LEPT_CALLOC(n,
sizeof(l_int32));
2941 for (i = 0; i < n; i++) {
2948 if (test[val] == 0) {
2959 return (
NUMA *)ERROR_PTR(
"nas not invertible", procName, NULL);
2988 l_int32 i, index, temp;
2992 PROCNAME(
"numaPseudorandomSequence");
2995 return (
NUMA *)ERROR_PTR(
"size <= 0", procName, NULL);
2997 if ((array = (l_int32 *)LEPT_CALLOC(size,
sizeof(l_int32))) == NULL)
2998 return (
NUMA *)ERROR_PTR(
"array not made", procName, NULL);
2999 for (i = 0; i < size; i++)
3002 for (i = size - 1; i > 0; i--) {
3003 index = (l_int32)((i + 1) * ((l_float64)rand() / (l_float64)RAND_MAX));
3004 index = L_MIN(index, i);
3006 array[i] = array[index];
3007 array[index] = temp;
3027 l_int32 i, index, size;
3029 NUMA *naindex, *nad;
3031 PROCNAME(
"numaRandomPermutation");
3034 return (
NUMA *)ERROR_PTR(
"nas not defined", procName, NULL);
3039 for (i = 0; i < size; i++) {
3090 PROCNAME(
"numaGetRankValue");
3093 return ERROR_INT(
"&val not defined", procName, 1);
3096 return ERROR_INT(
"na not defined", procName, 1);
3097 if (fract < 0.0 || fract > 1.0)
3098 return ERROR_INT(
"fract not in [0.0 ... 1.0]", procName, 1);
3101 return ERROR_INT(
"na empty", procName, 1);
3111 return ERROR_INT(
"nas not made", procName, 1);
3113 index = (l_int32)(fract * (l_float32)(n - 1) + 0.5);
3138 PROCNAME(
"numaGetMedian");
3141 return ERROR_INT(
"&val not defined", procName, 1);
3144 return ERROR_INT(
"na not defined", procName, 1);
3172 PROCNAME(
"numaGetBinnedMedian");
3175 return ERROR_INT(
"&val not defined", procName, 1);
3178 return ERROR_INT(
"na not defined", procName, 1);
3202 PROCNAME(
"numaGetMeanDevFromMedian");
3205 return ERROR_INT(
"&dev not defined", procName, 1);
3208 return ERROR_INT(
"na not defined", procName, 1);
3210 return ERROR_INT(
"na is empty", procName, 1);
3213 for (i = 0; i < n; i++) {
3215 dev += L_ABS(val - med);
3217 *pdev = dev / (l_float32)n;
3249 PROCNAME(
"numaGetMedianDevFromMedian");
3251 if (pmed) *pmed = 0.0;
3253 return ERROR_INT(
"&dev not defined", procName, 1);
3256 return ERROR_INT(
"na not defined", procName, 1);
3259 if (pmed) *pmed = med;
3262 for (i = 0; i < n; i++) {
3294 l_int32 i, n, maxcount, prevcount;
3295 l_float32 val, maxval, prevval;
3299 PROCNAME(
"numaGetMode");
3301 if (pcount) *pcount = 0;
3303 return ERROR_INT(
"&val not defined", procName, 1);
3306 return ERROR_INT(
"na not defined", procName, 1);
3311 return ERROR_INT(
"nas not made", procName, 1);
3318 maxcount = prevcount;
3321 for (i = 1; i < n; i++) {
3323 if (val == prevval) {
3326 if (prevcount > maxcount) {
3327 maxcount = prevcount;
3336 if (prevcount > maxcount) {
3337 maxcount = prevcount;
3378 PROCNAME(
"numaJoin");
3381 return ERROR_INT(
"nad not defined", procName, 1);
3388 if (iend < 0 || iend >= n)
3391 return ERROR_INT(
"istart > iend; nothing to add", procName, 1);
3393 for (i = istart; i <= iend; i++) {
3427 PROCNAME(
"numaaJoin");
3430 return ERROR_INT(
"naad not defined", procName, 1);
3437 if (iend < 0 || iend >= n)
3440 return ERROR_INT(
"istart > iend; nothing to add", procName, 1);
3442 for (i = istart; i <= iend; i++) {
3473 PROCNAME(
"numaaFlattenToNuma");
3476 return (
NUMA *)ERROR_PTR(
"naa not defined", procName, NULL);
3481 for (i = 0; i < nalloc; i++) {
l_ok numaGetSum(NUMA *na, l_float32 *psum)
numaGetSum()
NUMA * numaInvertMap(NUMA *nas)
numaInvertMap()
NUMA * numaBinSort(NUMA *nas, l_int32 sortorder)
numaBinSort()
void * ptraGetPtrToItem(L_PTRA *pa, l_int32 index)
ptraGetPtrToItem()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
l_ok numaFitMax(NUMA *na, l_float32 *pmaxval, NUMA *naloc, l_float32 *pmaxloc)
numaFitMax()
l_ok numaAddToNumber(NUMA *na, l_int32 index, l_float32 val)
numaAddToNumber()
NUMA * numaLowPassIntervals(NUMA *nas, l_float32 thresh, l_float32 maxn)
numaLowPassIntervals()
l_ok numaHasOnlyIntegers(NUMA *na, l_int32 maxsamples, l_int32 *pallints)
numaHasOnlyIntegers()
NUMA * numaGetSortIndex(NUMA *na, l_int32 sortorder)
numaGetSortIndex()
NUMA * numaSortAutoSelect(NUMA *nas, l_int32 sortorder)
numaSortAutoSelect()
l_ok numaInterpolateEqxVal(l_float32 startx, l_float32 deltax, NUMA *nay, l_int32 type, l_float32 xval, l_float32 *pyval)
numaInterpolateEqxVal()
l_int32 lept_roundftoi(l_float32 fval)
lept_roundftoi()
NUMA * numaReverse(NUMA *nad, NUMA *nas)
numaReverse()
NUMA ** numaaGetPtrArray(NUMAA *naa)
numaaGetPtrArray()
NUMA * numaSortByIndex(NUMA *nas, NUMA *naindex)
numaSortByIndex()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaRandomPermutation(NUMA *nas, l_int32 seed)
numaRandomPermutation()
l_ok numaSortPair(NUMA *nax, NUMA *nay, l_int32 sortorder, NUMA **pnasx, NUMA **pnasy)
numaSortPair()
NUMA * numaaFlattenToNuma(NUMAA *naa)
numaaFlattenToNuma()
l_ok numaGetNonzeroRange(NUMA *na, l_float32 eps, l_int32 *pfirst, l_int32 *plast)
numaGetNonzeroRange()
NUMA * numaGetBinSortIndex(NUMA *nas, l_int32 sortorder)
numaGetBinSortIndex()
l_int32 numaIsSorted(NUMA *nas, l_int32 sortorder, l_int32 *psorted)
numaIsSorted()
l_ok numaGetMedian(NUMA *na, l_float32 *pval)
numaGetMedian()
l_ok numaGetCountRelativeToZero(NUMA *na, l_int32 type, l_int32 *pcount)
numaGetCountRelativeToZero()
NUMA * numaMakeConstant(l_float32 val, l_int32 size)
numaMakeConstant()
l_ok numaIntegrateInterval(NUMA *nax, NUMA *nay, l_float32 x0, l_float32 x1, l_int32 npts, l_float32 *psum)
numaIntegrateInterval()
NUMA * numaSort(NUMA *naout, NUMA *nain, l_int32 sortorder)
numaSort()
l_int32 numaChooseSortType(NUMA *nas)
numaChooseSortType()
l_ok numaCountNonzeroRuns(NUMA *na, l_int32 *pcount)
numaCountNonzeroRuns()
NUMA * numaCreate(l_int32 n)
numaCreate()
NUMA * numaThresholdEdges(NUMA *nas, l_float32 thresh1, l_float32 thresh2, l_float32 maxn)
numaThresholdEdges()
void * ptraRemoveLast(L_PTRA *pa)
ptraRemoveLast()
l_int32 numaGetSpanValues(NUMA *na, l_int32 span, l_int32 *pstart, l_int32 *pend)
numaGetSpanValues()
NUMA * numaClipToInterval(NUMA *nas, l_int32 first, l_int32 last)
numaClipToInterval()
NUMA * numaGetPartialSums(NUMA *na)
numaGetPartialSums()
NUMA * numaSubsample(NUMA *nas, l_int32 subfactor)
numaSubsample()
NUMA * numaRemoveBorder(NUMA *nas, l_int32 left, l_int32 right)
numaRemoveBorder()
l_ok numaSetValue(NUMA *na, l_int32 index, l_float32 val)
numaSetValue()
l_ok ptraInsert(L_PTRA *pa, l_int32 index, void *item, l_int32 shiftflag)
ptraInsert()
NUMA * numaUniformSampling(NUMA *nas, l_int32 nsamp)
numaUniformSampling()
NUMA * numaArithOp(NUMA *nad, NUMA *na1, NUMA *na2, l_int32 op)
numaArithOp()
NUMA * numaMakeAbsValue(NUMA *nad, NUMA *nas)
numaMakeAbsValue()
NUMA * numaPseudorandomSequence(l_int32 size, l_int32 seed)
numaPseudorandomSequence()
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
NUMA * numaMakeDelta(NUMA *nas)
numaMakeDelta()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok numaDifferentiateInterval(NUMA *nax, NUMA *nay, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnadx, NUMA **pnady)
numaDifferentiateInterval()
L_PTRA * ptraCreate(l_int32 n)
ptraCreate()
l_ok numaInterpolateArbxVal(NUMA *nax, NUMA *nay, l_int32 type, l_float32 xval, l_float32 *pyval)
numaInterpolateArbxVal()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetMeanDevFromMedian(NUMA *na, l_float32 med, l_float32 *pdev)
numaGetMeanDevFromMedian()
l_ok numaGetMode(NUMA *na, l_float32 *pval, l_int32 *pcount)
numaGetMode()
l_ok ptraGetMaxIndex(L_PTRA *pa, l_int32 *pmaxindex)
ptraGetMaxIndex()
l_ok numaInterpolateEqxInterval(l_float32 startx, l_float32 deltax, NUMA *nasy, l_int32 type, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnax, NUMA **pnay)
numaInterpolateEqxInterval()
NUMA * numaMakeThresholdIndicator(NUMA *nas, l_float32 thresh, l_int32 type)
numaMakeThresholdIndicator()
l_ok numaSetParameters(NUMA *na, l_float32 startx, l_float32 delx)
numaSetParameters()
l_int32 numaGetEdgeValues(NUMA *na, l_int32 edge, l_int32 *pstart, l_int32 *pend, l_int32 *psign)
numaGetEdgeValues()
l_ok numaInterpolateArbxInterval(NUMA *nax, NUMA *nay, l_int32 type, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnadx, NUMA **pnady)
numaInterpolateArbxInterval()
NUMA * numaAddSpecifiedBorder(NUMA *nas, l_int32 left, l_int32 right, l_int32 type)
numaAddSpecifiedBorder()
l_ok numaGetParameters(NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
numaGetParameters()
NUMA * numaCreateFromIArray(l_int32 *iarray, l_int32 size)
numaCreateFromIArray()
NUMA * numaMakeSequence(l_float32 startval, l_float32 increment, l_int32 size)
numaMakeSequence()
l_ok numaSortGeneral(NUMA *na, NUMA **pnasort, NUMA **pnaindex, NUMA **pnainvert, l_int32 sortorder, l_int32 sorttype)
numaSortGeneral()
NUMA * numaCopy(NUMA *na)
numaCopy()
NUMA * numaAddBorder(NUMA *nas, l_int32 left, l_int32 right, l_float32 val)
numaAddBorder()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok numaGetMin(NUMA *na, l_float32 *pminval, l_int32 *piminloc)
numaGetMin()
void ptraDestroy(L_PTRA **ppa, l_int32 freeflag, l_int32 warnflag)
ptraDestroy()
l_ok numaaJoin(NUMAA *naad, NUMAA *naas, l_int32 istart, l_int32 iend)
numaaJoin()
l_ok numaJoin(NUMA *nad, NUMA *nas, l_int32 istart, l_int32 iend)
numaJoin()
l_float32 * numaGetFArray(NUMA *na, l_int32 copyflag)
numaGetFArray()
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
void * ptraRemove(L_PTRA *pa, l_int32 index, l_int32 flag)
ptraRemove()
NUMA * numaLogicalOp(NUMA *nad, NUMA *na1, NUMA *na2, l_int32 op)
numaLogicalOp()
NUMA * numaSortIndexAutoSelect(NUMA *nas, l_int32 sortorder)
numaSortIndexAutoSelect()
l_ok numaGetMedianDevFromMedian(NUMA *na, l_float32 *pmed, l_float32 *pdev)
numaGetMedianDevFromMedian()
l_ok numaReplaceNumber(NUMA *na, l_int32 index, l_float32 val)
numaReplaceNumber()
NUMA * numaClone(NUMA *na)
numaClone()
l_int32 numaSimilar(NUMA *na1, NUMA *na2, l_float32 maxdiff, l_int32 *psimilar)
numaSimilar()
l_ok numaGetMax(NUMA *na, l_float32 *pmaxval, l_int32 *pimaxloc)
numaGetMax()
l_ok numaGetBinnedMedian(NUMA *na, l_int32 *pval)
numaGetBinnedMedian()
NUMA * numaInvert(NUMA *nad, NUMA *nas)
numaInvert()
l_ok numaGetSumOnInterval(NUMA *na, l_int32 first, l_int32 last, l_float32 *psum)
numaGetSumOnInterval()
l_ok numaGetRankValue(NUMA *na, l_float32 fract, NUMA *nasort, l_int32 usebins, l_float32 *pval)
numaGetRankValue()
l_ok numaaAddNuma(NUMAA *naa, NUMA *na, l_int32 copyflag)
numaaAddNuma()