From 3d92926a902017e7cf1f5738e99ff62da596ce12 Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Sun, 9 Aug 2026 15:02:21 +0400 Subject: refactor --- lib/test.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'lib/test.c') diff --git a/lib/test.c b/lib/test.c index 56c47eb..d022f6e 100755 --- a/lib/test.c +++ b/lib/test.c @@ -33,42 +33,55 @@ void ts_test_all( void ) } bool ts_test( - void ( *ts_function )( - fp_t * const *y, - fp_t const * const *x, - uint_t n, - ts_constant_t const *c + int ( *ts_function )( + fp_t * const *y, + uint_t y_n, + fp_t const * const *x, + uint_t x_n, + uint_t n, + ts_constant_t const *c ), - uint_t ( *ts_offset )( - ts_constant_t const *c + uint_t ( *ts_offset )( + ts_constant_t const *c ), fp_t const * const *x, fp_t const * const *e, uint_t n, ts_constant_t const *c, ts_parameter_t const *m ) -{ +{ + if ( !ts_function || !ts_offset || !m || !e || !x ) return false; + uint_t offset = ts_offset( c ); - uint_t y_n = n - offset; + if ( offset >= n ) return false; + uint_t y_len = n - offset; bool result = true; - - fp_t *y[m->y]; - for( uint_t i = 0; i < m->y; i++ ) + fp_t *y[m->n_outputs]; + + for( uint_t i = 0; i < m->n_outputs; i++ ) { - fp_t *tmp = malloc( y_n * sizeof( fp_t ) ); + fp_t *tmp = calloc( y_len, sizeof( fp_t ) ); + if ( !tmp ) + { + for ( uint_t j = 0; j < i; j++ ) free( y[j] ); + return false; + } y[i] = tmp; } - ts_function( y, x, n, c ); + if ( ts_function( y, m->n_outputs, x, m->n_inputs, n, c ) != 0 ) + { + for ( uint_t i = 0; i < m->n_outputs; i++ ) free( y[i] ); + return false; + } - for( uint_t i = 0; i < m->y; ++i ) + for( uint_t i = 0; i < m->n_outputs; ++i ) { - for( uint_t j = 0; j < y_n; ++j ) + for( uint_t j = 0; j < y_len; ++j ) { - // _ts_assert_approximate( y[i][j], e[i][j], TS_TEST_EPSILON ); - result &= _ts_is_approximate( y[i][j], e[i][j], TS_TEST_EPSILON ); - } + result &= _ts_is_approximate( y[i][j], e[i][j], TS_TEST_EPSILON ); + } free( y[i] ); } -- cgit v1.3.1