diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30536087..b71a0016 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,6 +49,7 @@ jobs: run: | git clone --single-branch https://github.com/SacBase/sac-examples.git cd sac-examples + make all ./test.sh build-macos-x86: @@ -97,6 +98,7 @@ jobs: run: | git clone --single-branch https://github.com/SacBase/sac-examples.git cd sac-examples + make all ./test.sh build-macos-arm: @@ -145,4 +147,5 @@ jobs: run: | git clone --single-branch https://github.com/SacBase/sac-examples.git cd sac-examples + make all ./test.sh diff --git a/src/numerical/MathArray.sac b/src/numerical/MathArray.sac index 7f1a3f22..f4d3b070 100644 --- a/src/numerical/MathArray.sac +++ b/src/numerical/MathArray.sac @@ -1,7 +1,7 @@ #pragma safe module MathArray; -export all; +export all except { + }; /****************************************************************************** * @@ -37,3 +37,27 @@ MAP_REAL(MAP_A, fabs) MAP_REAL(MAP_A, sqrt) MAP_REAL(MAP_A, floor) MAP_REAL(MAP_AxS, pow) + +/****************************************************************************** + * + * L2-norm + * + ******************************************************************************/ + +inline float +(float a, float b) { return _add_SxS_(a, b); } +inline float l2norm(float[d:shp] a) +{ + return Math::sqrt(with { + (_mul_SxV_(0, shp) <= iv < shp) + : _mul_SxS_(_sel_VxA_(iv, a), _sel_VxA_(iv, a)); + } : fold(+, 0f)); +} + +inline double +(double a, double b) { return _add_SxS_(a, b); } +inline double l2norm(double[d:shp] a) +{ + return Math::sqrt(with { + (_mul_SxV_(0, shp) <= iv < shp) + : _mul_SxS_(_sel_VxA_(iv, a), _sel_VxA_(iv, a)); + } : fold(+, 0d)); +}