sqlmath 2025.2.28__tar.gz → 2025.3.31__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.ci.sh +4 -3
  2. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/CHANGELOG.md +6 -0
  3. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/PKG-INFO +8 -8
  4. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/README.md +7 -7
  5. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/jslint.mjs +1 -1
  6. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/jslint_ci.sh +1 -0
  7. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/package.json +1 -1
  8. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/pyproject.toml +1 -1
  9. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/setup.py +2 -2
  10. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath/__init__.py +2 -2
  11. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath.mjs +1 -1
  12. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_base.c +141 -121
  13. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_external_sqlite.c +4221 -2704
  14. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.gitconfig +0 -0
  15. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.github/workflows/ci.yml +0 -0
  16. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.github/workflows/publish.yml +0 -0
  17. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.github/workflows/publish_pypi_test.yml +0 -0
  18. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.gitignore +0 -0
  19. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/.npmignore +0 -0
  20. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/LICENSE +0 -0
  21. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/MANIFEST.in +0 -0
  22. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_image_folder_open_solid.svg +0 -0
  23. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_image_github_brands.svg +0 -0
  24. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_image_logo_256.html +0 -0
  25. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_image_logo_256.png +0 -0
  26. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_image_logo_256.svg +0 -0
  27. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/asset_sqlmath_external_rollup.js +0 -0
  28. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/cpplint.py +0 -0
  29. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/csslint.js +0 -0
  30. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/indent.exe +0 -0
  31. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/index.html +0 -0
  32. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/libiconv2.dll +0 -0
  33. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/libintl3.dll +0 -0
  34. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_base.h +0 -0
  35. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_browser.mjs +0 -0
  36. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_custom.c +0 -0
  37. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_custom.mjs +0 -0
  38. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_external_zlib.c +0 -0
  39. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/sqlmath_wrapper_wasm.js +0 -0
  40. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test.mjs +0 -0
  41. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test.py +0 -0
  42. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test_data_sinefit.csv +0 -0
  43. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test_lgbm.py +0 -0
  44. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test_lgbm_binary.test +0 -0
  45. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test_lgbm_binary.train +0 -0
  46. {sqlmath-2025.2.28 → sqlmath-2025.3.31}/test_lgbm_preb.txt +0 -0
@@ -87,6 +87,7 @@ process.stdout.write(
87
87
  # install graphicsmagick
88
88
  if (! command -v gm >/dev/null)
89
89
  then
90
+ sudo apt-get update
90
91
  sudo apt-get install -y graphicsmagick
91
92
  fi
92
93
  # mkdir .artifact/
@@ -513,16 +514,16 @@ shSqlmathUpdate() {(set -e
513
514
  if [ "$PWD/" = "$HOME/Documents/sqlmath/" ]
514
515
  then
515
516
  # shRollupFetch
516
- if [ ! -d .sqlite-autoconf-3470200 ]
517
+ if [ ! -d .sqlite-autoconf-3490100 ]
517
518
  then
518
519
  for URL in \
519
520
  https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz \
520
- https://www.sqlite.org/2024/sqlite-autoconf-3470200.tar.gz
521
+ https://www.sqlite.org/2025/sqlite-autoconf-3490100.tar.gz
521
522
  do
522
523
  curl -L "$URL" | tar -xz
523
524
  done
524
525
  for DIR in \
525
- sqlite-autoconf-3470200 \
526
+ sqlite-autoconf-3490100 \
526
527
  zlib-1.3.1
527
528
  do
528
529
  rm -rf ".$DIR"
@@ -1,9 +1,15 @@
1
1
  # Changelog
2
2
 
3
3
  # Todo
4
+ - sqlmath - Re-introduce sliding-discrete-fourier-transform to improve initial guess in sql-function WIN_SINEFIT2().
4
5
  - sqlite - Add similar error-handling from builtin-sql-function PERCENTILE() into custom-sql-function QUANTILE().
5
6
  - none
6
7
 
8
+ # v2025.3.31
9
+ - ubuntu-ci - bugfix - Fix out-of-date apt-list when installing graphicsmagick.
10
+ - sqlite - Upgrade to sqlite-v3.49.1.
11
+ - Cleanup sql-functions ZLIB_COMPRESS(), ZLIB_UNCOMPRESS().
12
+
7
13
  # v2025.2.28
8
14
  - sqlmath - Update sql-function SHA256() to use tinycrypt.
9
15
  - jslint - Update shell-function shDirHttplinkValidate() with pragma <\!!--novalidate--\>.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlmath
3
- Version: 2025.2.28
3
+ Version: 2025.3.31
4
4
  Summary: sqlite for datascience
5
5
  Author: Kai Zhu
6
6
  Requires-Python: >=3.10
@@ -27,7 +27,7 @@ Description-Content-Type: text/markdown
27
27
 
28
28
 
29
29
  # Status
30
- | Branch | [master<br>(v2025.2.28)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
30
+ | Branch | [master<br>(v2025.3.31)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
31
31
  |--:|:--:|:--:|:--:|
32
32
  | CI | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Amaster) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=beta)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Abeta) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=alpha)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Aalpha) |
