From 07e18043145f3d91c8ea7ec3ad41b3c905585277 Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Wed, 1 Jul 2026 09:42:39 +0400 Subject: initial commit: ts time series analysis library v0.1.0 - 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags --- lib/ts.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 lib/ts.c (limited to 'lib/ts.c') diff --git a/lib/ts.c b/lib/ts.c new file mode 100755 index 0000000..68e2f41 --- /dev/null +++ b/lib/ts.c @@ -0,0 +1,119 @@ +#include +#include +#include +#include +#include "ts.h" + + +fp_t * ts_fill( fp_t *x, uint_t n, fp_t x0, fp_t x1 ) +{ + fp_t step = ( x1 - x0 ) / ( n - 1 ); + + if( x0 == 0.0 && x1 == 0.0 ) + { + memset(x, 0, sizeof( fp_t ) * n ); + } + + else + { + for( uint_t i = 0; i < n; i++ ) + { + x[i] = x0 + ( i * step ); + } + } + + return x; +} + + +void ts_print( fp_t *x, uint_t n ) +{ + fputc('[', stdout); + + uint_t i; + for( i = 0; i < n - 1; i++ ) + { + fprintf(stdout, "%f,", x[i]); + } + + fprintf(stdout, "%f]", x[i]); +} + + +void ts_pretty_print( fp_t const * const *x, uint_t m, uint_t n ) +{ + if( m > 1 ) + { + for( uint_t i = 0; i < n; i++ ) + { + uint_t j = 0; + for( ; j < m; j++ ) + { + fprintf( stdout, "%f ", x[i][j] ); + } + + fputs( "\n", stdout ); + } + } + else + { + for( uint_t i = 0; i < n; i++ ) + { + fprintf( stdout, "%f\n", x[0][i] ); + } + } +} + + +fp_t _ts_square( fp_t x ) +{ + return x * x; +} + + +fp_t _ts_reciprocal( fp_t x ) +{ + return x != 0 ? 1.0 / x : INFINITY; +} + + +fp_t _ts_square_pyramidal_number( fp_t x ) +{ + return ( x * ( x + 1 ) * ( 2 * x + 1 ) ) / 6; +} + + +fp_t _ts_triangle_number( fp_t x ) +{ + return ( ( x ) * ( ( x ) + 1 ) ) * 0.5; +} + + +fp_t _ts_sum_to_covariance( fp_t sum_xy, fp_t sum_x, fp_t sum_y, uint_t k ) +{ + return ( sum_xy - ( sum_x * sum_y / k ) ) / k; +} + + +fp_t _ts_sum_to_variance( fp_t sum_x2, fp_t sum_x, uint_t k ) +{ + return _ts_sum_to_covariance( sum_x2, sum_x, sum_x, k ); +} + + +uint_t _ts_circle_increment( uint_t i, uint_t k ) +{ + return ( i + 1 ) % k; +} + + +// ts_constant_t * ts_constant_init( uint_t n, ... ) +// { +// va_list args; +// va_start( args, n ); + +// for( uint_t i = 0; i < n; i++ ) +// { + +// } +// } \ No newline at end of file -- cgit v1.3.1