33
33
  | Coverage | [![coverage](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/index.html) |
@@ -146,11 +146,11 @@ PORT=8080 sh jslint_ci.sh shHttpFileServer
146
146
  ```shell
147
147
  python -m build
148
148
  #
149
- twine upload --repository testpypi dist/sqlmath-2025.2.28*
150
- py -m pip install --index-url https://test.pypi.org/simple/ sqlmath==2025.2.28
149
+ twine upload --repository testpypi dist/sqlmath-2025.3.31*
150
+ py -m pip install --index-url https://test.pypi.org/simple/ sqlmath==2025.3.31
151
151
  #
152
- twine upload dist/sqlmath-2025.2.28*
153
- pip install sqlmath==2025.2.28
152
+ twine upload dist/sqlmath-2025.3.31*
153
+ pip install sqlmath==2025.3.31
154
154
  ```
155
155
 
156
156
 
@@ -164,8 +164,8 @@ pip install sqlmath==2025.2.28
164
164
  sh jslint_ci.sh shRollupUpgrade "v4.4.0" "v4.5.0" ".ci.sh sqlmath_base.h"
165
165
  #
166
166
  # sqlite
167
- sh jslint_ci.sh shRollupUpgrade "3.46.1" "3.47.2" ".ci.sh sqlmath_external_sqlite.c"
168
- sh jslint_ci.sh shRollupUpgrade "3460100" "3470200" ".ci.sh sqlmath_external_sqlite.c"
167
+ sh jslint_ci.sh shRollupUpgrade "3.47.2" "3.49.1" ".ci.sh sqlmath_external_sqlite.c"
168
+ sh jslint_ci.sh shRollupUpgrade "3470200" "3490100" ".ci.sh sqlmath_external_sqlite.c"
169
169
  #
170
170
  # zlib
171
171
  # sh jslint_ci.sh shRollupUpgrade "1.3" "1.3.1" ".ci.sh sqlmath_external_zlib.c"
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  # Status
5
- | Branch | [master<br>(v2025.2.28)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
5
+ | Branch | [master<br>(v2025.3.31)](https://github.com/sqlmath/sqlmath/tree/master) | [beta<br>(Web Demo)](https://github.com/sqlmath/sqlmath/tree/beta) | [alpha<br>(Development)](https://github.com/sqlmath/sqlmath/tree/alpha) |
6
6
  |--:|:--:|:--:|:--:|
7
7
  | CI | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Amaster) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=beta)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Abeta) | [![ci](https://github.com/sqlmath/sqlmath/actions/workflows/ci.yml/badge.svg?branch=alpha)](https://github.com/sqlmath/sqlmath/actions?query=branch%3Aalpha) |
8
8
  | Coverage | [![coverage](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-master/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-beta/.artifact/coverage/index.html) | [![coverage](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/coverage_badge.svg)](https://sqlmath.github.io/sqlmath/branch-alpha/.artifact/coverage/index.html) |
@@ -121,11 +121,11 @@ PORT=8080 sh jslint_ci.sh shHttpFileServer
121
121
  ```shell
122
122
  python -m build
123
123
  #
124
- twine upload --repository testpypi dist/sqlmath-2025.2.28*
125
- py -m pip install --index-url https://test.pypi.org/simple/ sqlmath==2025.2.28
124
+ twine upload --repository testpypi dist/sqlmath-2025.3.31*
125
+ py -m pip install --index-url https://test.pypi.org/simple/ sqlmath==2025.3.31
126
126
  #
127
- twine upload dist/sqlmath-2025.2.28*
128
- pip install sqlmath==2025.2.28
127
+ twine upload dist/sqlmath-2025.3.31*
128
+ pip install sqlmath==2025.3.31
129
129
  ```
130
130
 
131
131
 
@@ -139,8 +139,8 @@ pip install sqlmath==2025.2.28
139
139
  sh jslint_ci.sh shRollupUpgrade "v4.4.0" "v4.5.0" ".ci.sh sqlmath_base.h"
140
140
  #
141
141
  # sqlite
142
- sh jslint_ci.sh shRollupUpgrade "3.46.1" "3.47.2" ".ci.sh sqlmath_external_sqlite.c"
143
- sh jslint_ci.sh shRollupUpgrade "3460100" "3470200" ".ci.sh sqlmath_external_sqlite.c"
142
+ sh jslint_ci.sh shRollupUpgrade "3.47.2" "3.49.1" ".ci.sh sqlmath_external_sqlite.c"
143
+ sh jslint_ci.sh shRollupUpgrade "3470200" "3490100" ".ci.sh sqlmath_external_sqlite.c"
144
144
  #
145
145
  # zlib
146
146
  # sh jslint_ci.sh shRollupUpgrade "1.3" "1.3.1" ".ci.sh sqlmath_external_zlib.c"
@@ -163,7 +163,7 @@ let jslint_charset_ascii = (
163
163
  + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
164
164
  + "`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
165
165
  );
166
- let jslint_edition = "v2024.12.1-beta";
166
+ let jslint_edition = "v2025.3.1-beta";
167
167
  let jslint_export; // The jslint object to be exported.
168
168
  let jslint_fudge = 1; // Fudge starting line and starting
169
169
  // ... column to 1.
@@ -293,6 +293,7 @@ shCiArtifactUpload() {(set -e
293
293
  # install graphicsmagick
294
294
  if (! command -v gm >/dev/null)
295
295
  then
296
+ sudo apt-get update
296
297
  sudo apt-get install -y graphicsmagick
297
298
  fi
298
299
  # mkdir .artifact/
@@ -32,5 +32,5 @@
32
32
  },
33
33
  "shCiArtifactUpload": 1,
34
34
  "shCiPublishNpm": 1,
35
- "version": "2025.2.28"
35
+ "version": "2025.3.31"
36
36
  }
@@ -9,7 +9,7 @@ backend-path = ["."]
9
9
  # https://peps.python.org/pep-0621/#example
10
10
  [project]
11
11
  name = "sqlmath"
12
- version = "2025.2.28"
12
+ version = "2025.3.31"
13
13
  description = "sqlite for datascience"
14
14
  authors = [{name = "Kai Zhu"}]
15
15
  maintainers = []
@@ -27,8 +27,8 @@ python setup.py bdist_wheel
27
27
  python setup.py build_ext
28
28
  """
29
29
 
30
- __version__ = "2025.2.28"
31
- __version_info__ = ("2025", "2", "28")
30
+ __version__ = "2025.3.31"
31
+ __version_info__ = ("2025", "3", "31")
32
32
 
33
33
  import asyncio
34
34
  import base64
@@ -21,8 +21,8 @@
21
21
 
22
22
  """sqlmath.py."""
23
23
 
24
- __version__ = "2025.2.28"
25
- __version_info__ = ("2025", "2", "28")
24
+ __version__ = "2025.3.31"
25
+ __version_info__ = ("2025", "3", "31")
26
26
 
27
27
  import json
28
28
  import math
@@ -122,7 +122,7 @@ let {
122
122
  let sqlMessageDict = {}; // dict of web-worker-callbacks
123
123
  let sqlMessageId = 0;
124
124
  let sqlWorker;
125
- let version = "v2025.2.28";
125
+ let version = "v2025.3.31";
126
126
 
127
127
  async function assertErrorThrownAsync(asyncFunc, regexp) {
128
128
 
@@ -314,7 +314,7 @@ typedef struct Doublewin {
314
314
  //
315
315
  double ncol; // number of columns
316
316
  double waa; // window-position-left
317
- double wnn; // number of window elements
317
+ double wnn; // window-mode
318
318
  } Doublewin;
319
319
  SQLMATH_API void doublewinAggfree(
320
320
  Doublewin ** dblwinAgg
@@ -2526,37 +2526,40 @@ SQLMATH_FUNC static void sql1_zlib_compress_func(
2526
2526
  sqlite3_value ** argv
2527
2527
  ) {
2528
2528
  // This function will compress <argv[0]> using zlib's compress() function,
2529
- // with a 4-byte header storing original uncompressed size.
2529
+ // with a 4-byte header storing <original_size>.
2530
2530
  UNUSED_PARAMETER(argc);
2531
- // Extract the BLOB data and its size
2532
- const void *input_data = sqlite3_value_blob(argv[0]);
2533
- if (input_data == NULL) {
2534
- sqlite3_result_error(context, "Cannot compress() NULL blob", -1);
2531
+ // init original_data
2532
+ const void *original_data = sqlite3_value_blob(argv[0]);
2533
+ if (original_data == NULL) {
2534
+ sqlite3_result_error(context, "zlib_compress - cannot compress NULL",
2535
+ -1);
2535
2536
  return;
2536
2537
  }
2537
- int input_size = sqlite3_value_bytes(argv[0]);
2538
- // Estimate the maximum size of the compressed data
2539
- uLongf output_size = compressBound(input_size);
2540
- // Allocate memory for the final result (header + compressed data)
2541
- unsigned char *result = (unsigned char *) sqlite3_malloc(4 + output_size);
2542
- if (result == NULL) {
2538
+ // init original_size
2539
+ int original_size = sqlite3_value_bytes(argv[0]);
2540
+ // init compress_size
2541
+ uLongf compress_size = compressBound(original_size);
2542
+ // init compress_data
2543
+ unsigned char *compress_data =
2544
+ (unsigned char *) sqlite3_malloc(4 + compress_size);
2545
+ if (compress_data == NULL) {
2543
2546
  sqlite3_result_error_nomem(context);
2544
2547
  return;
2545
2548
  }
2546
- // Perform the compression using zlib
2547
- int ret = compress(result + 4, &output_size, input_data, input_size);
2548
- if (ret != Z_OK) {
2549
- sqlite3_free(result);
2550
- sqlite3_result_error(context, "Compression failed", -1);
2549
+ // zlib_compress
2550
+ if (compress(compress_data + 4, &compress_size, original_data,
2551
+ original_size) != Z_OK) {
2552
+ sqlite3_free(compress_data);
2553
+ sqlite3_result_error(context, "zlib_compress - failed compress", -1);
2551
2554
  return;
2552
2555
  }
2553
- // Set the 4-byte header with the original BLOB size (big-endian)
2554
- result[0] = (input_size >> 24) & 0xFF;
2555
- result[1] = (input_size >> 16) & 0xFF;
2556
- result[2] = (input_size >> 8) & 0xFF;
2557
- result[3] = input_size & 0xFF;
2558
- // Return the compressed result as a BLOB
2559
- sqlite3_result_blob(context, result, 4 + output_size, sqlite3_free);
2556
+ // set 4-byte header storing <original_size> (big-endian)
2557
+ compress_data[0] = (original_size >> 0x18) & 0xff;
2558
+ compress_data[1] = (original_size >> 0x10) & 0xff;
2559
+ compress_data[2] = (original_size >> 0x08) & 0xff;
2560
+ compress_data[3] = (original_size >> 0x00) & 0xff;
2561
+ sqlite3_result_blob(context, compress_data, 4 + compress_size,
2562
+ sqlite3_free);
2560
2563
  }
2561
2564
 
2562
2565
  SQLMATH_FUNC static void sql1_zlib_uncompress_func(
@@ -2564,53 +2567,49 @@ SQLMATH_FUNC static void sql1_zlib_uncompress_func(
2564
2567
  int argc,
2565
2568
  sqlite3_value ** argv
2566
2569
  ) {
2567
- // This function will uncompress <argv[0]> using zlib's uncompress() function,
2568
- // and assumes input has a 4-byte header storing original uncompressed size.
2570
+ // This function will compress <argv[0]> using zlib's compress() function,
2571
+ // with a 4-byte header storing <original_size>.
2569
2572
  UNUSED_PARAMETER(argc);
2570
- // Extract the compressed BLOB data and its size
2571
- const unsigned char *input_data = sqlite3_value_blob(argv[0]);
2572
- if (input_data == NULL) {
2573
- sqlite3_result_error(context, "Cannot uncompress() NULL blob", -1);
2573
+ // init compress_data
2574
+ const unsigned char *compress_data = sqlite3_value_blob(argv[0]);
2575
+ if (compress_data == NULL) {
2576
+ sqlite3_result_error(context,
2577
+ "zlib_uncompress - cannot uncompress NULL", -1);
2574
2578
  return;
2575
2579
  }
2576
- int input_size = sqlite3_value_bytes(argv[0]);
2577
- // Ensure the input BLOB is large enough to contain the 4-byte header
2578
- if (input_size < 4) {
2579
- sqlite3_result_error(context, "Invalid compressed BLOB, too small",
2580
- -1);
2580
+ // init compress_size
2581
+ int compress_size = sqlite3_value_bytes(argv[0]) - 4;
2582
+ if (compress_size < 0) {
2583
+ sqlite3_result_error(context, "zlib_uncompress - invalid header", -1);
2581
2584
  return;
2582
2585
  }
2583
- // Extract the original size from the 4-byte header (big-endian)
2584
- int original_size = (input_data[0] << 24) | (input_data[1] << 16) |
2585
- (input_data[2] << 8) | input_data[3];
2586
- // Ensure the original size is valid (greater than 0 and reasonable)
2586
+ // init original_size
2587
+ uLongf original_size = 0 //
2588
+ | (compress_data[0] << 0x18) //
2589
+ | (compress_data[1] << 0x10) //
2590
+ | (compress_data[2] << 0x08) //
2591
+ | (compress_data[3] << 0x00);
2587
2592
  if (original_size <= 0 || original_size > SIZEOF_BLOB_MAX) {
2588
- sqlite3_result_error(context, "Invalid original size", -1);
2593
+ sqlite3_result_error(context,
2594
+ "zlib_uncompress - invalid original_size", -1);
2589
2595
  return;
2590
2596
  }
2591
- // The compressed data is everything after the 4-byte header
2592
- const void *compressed_data = input_data + 4;
2593
- int compressed_size = input_size - 4;
2594
- // Allocate memory for the decompressed data
2595
- unsigned char *decompressed_data =
2597
+ // init original_data
2598
+ unsigned char *original_data =
2596
2599
  (unsigned char *) sqlite3_malloc(original_size);
2597
- if (decompressed_data == NULL) {
2600
+ if (original_data == NULL) {
2598
2601
  sqlite3_result_error_nomem(context);
2599
2602
  return;
2600
2603
  }
2601
- // Perform decompression using zlib
2602
- uLongf decompressed_size = original_size;
2603
- int ret =
2604
- uncompress(decompressed_data, &decompressed_size, compressed_data,
2605
- compressed_size);
2606
- if (ret != Z_OK) {
2607
- sqlite3_free(decompressed_data);
2608
- sqlite3_result_error(context, "Decompression failed", -1);
2604
+ // zlib_uncompress
2605
+ if (uncompress(original_data, &original_size, compress_data + 4,
2606
+ compress_size) != Z_OK) {
2607
+ sqlite3_free(original_data);
2608
+ sqlite3_result_error(context, "zlib_uncompress - failed uncompress",
2609
+ -1);
2609
2610
  return;
2610
2611
  }
2611
- // Return the decompressed data as a BLOB
2612
- sqlite3_result_blob(context, decompressed_data, decompressed_size,
2613
- sqlite3_free);
2612
+ sqlite3_result_blob(context, original_data, original_size, sqlite3_free);
2614
2613
  }
2615
2614
 
2616
2615
  // SQLMATH_FUNC sql1_zlib_xxx_func - end
@@ -3051,7 +3050,7 @@ SQLMATH_FUNC static void sql3_win_avg1_inverse(
3051
3050
  // dblwin - init
3052
3051
  DOUBLEWIN_AGGREGATE_CONTEXT(0);
3053
3052
  if (!dblwin->wnn) {
3054
- dblwin->wnn = dblwin->nbody;
3053
+ dblwin->wnn = 1;
3055
3054
  }
3056
3055
  }
3057
3056
 
@@ -3263,7 +3262,7 @@ typedef struct AggStdev {
3263
3262
  double mxx; // x-average
3264
3263
  double nnn; // number of elements
3265
3264
  double vxx; // x-variance.p
3266
- double wnn; // number of window elements
3265
+ double wnn; // window-mode
3267
3266
  double xx0; // x-trailing
3268
3267
  } AggStdev;
3269
3268
 
@@ -3300,7 +3299,7 @@ SQLMATH_FUNC static void sql3_stdev_inverse(
3300
3299
  SQLITE3_AGGREGATE_CONTEXT(AggStdev);
3301
3300
  // agg - welford - increment agg->vxx
3302
3301
  if (sqlite3_value_numeric_type(argv[0]) != SQLITE_NULL) {
3303
- agg->wnn = agg->nnn;
3302
+ agg->wnn = 1;
3304
3303
  agg->xx0 = sqlite3_value_double(argv[0]);
3305
3304
  }
3306
3305
  }
@@ -3538,7 +3537,7 @@ SQLMATH_FUNC static void sql3_win_ema1_inverse(
3538
3537
  // dblwin - init
3539
3538
  DOUBLEWIN_AGGREGATE_CONTEXT(0);
3540
3539
  if (!dblwin->wnn) {
3541
- dblwin->wnn = dblwin->nbody;
3540
+ dblwin->wnn = 1;
3542
3541
  }
3543
3542
  }
3544
3543
 
@@ -3672,7 +3671,7 @@ SQLMATH_FUNC static void sql3_win_quantile1_inverse(
3672
3671
  // dblwin - init
3673
3672
  DOUBLEWIN_AGGREGATE_CONTEXT(0);
3674
3673
  if (!dblwin->wnn) {
3675
- dblwin->wnn = dblwin->nbody;
3674
+ dblwin->wnn = 1;
3676
3675
  }
3677
3676
  // dblwin - inverse
3678
3677
  const int ncol = argc / 2;
@@ -3817,12 +3816,12 @@ typedef struct WinSinefit {
3817
3816
  double spp; // sine phase
3818
3817
  double sww; // sine angular-frequency
3819
3818
  //
3820
- double vxx; // y-variance.p
3819
+ double vxx; // x-variance.p
3821
3820
  double vxy; // xy-covariance.p
3822
3821
  double vyy; // y-variance.p
3823
3822
  //
3824
3823
  double wbb; // window-position-right
3825
- double wnn; // number of window elements
3824
+ double wnn; // window-mode
3826
3825
  //
3827
3826
  double xx0; // x-trailing
3828
3827
  double xx1; // x-current
@@ -3832,6 +3831,79 @@ typedef struct WinSinefit {
3832
3831
  } WinSinefit;
3833
3832
  static const int WIN_SINEFIT_N = sizeof(WinSinefit) / sizeof(double);
3834
3833
  static const int WIN_SINEFIT_STEP = 3 + 0;
3834
+ // static const int WIN_SINEFIT_STEP = 3 + 2;
3835
+
3836
+ static void winSinefitDft(
3837
+ WinSinefit * wsf,
3838
+ double *xxyy,
3839
+ const int wbb,
3840
+ const int nbody,
3841
+ const int ncol
3842
+ ) {
3843
+ // This function will calculate running sliding-discrete-fourier-transform as:
3844
+ // DFTn(tt+1) = (DFTn(tt) - dft(tt) + dft(tt+nnn)) * e
3845
+ UNUSED_PARAMETER(wsf);
3846
+ UNUSED_PARAMETER(xxyy);
3847
+ UNUSED_PARAMETER(wbb);
3848
+ UNUSED_PARAMETER(nbody);
3849
+ UNUSED_PARAMETER(ncol);
3850
+ }
3851
+
3852
+ static void winSinefitLnr(
3853
+ WinSinefit * wsf,
3854
+ double *xxyy,
3855
+ const int wbb
3856
+ ) {
3857
+ // This function will calculate running simple-linear-regression as:
3858
+ // yy = laa + lbb*xx
3859
+ const double invn0 = 1.0 / wsf->nnn;
3860
+ const double xx = wsf->xx1;
3861
+ const double yy = wsf->yy1;
3862
+ double mxx = wsf->mxx;
3863
+ double myy = wsf->myy;
3864
+ double vxx = wsf->vxx;
3865
+ double vxy = wsf->vxy;
3866
+ double vyy = wsf->vyy;
3867
+ if (wsf->wnn) {
3868
+ // calculate running lnr - window
3869
+ const double xx0 = wsf->xx0;
3870
+ const double yy0 = wsf->yy0;
3871
+ const double dx = xx - xx0;
3872
+ const double dy = yy - yy0;
3873
+ vxx += (xx * xx - xx0 * xx0) - dx * (dx * invn0 + 2 * mxx);
3874
+ vyy += (yy * yy - yy0 * yy0) - dy * (dy * invn0 + 2 * myy);
3875
+ vxy += (xx * yy - xx0 * yy0) - dx * myy - dy * (dx * invn0 + mxx);
3876
+ mxx += dx * invn0;
3877
+ myy += dy * invn0;
3878
+ } else {
3879
+ // calculate running lnr - welford
3880
+ const double dx = xx - mxx;
3881
+ const double dy = yy - myy;
3882
+ // welford - increment vxx
3883
+ mxx += dx * invn0;
3884
+ vxx += dx * (xx - mxx);
3885
+ // welford - increment vyy
3886
+ myy += dy * invn0;
3887
+ vyy += dy * (yy - myy);
3888
+ // welford - increment vxy
3889
+ vxy += dy * (xx - mxx);
3890
+ }
3891
+ // calculate lnr - laa, lbb
3892
+ const double lbb = vxy / vxx;
3893
+ const double laa = myy - lbb * mxx;
3894
+ const double rr = yy - (laa + lbb * xx);
3895
+ // wsf - save
3896
+ wsf->laa = laa;
3897
+ wsf->lbb = lbb;
3898
+ wsf->mxx = mxx;
3899
+ wsf->myy = myy;
3900
+ wsf->rr1 = rr;
3901
+ wsf->vxx = vxx;
3902
+ wsf->vxy = vxy;
3903
+ wsf->vyy = vyy;
3904
+ // save rr1 in window
3905
+ xxyy[wbb + 2] = isfinite(rr) ? rr : 0;
3906
+ }
3835
3907
 
3836
3908
  static void winSinefitSnr(
3837
3909
  WinSinefit * wsf,
@@ -3888,6 +3960,7 @@ static void winSinefitSnr(
3888
3960
  tmp = sww * xxyy[ii + 0];
3889
3961
  const double sxx = cos(tmp);
3890
3962
  const double syy = sin(tmp);
3963
+ // Use de-trended residual.
3891
3964
  const double szz = inva * xxyy[ii + 2];
3892
3965
  sumxx += sxx * sxx;
3893
3966
  sumxy += sxx * syy;
@@ -4031,62 +4104,6 @@ static void winSinefitSnr(
4031
4104
  wsf->sww = sww;
4032
4105
  }
4033
4106
 
4034
- static void winSinefitLnr(
4035
- WinSinefit * wsf,
4036
- double *xxyy,
4037
- const int wbb
4038
- ) {
4039
- // This function will calculate running simple-linear-regression as:
4040
- // yy = laa + lbb*xx
4041
- const double invn0 = 1.0 / wsf->nnn;
4042
- const double xx = wsf->xx1;
4043
- const double yy = wsf->yy1;
4044
- double mxx = wsf->mxx;
4045
- double myy = wsf->myy;
4046
- double vxx = wsf->vxx;
4047
- double vxy = wsf->vxy;
4048
- double vyy = wsf->vyy;
4049
- if (wsf->wnn) {
4050
- // calculate running lnr - window
4051
- const double xx0 = wsf->xx0;
4052
- const double yy0 = wsf->yy0;
4053
- const double dx = xx - xx0;
4054
- const double dy = yy - yy0;
4055
- vxx += (xx * xx - xx0 * xx0) - dx * (dx * invn0 + 2 * mxx);
4056
- vyy += (yy * yy - yy0 * yy0) - dy * (dy * invn0 + 2 * myy);
4057
- vxy += (xx * yy - xx0 * yy0) - dx * myy - dy * (dx * invn0 + mxx);
4058
- mxx += dx * invn0;
4059
- myy += dy * invn0;
4060
- } else {
4061
- // calculate running lnr - welford
4062
- const double dx = xx - mxx;
4063
- const double dy = yy - myy;
4064
- // welford - increment vxx
4065
- mxx += dx * invn0;
4066
- vxx += dx * (xx - mxx);
4067
- // welford - increment vyy
4068
- myy += dy * invn0;
4069
- vyy += dy * (yy - myy);
4070
- // welford - increment vxy
4071
- vxy += dy * (xx - mxx);
4072
- }
4073
- // calculate lnr - laa, lbb
4074
- const double lbb = vxy / vxx;
4075
- const double laa = myy - lbb * mxx;
4076
- const double rr = yy - (laa + lbb * xx);
4077
- // wsf - save
4078
- wsf->laa = laa;
4079
- wsf->lbb = lbb;
4080
- wsf->mxx = mxx;
4081
- wsf->myy = myy;
4082
- wsf->rr1 = rr;
4083
- wsf->vxx = vxx;
4084
- wsf->vxy = vxy;
4085
- wsf->vyy = vyy;
4086
- // save rr1 in window
4087
- xxyy[wbb + 2] = isfinite(rr) ? rr : 0;
4088
- }
4089
-
4090
4107
  SQLMATH_FUNC static void sql3_win_sinefit2_value(
4091
4108
  sqlite3_context * context
4092
4109
  ) {
@@ -4132,7 +4149,7 @@ SQLMATH_FUNC static void sql3_win_sinefit2_inverse(
4132
4149
  // dblwin - init
4133
4150
  DOUBLEWIN_AGGREGATE_CONTEXT(0);
4134
4151
  if (!dblwin->wnn) {
4135
- dblwin->wnn = dblwin->nbody;
4152
+ dblwin->wnn = 1;
4136
4153
  }
4137
4154
  }
4138
4155
 
@@ -4200,6 +4217,8 @@ static void sql3_win_sinefit2_step(
4200
4217
  winSinefitLnr(wsf, xxyy, wbb);
4201
4218
  // dblwin - calculate snr
4202
4219
  if (modeSnr) {
4220
+ winSinefitDft(wsf, xxyy, wbb, (int) dblwin->nbody,
4221
+ (int) dblwin->ncol);
4203
4222
  winSinefitSnr(wsf, xxyy, wbb, (int) dblwin->nbody,
4204
4223
  (int) dblwin->ncol);
4205
4224
  }
@@ -4424,6 +4443,7 @@ SQLMATH_FUNC static void sql1_sinefit_refitlast_func(
4424
4443
  // dblwin - calculate lnr
4425
4444
  winSinefitLnr(wsf, xxyy, wbb);
4426
4445
  // dblwin - calculate snr
4446
+ winSinefitDft(wsf, xxyy, wbb, nbody, ncol);
4427
4447
  winSinefitSnr(wsf, xxyy, wbb, nbody, ncol);
4428
4448
  // increment counter
4429
4449
  argv += 2;