From db1a5fd344e5591c36ab9aba87a84726154c7eca Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 23 Jul 2026 01:50:41 +0530 Subject: [PATCH 1/4] feat: add `ml/strided/dsgd-trainer-squared-epsilon-insensitive` --- .../examples/index.js | 61 +++++ .../lib/base.js | 256 ++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js new file mode 100644 index 000000000000..94fd74d8e05a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsgdTrainerSqEpsIns = require( './../lib/base.js' ); + +var M = 100000; // number of samples +var N = 20; // number of features + +var opts = { + 'dtype': 'float64' +}; + +// Generate a random `MxN` design matrix and a random target vector: +var x = uniform( M*N, -10.0, 10.0, opts ); +var y = uniform( M, -50.0, 50.0, opts ); + +// Allocate the weight vector and the per-feature L1 shrinkage workspace: +var w = new Float64Array( N ); +var workspace = new Float64Array( N ); + +// Configure the training hyperparameters: +var penalty = 'elasticnet'; +var fitIntercept = true; +var l1Ratio = 0.15; +var maxIter = 20; +var learningRate = 'invscaling'; +var eta0 = 0.01; +var powerT = 0.25; +var epsilon = 0.0; +var lambda = 1.0e-5; +var intercept = 0.0; + +// Train a linear model via plain SGD with an elastic-net penalty: +var out = dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, 1, 0, w, 1, 0, x, N, 1, 0, workspace, 1, 0 ); // eslint-disable-line max-len + +var j; +console.log( 'Estimated intercept: %d', out.intercept ); +console.log( '' ); +console.log( 'feature | estimated weight' ); +for ( j = 0; j < N; j++ ) { + console.log( '%d\t| %d', j, out.weights[ j ] ); +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js new file mode 100644 index 000000000000..20796fbfafa5 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js @@ -0,0 +1,256 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var logger = require( 'debug' ); +var sqEpsInsGradient = require( '@stdlib/ml/base/loss/float64/squared-epsilon-insensitive-gradient' ); +var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; +var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var pow = require( '@stdlib/math/base/special/pow' ); +var max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); + + +// VARIABLES // + +var debug = logger( 'ml:dsgd-trainer-squared-epsilon-insensitive' ); + +var MIN_SCALE = 1.0e-9; +var MAX_DLOSS = 1e12; + +// NOTE: both of the above constants were picked from sklearn API + +// FUNCTIONS // + +/** +* Applies the cumulative L1 penalty to the weight vector using scikit-learn's truncated-gradient scheme. +* +* @private +* @param {NonNegativeInteger} N - number of features (length of `w`) +* @param {number} u - cumulative L1 penalty accumulated so far +* @param {number} scaleFactor - current scaling factor applied to the stored weights +* @param {Float64Array} w - weight vector (updated in-place) +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} workspace - workspace array tracking the total L1 shrinkage applied to each feature (updated in-place) +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @returns {void} +*/ +function l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ) { + var wsIdx; + var idx; + var z; + var j; + + for ( j = 0; j < N; j++ ) { + idx = offsetW + ( j * strideW ); + wsIdx = offsetWS + ( j * strideWS ); + z = w[ idx ]; + if ( scaleFactor * z > 0.0 ) { + w[ idx ] = max( 0.0, z - ( ( u + workspace[ wsIdx ] ) / scaleFactor ) ); + } else if ( scaleFactor * z < 0.0 ) { + w[ idx ] = min( 0.0, z + ( ( u - workspace[ wsIdx ] ) / scaleFactor ) ); + } + workspace[ wsIdx ] += scaleFactor * ( w[ idx ] - z ); + } +} + + +// MAIN // + +/** +* Trains a linear model with the squared epsilon-insensitive loss via stochastic gradient descent. +* +* @private +* @param {string} penalty - penalty type: `'l1'`, `'l2'`, or `'elasticnet'` +* @param {string} learningRate - schedule: `'constant'` (eta = eta0), `'invscaling'` (eta = eta0/t^powerT), `'basic'` (eta = 10/(10+t)), or `'pegasos'` (eta = 1/(lambda*t)) +* @param {boolean} fitIntercept - boolean indicating whether to fit an intercept term +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {number} l1Ratio - elastic-net mixing parameter on the interval `[0,1]` (`0` => L2, `1` => L1); overridden for pure L1/L2 penalties +* @param {PositiveInteger} maxIter - number of epochs +* @param {number} eta0 - initial/base learning rate (used by `'constant'` and `'invscaling'`) +* @param {number} powerT - exponent for the inverse-scaling schedule (only used by `'invscaling'`) +* @param {number} epsilon - width of the insensitive region of the loss +* @param {number} lambda - regularization strength +* @param {number} intercept - initial intercept +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} x - `M` by `N` input matrix +* @param {integer} strideX1 - stride of the first dimension of `x` +* @param {integer} strideX2 - stride of the second dimension of `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @returns {Object} results object with `intercept` and `weights` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Two features, four samples; target y = 2*x0 - 1*x1: +* var x = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0 ] ); +* var y = new Float64Array( [ 2.0, -1.0, 1.0, 3.0 ] ); +* var w = new Float64Array( 2 ); +* var workspace = new Float64Array( 2 ); +* +* var out = dsgdTrainerSqEpsIns( +* 'l2', 'invscaling', true, // penalty, learningRate, fitIntercept +* 4, 2, 0.0, // M, N, l1Ratio +* 1000, // maxIter +* 0.02, 0.5, // eta0, powerT +* 0.0, 1.0e-4, // epsilon, lambda +* 0.0, // initial intercept +* y, 1, 0, // y, strideY, offsetY +* w, 1, 0, // w, strideW, offsetW +* x, 2, 1, 0, // x, strideX1, strideX2, offsetX +* workspace, 1, 0 // workspace, strideWS, offsetWS +* ); +*/ +function dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, strideY, offsetY, w, strideW, offsetW, x, strideX1, strideX2, offsetX, workspace, strideWS, offsetWS ) { // eslint-disable-line max-params, max-len + var scaleFactor; + var update; + var factor; + var epoch; + var dloss; + var eta; + var ox; + var oy; + var t; + var p; + var i; + var u; + + debug( 'Starting SGD trainer with squared epsilon insensitive loss...' ); + debug( 'M = %d, N = %d, penalty = %s, lr scheduler = %s, loss function = %s, eta0 = %s, ', M, N, penalty, learningRate, 'squared-epsilon-insensitive-loss', eta0 ); + + /* + * w - (k*N) (feature vector) + * x - M*N (input vector) + * y - k (output vector) + */ + + /* + * DOUBTS? + * - should I include the intercept with the weight vector itself? + * - if yes, then should N be including intercept? + * - if no, then how do I show it to the user? should I have a `intercept` field in the results struct + * + * - Should we implement a standalone weight matrix just like how `ml/incr/sgd-regression` as well as + * the sklearn API did? They referred sofia-ml as far as I know. + */ + + // Do we set this here or expect higher level user to pass it? + if ( penalty === 'l2' ) { + l1Ratio = 0.0; + } else if ( penalty === 'l1' ) { + l1Ratio = 1.0; + } + + eta = eta0; + t = 1; + scaleFactor = 1.0; + u = 0.0; + for ( epoch = 1; epoch <= maxIter; epoch++ ) { + ox = offsetX; + oy = offsetY; + for ( i = 0; i < M; i++ ) { + p = ( scaleFactor*ddot( N, w, strideW, offsetW, x, strideX2, ox ) ) + intercept; // eslint-disable-line max-len + + if ( learningRate === 'invscaling' ) { + eta = eta0 / pow( t, powerT ); + } else if ( learningRate === 'basic' ) { + eta = 10.0 / ( 10.0 + t ); + } else if ( learningRate === 'pegasos' ) { + eta = 1.0 / ( lambda * t ); + } + // NOTE: No need to write branch for `constant` as we set eta=eta0 before starting iterations + + dloss = sqEpsInsGradient( 1.0, epsilon, y[ oy ], p ); + if ( dloss < -MAX_DLOSS ) { + dloss = -MAX_DLOSS; + } else if ( dloss > MAX_DLOSS ) { + dloss = MAX_DLOSS; + } + update = -eta * dloss; + + if ( penalty === 'l2' || penalty === 'elasticnet' ) { + factor = 1.0 - ( ( 1.0 - l1Ratio ) * eta * lambda ); + scaleFactor *= max( 0.0, factor ); + } + + if ( scaleFactor < MIN_SCALE ) { + dscal( N, scaleFactor, w, strideW, offsetW ); + scaleFactor = 1.0; + } + + // Gradient step: w_eff += -eta*dloss*x <=> w_stored += (-eta*dloss/scaleFactor)*x + // w_eff = w_stored*scaleFactor + daxpy( N, update/scaleFactor, x, strideX2, ox, w, strideW, offsetW ); // eslint-disable-line max-len + + if ( fitIntercept ) { + intercept += update; + } + + if ( penalty === 'l1' || penalty === 'elasticnet' ) { + u += ( l1Ratio * eta * lambda ); + l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ); // eslint-disable-line max-len + } + + t += 1; + ox += strideX1; + oy += strideY; + } + debug( 'Epoch %d done...', epoch ); + } + + // Fold any residual scale back into the weights so `w` holds effective values: + // sklearn does w.reset_scale() + if ( scaleFactor !== 1 ) { + dscal( N, scaleFactor, w, strideW, offsetW ); + scaleFactor = 1.0; + } + + debug( 'Finished SGD trainer with squared epsilon insensitive loss.' ); + + return { + 'intercept': intercept, + 'weights': w + }; + + /* + * returning this doesn't look solid, I have to brainstorm here. + * we will have to either return `intercept`, or keep `intercept` inside the weight matrix, + * as we cant pass a number by reference as fn argument, so the `intercept` user passes won't be updated, instead + * a copy of that `intercept` is being updated here. + */ +} + + +// EXPORTS // + +module.exports = dsgdTrainerSqEpsIns; From 19e0707c8d5cde7b250dca4f22e1401f3766383e Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Wed, 5 Aug 2026 18:45:08 +0530 Subject: [PATCH 2/4] fix: use enum resolution objects --- .../ml/strided/dsgd-trainer/examples/index.js | 61 +++++ .../ml/strided/dsgd-trainer/lib/base.js | 215 ++++++++++++++++++ .../ml/strided/dsgd-trainer/lib/decay.js | 73 ++++++ .../strided/dsgd-trainer/lib/learning_rate.js | 88 +++++++ .../ml/strided/dsgd-trainer/lib/loss.js | 91 ++++++++ .../ml/strided/dsgd-trainer/lib/truncation.js | 106 +++++++++ 6 files changed, 634 insertions(+) create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js new file mode 100644 index 000000000000..94fd74d8e05a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsgdTrainerSqEpsIns = require( './../lib/base.js' ); + +var M = 100000; // number of samples +var N = 20; // number of features + +var opts = { + 'dtype': 'float64' +}; + +// Generate a random `MxN` design matrix and a random target vector: +var x = uniform( M*N, -10.0, 10.0, opts ); +var y = uniform( M, -50.0, 50.0, opts ); + +// Allocate the weight vector and the per-feature L1 shrinkage workspace: +var w = new Float64Array( N ); +var workspace = new Float64Array( N ); + +// Configure the training hyperparameters: +var penalty = 'elasticnet'; +var fitIntercept = true; +var l1Ratio = 0.15; +var maxIter = 20; +var learningRate = 'invscaling'; +var eta0 = 0.01; +var powerT = 0.25; +var epsilon = 0.0; +var lambda = 1.0e-5; +var intercept = 0.0; + +// Train a linear model via plain SGD with an elastic-net penalty: +var out = dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, 1, 0, w, 1, 0, x, N, 1, 0, workspace, 1, 0 ); // eslint-disable-line max-len + +var j; +console.log( 'Estimated intercept: %d', out.intercept ); +console.log( '' ); +console.log( 'feature | estimated weight' ); +for ( j = 0; j < N; j++ ) { + console.log( '%d\t| %d', j, out.weights[ j ] ); +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js new file mode 100644 index 000000000000..329c096d5123 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js @@ -0,0 +1,215 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var logger = require( 'debug' ); +var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; +var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray; +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var LEARNING_RATE_METHODS = require( './learning_rate.js' ); +var LOSS_FUNCTIONS = require( './loss.js' ); +var DECAYS = require( './decay.js' ); +var TRUNCATIONS = require( './truncation.js' ); + + +// VARIABLES // + +var debug = logger( 'ml:dsgd-trainer-squared-epsilon-insensitive' ); + +var MIN_SCALE = 1.0e-9; +var MAX_DLOSS = 1e12; + + +// MAIN // + +/** +* Trains a linear model with the squared epsilon-insensitive loss via stochastic gradient descent. +* +* @private +* @param {string} penalty - penalty type: `'l1'`, `'l2'`, or `'elasticnet'` +* @param {string} learningRate - schedule: `'constant'` (eta = eta0), `'invscaling'` (eta = eta0/t^powerT), `'basic'` (eta = 10/(10+t)), or `'pegasos'` (eta = 1/(lambda*t)) +* @param {boolean} fitIntercept - boolean indicating whether to fit an intercept term +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {number} l1Ratio - elastic-net mixing parameter on the interval `[0,1]` (`0` => L2, `1` => L1); overridden for pure L1/L2 penalties +* @param {PositiveInteger} maxIter - number of epochs +* @param {number} eta0 - initial/base learning rate (used by `'constant'` and `'invscaling'`) +* @param {number} powerT - exponent for the inverse-scaling schedule (only used by `'invscaling'`) +* @param {number} epsilon - width of the insensitive region of the loss +* @param {number} lambda - regularization strength +* @param {number} intercept - initial intercept +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} x - `M` by `N` input matrix +* @param {integer} strideX1 - stride of the first dimension of `x` +* @param {integer} strideX2 - stride of the second dimension of `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @returns {Object} results object with `intercept` and `weights` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Two features, four samples; target y = 2*x0 - 1*x1: +* var x = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0 ] ); +* var y = new Float64Array( [ 2.0, -1.0, 1.0, 3.0 ] ); +* var w = new Float64Array( 2 ); +* var workspace = new Float64Array( 2 ); +* +* var out = dsgdTrainerSqEpsIns( +* 'l2', 'invscaling', true, // penalty, learningRate, fitIntercept +* 4, 2, 0.0, // M, N, l1Ratio +* 1000, // maxIter +* 0.02, 0.5, // eta0, powerT +* 0.0, 1.0e-4, // epsilon, lambda +* 0.0, // initial intercept +* y, 1, 0, // y, strideY, offsetY +* w, 1, 0, // w, strideW, offsetW +* x, 2, 1, 0, // x, strideX1, strideX2, offsetX +* workspace, 1, 0 // workspace, strideWS, offsetWS +* ); +*/ +function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, strideY, offsetY, w, strideW, offsetW, x, strideX1, strideX2, offsetX, workspace, strideWS, offsetWS ) { // eslint-disable-line max-params, max-len + var scaleFactor; + var update; + var factor; + var epoch; + var dloss; + var eta; + var ox; + var oy; + var t; + var p; + var i; + var u; + + debug( 'Starting SGD trainer with squared epsilon insensitive loss...' ); + debug( 'M = %d, N = %d, penalty = %s, lr scheduler = %s, loss function = %s, eta0 = %s, ', M, N, penalty, learningRate, 'squared-epsilon-insensitive-loss', eta0 ); + + /* + * w - (k*N) (feature vector) + * x - M*N (input vector) + * y - k (output vector) + */ + + /* + * DOUBTS? + * - should I include the intercept with the weight vector itself? + * - if yes, then should N be including intercept? + * - if no, then how do I show it to the user? should I have a `intercept` field in the results struct + * + * - Should we implement a standalone weight matrix just like how `ml/incr/sgd-regression` as well as + * the sklearn API did? They referred sofia-ml as far as I know. + */ + + // Do we set this here or expect higher level user to pass it? + if ( penalty === 'l2' ) { + l1Ratio = 0.0; + } else if ( penalty === 'l1' ) { + l1Ratio = 1.0; + } + + eta = eta0; + t = 1; + scaleFactor = 1.0; + u = 0.0; + for ( epoch = 1; epoch <= maxIter; epoch++ ) { + ox = offsetX; + oy = offsetY; + for ( i = 0; i < M; i++ ) { + p = ( scaleFactor*ddot( N, w, strideW, offsetW, x, strideX2, ox ) ) + intercept; // eslint-disable-line max-len + + var params = []; // update later + eta = LEARNING_RATE_METHODS[ learningRate ]( t, params ); + + dloss = LOSS_FUNCTIONS[ lossFunction ]( y[ oy ], p, params ); + if ( dloss < -MAX_DLOSS ) { + dloss = -MAX_DLOSS; + } else if ( dloss > MAX_DLOSS ) { + dloss = MAX_DLOSS; + } + update = -eta * dloss; + + var penaltyParams = []; + scaleFactor = DECAYS[ penalty ]( scaleFactor, penaltyParams ); + // if ( penalty === 'l2' || penalty === 'elasticnet' ) { + // factor = 1.0 - ( ( 1.0 - l1Ratio ) * eta * lambda ); + // scaleFactor *= max( 0.0, factor ); + // } + + if ( scaleFactor < MIN_SCALE ) { + dscal( N, scaleFactor, w, strideW, offsetW ); + scaleFactor = 1.0; + } + + // Gradient step: w_eff += -eta*dloss*x <=> w_stored += (-eta*dloss/scaleFactor)*x + // w_eff = w_stored*scaleFactor + daxpy( N, update/scaleFactor, x, strideX2, ox, w, strideW, offsetW ); // eslint-disable-line max-len + + if ( fitIntercept ) { + intercept += update; + } + + u = TRUNCATIONS[ penalty ]( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, penaltyParams ); // eslint-disable-line max-len + // if ( penalty === 'l1' || penalty === 'elasticnet' ) { + // u += ( l1Ratio * eta * lambda ); + // l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ); // eslint-disable-line max-len + // } + + t += 1; + ox += strideX1; + oy += strideY; + } + debug( 'Epoch %d done...', epoch ); + } + + // Fold any residual scale back into the weights so `w` holds effective values: + // sklearn does w.reset_scale() + if ( scaleFactor !== 1 ) { + dscal( N, scaleFactor, w, strideW, offsetW ); + scaleFactor = 1.0; + } + + debug( 'Finished SGD trainer with squared epsilon insensitive loss.' ); + + return { + 'intercept': intercept, + 'weights': w + }; + + /* + * returning this doesn't look solid, I have to brainstorm here. + * we will have to either return `intercept`, or keep `intercept` inside the weight matrix, + * as we cant pass a number by reference as fn argument, so the `intercept` user passes won't be updated, instead + * a copy of that `intercept` is being updated here. + */ +} + + +// EXPORTS // + +module.exports = dsgdTrainerSqEpsIns; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js new file mode 100644 index 000000000000..7b583de4b6d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var max = require( '@stdlib/math/base/special/max' ); + + +// VARIABLES // + +var DECAYS = { + 'elasticnet': l2Decay, + 'l1': identityDecay, + 'l2': l2Decay, + 'none': identityDecay +}; + + +// FUNCTIONS // + +/** +* Computes scale factor by applying the identity decay. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {NonNegativeInteger} scaleFactor - current iteration. +* @param {Float64Array} params - strided array containing regularizer specific parameters. +* @returns {number} scale factor +*/ +function identityDecay( scaleFactor, params ) { // eslint-disable-line no-unused-vars + return scaleFactor; +} + +/** +* Computes learning rate by applying the inverse scaling learning rate scheduler. +* +* Note: +* +* - Here `params` => `[ eta, lambda, l1Ratio ]` +* +* @private +* @param {NonNegativeInteger} scaleFactor - current iteration. +* @param {Float64Array} params - strided array containing regularizer specific parameters. +* @returns {number} scale factor +*/ +function l2Decay( scaleFactor, params ) { + return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * params[ 0 ] * params[ 1 ] ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = DECAYS; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js new file mode 100644 index 000000000000..3c22b3e1a078 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var pow = require( '@stdlib/math/base/special/pow' ); + + +// VARIABLES // + +var LEARNING_RATE_METHODS = { + 'basic': basic, + 'invscaling': invscaling, + 'pegasos': pegasos +}; + + +// FUNCTIONS // + +/** +* Computes learning rate by applying the basic learning rate scheduler. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {NonNegativeInteger} t - current iteration. +* @param {Float64Array} params - strided array containing scheduler specific parameters. +* @returns {number} learning rate +*/ +function basic( t, params ) { // eslint-disable-line no-unused-vars + return 10.0 / ( 10.0*t ); +} + +/** +* Computes learning rate by applying the inverse scaling learning rate scheduler. +* +* Note: +* +* - Here `params` => `[ eta0, powerT ]` +* +* @private +* @param {NonNegativeInteger} t - current iteration. +* @param {Float64Array} params - strided array containing scheduler specific parameters. +* @returns {number} learning rate +*/ +function invscaling( t, params ) { + return params[ 0 ] / pow( t, params[ 1 ] ); +} + +/** +* Computes learning rate by applying the Pegasos learning rate scheduler. +* +* Note: +* +* - Here `params` => `[ lambda ]` +* +* @private +* @param {NonNegativeInteger} t - current iteration. +* @param {Float64Array} params - strided array containing scheduler specific parameters. +* @returns {number} learning rate +*/ +function pegasos( t, params ) { + return 1.0 / ( params[ 0 ]*t ); +} + + +// EXPORTS // + +module.exports = LEARNING_RATE_METHODS; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js new file mode 100644 index 000000000000..a60f0f1a3ada --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hingeGradient = require( '@stdlib/ml/base/loss/float64/hinge-gradient' ); +var logGradient = require( '@stdlib/ml/base/loss/float64/log-gradient' ); +var modifiedHuberGradient = require( '@stdlib/ml/base/loss/float64/modified-huber-gradient' ); +var squaredHingeGradient = require( '@stdlib/ml/base/loss/float64/squared-hinge-gradient' ); +var squaredErrorGradient = require( '@stdlib/ml/base/loss/float64/squared-error-gradient' ); +var huberGradient = require( '@stdlib/ml/base/loss/float64/huber-gradient' ); +var epsilonInsensitiveGradient = require( '@stdlib/ml/base/loss/float64/epsilon-insensitive-gradient' ); +var squaredEpsilonInsensitiveGradient = require( '@stdlib/ml/base/loss/float64/squared-epsilon-insensitive-gradient' ); + + +// VARIABLES // + +var LOSS_FUNCTIONS = { + 'epsilon-insensitive': epsilonInsensitive, + 'hinge': hinge, + 'huber': huber, + 'log': log, + 'modified-huber': modifiedHuber, + 'perceptron': perceptron, + 'squared-error': squaredError, + 'squared-epsilon-insensitive': squaredEpsilonInsensitive, + 'squared-hinge': squaredHinge +}; + + +// FUNCTIONS // + +// params => [ ] +function hinge( y, p, params ) { + hingeGradient( 1.0, 1.0, y, p ); +} + +// params => [ ] +function perceptron( y, p, params ) { + hingeGradient( 1.0, 0.0, y, p ); +} + +// params => [ ] +function log( y, p, params ) { + logGradient( 1.0, y, p ); +} + +function squaredHinge( y, p, params ) { + squaredHingeGradient( 1.0, y, p ); +} + +function modifiedHuber( y, p, params ) { + modifiedHuberGradient( 1.0, y, p ); +} + +function squaredError( y, p, params ) { + squaredErrorGradient( 1.0, y, p ); +} + +function huber( y, p, params ) { + huberGradient( 1.0, y, p ); +} + +function epsilonInsensitive( y, p, params ) { + epsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); +} + +function squaredEpsilonInsensitive( y, p, params ) { + squaredEpsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); +} + +// MAIN // + + diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js new file mode 100644 index 000000000000..eb2bc7cd83c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var max = require( '@stdlib/math/base/special/max' ); +var min = require( '@stdlib/math/base/special/min' ); + + +// VARIABLES // + +var TRUNCATIONS = { + 'elasticnet': l1Truncate, + 'l1': l1Truncate, + 'l2': noTruncation, + 'none': noTruncation +}; + + +// FUNCTIONS // + +/** +* Applies no truncation. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {NonNegativeInteger} N - number of features (length of `w`) +* @param {number} u - cumulative L1 penalty accumulated so far +* @param {number} scaleFactor - current scaling factor applied to the stored weights +* @param {Float64Array} w - weight vector (updated in-place) +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} workspace - workspace array tracking the total L1 shrinkage applied to each feature (updated in-place) +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @param {Float64Array} params - strided array containing regularizer specific parameters. +* @returns {void} +*/ +function noTruncation( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line no-unused-vars, max-len + return u; +} + +/** +* Applies the cumulative L1 penalty to the weight vector. +* +* Note: +* +* - Here `params` => `[ eta, lambda, l1Ratio ]` +* +* @private +* @param {NonNegativeInteger} N - number of features (length of `w`) +* @param {number} u - cumulative L1 penalty accumulated so far +* @param {number} scaleFactor - current scaling factor applied to the stored weights +* @param {Float64Array} w - weight vector (updated in-place) +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} workspace - workspace array tracking the total L1 shrinkage applied to each feature (updated in-place) +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @param {Float64Array} params - strided array containing regularizer specific parameters. +* @returns {void} +*/ +function l1Truncate( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-len + var wsIdx; + var idx; + var z; + var j; + + for ( j = 0; j < N; j++ ) { + idx = offsetW + ( j * strideW ); + wsIdx = offsetWS + ( j * strideWS ); + z = w[ idx ]; + if ( scaleFactor * z > 0.0 ) { + w[ idx ] = max( 0.0, z - ( ( u + workspace[ wsIdx ] ) / scaleFactor ) ); // eslint-disable-line max-len + } else if ( scaleFactor * z < 0.0 ) { + w[ idx ] = min( 0.0, z + ( ( u - workspace[ wsIdx ] ) / scaleFactor ) ); // eslint-disable-line max-len + } + workspace[ wsIdx ] += scaleFactor * ( w[ idx ] - z ); + } + return u * params[ 0 ] * params[ 1 ] * params[ 2 ]; +} + + +// EXPORTS // + +module.exports = TRUNCATIONS; From 6e95f99e4cff4c29fef7646fbdbe75d800161503 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 23:26:56 +0530 Subject: [PATCH 3/4] feat: add benchmarks, docs, C header --- .../examples/index.js | 61 - .../lib/base.js | 256 ---- .../@stdlib/ml/strided/dsgd-trainer/README.md | 360 ++++++ .../dsgd-trainer/benchmark/benchmark.js | 122 ++ .../benchmark/benchmark.native.js | 127 ++ .../benchmark/benchmark.ndarray.js | 122 ++ .../benchmark/benchmark.ndarray.native.js | 127 ++ .../strided/dsgd-trainer/benchmark/c/Makefile | 146 +++ .../benchmark/c/benchmark.length.c | 253 ++++ .../ml/strided/dsgd-trainer/binding.gyp | 265 +++++ .../ml/strided/dsgd-trainer/docs/repl.txt | 160 +++ .../dsgd-trainer/docs/types/index.d.ts | 134 +++ .../strided/dsgd-trainer/docs/types/test.ts | 517 ++++++++ .../strided/dsgd-trainer/examples/c/Makefile | 146 +++ .../strided/dsgd-trainer/examples/c/example.c | 54 + .../ml/strided/dsgd-trainer/include.gypi | 70 ++ .../include/stdlib/ml/strided/dsgd_trainer.h | 81 ++ .../ml/strided/dsgd-trainer/lib/base.js | 119 +- .../ml/strided/dsgd-trainer/lib/decay.js | 34 +- .../strided/dsgd-trainer/lib/dsgd_trainer.js | 146 +++ .../dsgd-trainer/lib/dsgd_trainer.native.js | 131 +++ .../ml/strided/dsgd-trainer/lib/index.js | 72 ++ .../strided/dsgd-trainer/lib/learning_rate.js | 44 +- .../ml/strided/dsgd-trainer/lib/loss.js | 195 +++- .../ml/strided/dsgd-trainer/lib/main.js | 35 + .../ml/strided/dsgd-trainer/lib/native.js | 35 + .../ml/strided/dsgd-trainer/lib/ndarray.js | 110 ++ .../dsgd-trainer/lib/ndarray.native.js | 111 ++ .../ml/strided/dsgd-trainer/lib/truncation.js | 32 +- .../ml/strided/dsgd-trainer/manifest.json | 541 +++++++++ .../ml/strided/dsgd-trainer/package.json | 72 ++ .../ml/strided/dsgd-trainer/src/Makefile | 70 ++ .../ml/strided/dsgd-trainer/src/addon.c | 124 ++ .../ml/strided/dsgd-trainer/src/dgemv.c | 112 ++ .../ml/strided/dsgd-trainer/src/dgemv_cblas.c | 41 + .../strided/dsgd-trainer/src/dgemv_ndarray.c | 167 +++ .../fixtures/column_major_alpha_zero.json | 20 + .../column_major_complex_access_pattern.json | 18 + .../test/fixtures/column_major_nt.json | 20 + .../test/fixtures/column_major_oa.json | 18 + .../test/fixtures/column_major_sa1_sa2.json | 18 + .../test/fixtures/column_major_sa1_sa2n.json | 18 + .../test/fixtures/column_major_sa1n_sa2.json | 18 + .../test/fixtures/column_major_sa1n_sa2n.json | 18 + .../test/fixtures/column_major_t.json | 20 + .../test/fixtures/column_major_x_zeros.json | 20 + .../column_major_x_zeros_beta_one.json | 20 + .../test/fixtures/column_major_xnyn.json | 20 + .../test/fixtures/column_major_xnyp.json | 20 + .../test/fixtures/column_major_xpyn.json | 20 + .../test/fixtures/column_major_xpyp.json | 20 + .../test/fixtures/row_major_alpha_zero.json | 20 + .../row_major_complex_access_pattern.json | 18 + .../test/fixtures/row_major_nt.json | 20 + .../test/fixtures/row_major_oa.json | 18 + .../test/fixtures/row_major_sa1_sa2.json | 18 + .../test/fixtures/row_major_sa1_sa2n.json | 18 + .../test/fixtures/row_major_sa1n_sa2.json | 18 + .../test/fixtures/row_major_sa1n_sa2n.json | 18 + .../test/fixtures/row_major_t.json | 20 + .../test/fixtures/row_major_x_zeros.json | 20 + .../fixtures/row_major_x_zeros_beta_one.json | 20 + .../test/fixtures/row_major_xnyn.json | 20 + .../test/fixtures/row_major_xnyp.json | 20 + .../test/fixtures/row_major_xpyn.json | 20 + .../test/fixtures/row_major_xpyp.json | 20 + .../strided/dsgd-trainer/test/test.dgemv.js | 791 +++++++++++++ .../dsgd-trainer/test/test.dgemv.native.js | 799 +++++++++++++ .../ml/strided/dsgd-trainer/test/test.js | 82 ++ .../strided/dsgd-trainer/test/test.ndarray.js | 1025 ++++++++++++++++ .../dsgd-trainer/test/test.ndarray.native.js | 1035 +++++++++++++++++ 71 files changed, 9068 insertions(+), 432 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include/stdlib/ml/strided/dsgd_trainer.h create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/index.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/main.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/manifest.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/package.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js deleted file mode 100644 index 94fd74d8e05a..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/examples/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random/array/uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); -var dsgdTrainerSqEpsIns = require( './../lib/base.js' ); - -var M = 100000; // number of samples -var N = 20; // number of features - -var opts = { - 'dtype': 'float64' -}; - -// Generate a random `MxN` design matrix and a random target vector: -var x = uniform( M*N, -10.0, 10.0, opts ); -var y = uniform( M, -50.0, 50.0, opts ); - -// Allocate the weight vector and the per-feature L1 shrinkage workspace: -var w = new Float64Array( N ); -var workspace = new Float64Array( N ); - -// Configure the training hyperparameters: -var penalty = 'elasticnet'; -var fitIntercept = true; -var l1Ratio = 0.15; -var maxIter = 20; -var learningRate = 'invscaling'; -var eta0 = 0.01; -var powerT = 0.25; -var epsilon = 0.0; -var lambda = 1.0e-5; -var intercept = 0.0; - -// Train a linear model via plain SGD with an elastic-net penalty: -var out = dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, 1, 0, w, 1, 0, x, N, 1, 0, workspace, 1, 0 ); // eslint-disable-line max-len - -var j; -console.log( 'Estimated intercept: %d', out.intercept ); -console.log( '' ); -console.log( 'feature | estimated weight' ); -for ( j = 0; j < N; j++ ) { - console.log( '%d\t| %d', j, out.weights[ j ] ); -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js deleted file mode 100644 index 20796fbfafa5..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer-squared-epsilon-insensitive/lib/base.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var sqEpsInsGradient = require( '@stdlib/ml/base/loss/float64/squared-epsilon-insensitive-gradient' ); -var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; -var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray; -var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; -var pow = require( '@stdlib/math/base/special/pow' ); -var max = require( '@stdlib/math/base/special/max' ); -var min = require( '@stdlib/math/base/special/min' ); - - -// VARIABLES // - -var debug = logger( 'ml:dsgd-trainer-squared-epsilon-insensitive' ); - -var MIN_SCALE = 1.0e-9; -var MAX_DLOSS = 1e12; - -// NOTE: both of the above constants were picked from sklearn API - -// FUNCTIONS // - -/** -* Applies the cumulative L1 penalty to the weight vector using scikit-learn's truncated-gradient scheme. -* -* @private -* @param {NonNegativeInteger} N - number of features (length of `w`) -* @param {number} u - cumulative L1 penalty accumulated so far -* @param {number} scaleFactor - current scaling factor applied to the stored weights -* @param {Float64Array} w - weight vector (updated in-place) -* @param {integer} strideW - stride length for `w` -* @param {NonNegativeInteger} offsetW - starting index for `w` -* @param {Float64Array} workspace - workspace array tracking the total L1 shrinkage applied to each feature (updated in-place) -* @param {integer} strideWS - stride length for `workspace` -* @param {NonNegativeInteger} offsetWS - starting index for `workspace` -* @returns {void} -*/ -function l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ) { - var wsIdx; - var idx; - var z; - var j; - - for ( j = 0; j < N; j++ ) { - idx = offsetW + ( j * strideW ); - wsIdx = offsetWS + ( j * strideWS ); - z = w[ idx ]; - if ( scaleFactor * z > 0.0 ) { - w[ idx ] = max( 0.0, z - ( ( u + workspace[ wsIdx ] ) / scaleFactor ) ); - } else if ( scaleFactor * z < 0.0 ) { - w[ idx ] = min( 0.0, z + ( ( u - workspace[ wsIdx ] ) / scaleFactor ) ); - } - workspace[ wsIdx ] += scaleFactor * ( w[ idx ] - z ); - } -} - - -// MAIN // - -/** -* Trains a linear model with the squared epsilon-insensitive loss via stochastic gradient descent. -* -* @private -* @param {string} penalty - penalty type: `'l1'`, `'l2'`, or `'elasticnet'` -* @param {string} learningRate - schedule: `'constant'` (eta = eta0), `'invscaling'` (eta = eta0/t^powerT), `'basic'` (eta = 10/(10+t)), or `'pegasos'` (eta = 1/(lambda*t)) -* @param {boolean} fitIntercept - boolean indicating whether to fit an intercept term -* @param {NonNegativeInteger} M - number of samples -* @param {NonNegativeInteger} N - number of features -* @param {number} l1Ratio - elastic-net mixing parameter on the interval `[0,1]` (`0` => L2, `1` => L1); overridden for pure L1/L2 penalties -* @param {PositiveInteger} maxIter - number of epochs -* @param {number} eta0 - initial/base learning rate (used by `'constant'` and `'invscaling'`) -* @param {number} powerT - exponent for the inverse-scaling schedule (only used by `'invscaling'`) -* @param {number} epsilon - width of the insensitive region of the loss -* @param {number} lambda - regularization strength -* @param {number} intercept - initial intercept -* @param {Float64Array} y - target vector -* @param {integer} strideY - stride length for `y` -* @param {NonNegativeInteger} offsetY - starting index for `y` -* @param {Float64Array} w - weight vector -* @param {integer} strideW - stride length for `w` -* @param {NonNegativeInteger} offsetW - starting index for `w` -* @param {Float64Array} x - `M` by `N` input matrix -* @param {integer} strideX1 - stride of the first dimension of `x` -* @param {integer} strideX2 - stride of the second dimension of `x` -* @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Float64Array} workspace - workspace array -* @param {integer} strideWS - stride length for `workspace` -* @param {NonNegativeInteger} offsetWS - starting index for `workspace` -* @returns {Object} results object with `intercept` and `weights` -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* // Two features, four samples; target y = 2*x0 - 1*x1: -* var x = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0 ] ); -* var y = new Float64Array( [ 2.0, -1.0, 1.0, 3.0 ] ); -* var w = new Float64Array( 2 ); -* var workspace = new Float64Array( 2 ); -* -* var out = dsgdTrainerSqEpsIns( -* 'l2', 'invscaling', true, // penalty, learningRate, fitIntercept -* 4, 2, 0.0, // M, N, l1Ratio -* 1000, // maxIter -* 0.02, 0.5, // eta0, powerT -* 0.0, 1.0e-4, // epsilon, lambda -* 0.0, // initial intercept -* y, 1, 0, // y, strideY, offsetY -* w, 1, 0, // w, strideW, offsetW -* x, 2, 1, 0, // x, strideX1, strideX2, offsetX -* workspace, 1, 0 // workspace, strideWS, offsetWS -* ); -*/ -function dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, strideY, offsetY, w, strideW, offsetW, x, strideX1, strideX2, offsetX, workspace, strideWS, offsetWS ) { // eslint-disable-line max-params, max-len - var scaleFactor; - var update; - var factor; - var epoch; - var dloss; - var eta; - var ox; - var oy; - var t; - var p; - var i; - var u; - - debug( 'Starting SGD trainer with squared epsilon insensitive loss...' ); - debug( 'M = %d, N = %d, penalty = %s, lr scheduler = %s, loss function = %s, eta0 = %s, ', M, N, penalty, learningRate, 'squared-epsilon-insensitive-loss', eta0 ); - - /* - * w - (k*N) (feature vector) - * x - M*N (input vector) - * y - k (output vector) - */ - - /* - * DOUBTS? - * - should I include the intercept with the weight vector itself? - * - if yes, then should N be including intercept? - * - if no, then how do I show it to the user? should I have a `intercept` field in the results struct - * - * - Should we implement a standalone weight matrix just like how `ml/incr/sgd-regression` as well as - * the sklearn API did? They referred sofia-ml as far as I know. - */ - - // Do we set this here or expect higher level user to pass it? - if ( penalty === 'l2' ) { - l1Ratio = 0.0; - } else if ( penalty === 'l1' ) { - l1Ratio = 1.0; - } - - eta = eta0; - t = 1; - scaleFactor = 1.0; - u = 0.0; - for ( epoch = 1; epoch <= maxIter; epoch++ ) { - ox = offsetX; - oy = offsetY; - for ( i = 0; i < M; i++ ) { - p = ( scaleFactor*ddot( N, w, strideW, offsetW, x, strideX2, ox ) ) + intercept; // eslint-disable-line max-len - - if ( learningRate === 'invscaling' ) { - eta = eta0 / pow( t, powerT ); - } else if ( learningRate === 'basic' ) { - eta = 10.0 / ( 10.0 + t ); - } else if ( learningRate === 'pegasos' ) { - eta = 1.0 / ( lambda * t ); - } - // NOTE: No need to write branch for `constant` as we set eta=eta0 before starting iterations - - dloss = sqEpsInsGradient( 1.0, epsilon, y[ oy ], p ); - if ( dloss < -MAX_DLOSS ) { - dloss = -MAX_DLOSS; - } else if ( dloss > MAX_DLOSS ) { - dloss = MAX_DLOSS; - } - update = -eta * dloss; - - if ( penalty === 'l2' || penalty === 'elasticnet' ) { - factor = 1.0 - ( ( 1.0 - l1Ratio ) * eta * lambda ); - scaleFactor *= max( 0.0, factor ); - } - - if ( scaleFactor < MIN_SCALE ) { - dscal( N, scaleFactor, w, strideW, offsetW ); - scaleFactor = 1.0; - } - - // Gradient step: w_eff += -eta*dloss*x <=> w_stored += (-eta*dloss/scaleFactor)*x - // w_eff = w_stored*scaleFactor - daxpy( N, update/scaleFactor, x, strideX2, ox, w, strideW, offsetW ); // eslint-disable-line max-len - - if ( fitIntercept ) { - intercept += update; - } - - if ( penalty === 'l1' || penalty === 'elasticnet' ) { - u += ( l1Ratio * eta * lambda ); - l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ); // eslint-disable-line max-len - } - - t += 1; - ox += strideX1; - oy += strideY; - } - debug( 'Epoch %d done...', epoch ); - } - - // Fold any residual scale back into the weights so `w` holds effective values: - // sklearn does w.reset_scale() - if ( scaleFactor !== 1 ) { - dscal( N, scaleFactor, w, strideW, offsetW ); - scaleFactor = 1.0; - } - - debug( 'Finished SGD trainer with squared epsilon insensitive loss.' ); - - return { - 'intercept': intercept, - 'weights': w - }; - - /* - * returning this doesn't look solid, I have to brainstorm here. - * we will have to either return `intercept`, or keep `intercept` inside the weight matrix, - * as we cant pass a number by reference as fn argument, so the `intercept` user passes won't be updated, instead - * a copy of that `intercept` is being updated here. - */ -} - - -// EXPORTS // - -module.exports = dsgdTrainerSqEpsIns; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md new file mode 100644 index 000000000000..d3d1f9c2e274 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md @@ -0,0 +1,360 @@ + + +# dgemv + +> Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`. + +
+ +## Usage + +```javascript +var dgemv = require( '@stdlib/ml/strided/dsgd-trainer' ); +``` + +#### dgemv( order, trans, M, N, α, A, LDA, x, sx, β, y, sy ) + +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0 ] ); + +dgemv( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); +// y => [ 7.0, 16.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. +- **trans**: specifies whether `A` should be transposed, conjugate-transposed, or not transposed. +- **M**: number of rows in the matrix `A`. +- **N**: number of columns in the matrix `A`. +- **α**: scalar constant. +- **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **x**: input [`Float64Array`][mdn-float64array]. +- **sx**: stride length for `x`. +- **β**: scalar constant. +- **y**: output [`Float64Array`][mdn-float64array]. +- **sy**: stride length for `y`. + +The stride parameters determine how operations are performed. For example, to iterate over every other element in `x` and `y`, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] ); +var y = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] ); + +dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x, 2, 1.0, y, 2 ); +// y => [ 4.0, 0.0, 8.0, 0.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); +var y0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 ); +// y0 => [ 0.0, 8.0, 4.0 ] +``` + + + +#### dgemv.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy ) + +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +var y = new Float64Array( [ 1.0, 1.0 ] ); + +dgemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); +// y => [ 7.0, 16.0 ] +``` + +The function has the following additional parameters: + +- **sa1**: stride of the first dimension of `A`. +- **sa2**: stride of the second dimension of `A`. +- **oa**: starting index for `A`. +- **ox**: starting index for `x`. +- **oy**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0 ] ); + +dgemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 1, 1.0, y, -2, 2 ); +// y => [ 39, 8, 23, 10 ] +``` + +
+ + + +
+ +## Notes + +- `dgemv()` corresponds to the [BLAS][blas] level 2 function [`dgemv`][blas-dgemv]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dgemv = require( '@stdlib/ml/strided/dsgd-trainer' ); + +var opts = { + 'dtype': 'float64' +}; + +var M = 3; +var N = 3; + +var A = discreteUniform( M*N, 0, 255, opts ); +var x = discreteUniform( N, 0, 255, opts ); +var y = discreteUniform( M, 0, 255, opts ); + +dgemv( 'row-major', 'no-transpose', M, N, 1.0, A, N, x, -1, 1.0, y, -1 ); +console.log( y ); + +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/strided/dsgd-trainer.h" +``` + +#### c_dgemv( layout, trans, M, N, alpha, \*A, LDA, \*X, strideX, beta, \*Y, strideY ) + +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + +```c +#include "stdlib/blas/base/shared.h" + +const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 }; +const double x[] = { 1.0, 2.0, 3.0 }; +double y[] = { 1.0, 2.0, 3.0 }; + +c_dgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); +``` + +The function accepts the following arguments: + +- **layout**: `[in] CBLAS_LAYOUT` storage layout. +- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed. +- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`. +- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`. +- **alpha**: `[in] double` scalar constant. +- **A**: `[in] double*` input matrix. +- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **X**: `[in] double*` first input vector. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **beta**: `[in] double` scalar constant. +- **Y**: `[inout] double*` second input vector. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. + +```c +void c_dgemv( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) +``` + +#### c_dgemv_ndarray( trans, M, N, alpha, \*A, sa1, sa2, oa, \*X, sx, ox, beta, \*Y, sy, oy ) + +Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + +```c +#include "stdlib/blas/base/shared.h" + +const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 }; +const double x[] = { 1.0, 2.0, 3.0 }; +double y[] = { 1.0, 2.0, 3.0 }; + +c_dgemv_ndarray( CblasNoTrans, 3, 3, 1.0, A, 1, 3, 0, x, 1, 0, 1.0, y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed. +- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`. +- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`. +- **alpha**: `[in] double` scalar. +- **A**: `[in] double*` input matrix. +- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`. +- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`. +- **oa**: `[in] CBLAS_INT` starting index for `A`. +- **X**: `[in] double*` first input vector. +- **sx**: `[in] CBLAS_INT` stride length for `X`. +- **ox**: `[in] CBLAS_INT` starting index for `X`. +- **beta**: `[in] double` scalar. +- **Y**: `[inout] double*` second input vector. +- **sy**: `[in] CBLAS_INT` stride length for `Y`. +- **oy**: `[in] CBLAS_INT` starting index for `Y`. + +```c +void c_dgemv_ndarray( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 matrix stored in row-major order: + const double A[ 3*3 ] = { + 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, + 7.0, 8.0, 9.0 + }; + + // Define `x` and `y` vectors: + const double x[ 3 ] = { 1.0, 2.0, 3.0 }; + double y[ 3 ] = { 1.0, 2.0, 3.0 }; + + // Specify the number of elements along each dimension of `A`: + const int M = 3; + const int N = 3; + + // Perform the matrix-vector operation `y = α*A*x + β*y`: + c_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0, A, M, x, 1, 1.0, y, 1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } + + // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: + c_dgemv_ndarray( CblasNoTrans, M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.js new file mode 100644 index 000000000000..e470c16d3df6 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var pkg = require( './../package.json' ).name; +var dsgdTrainer = require( './../lib/dsgd_trainer.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var ws = new Float64Array( N ); + var x = uniform( N*N, -10.0, 10.0, options ); + var y = uniform( N, -10.0, 10.0, options ); + var w = uniform( N, -0.05, 0.05, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var params; + var z; + var i; + + params = new Params(); + + params.penalty = 'l2'; + params.learningRate = 'constant'; + params.lossFunction = 'hinge'; + params.intercept = 0.0; + params.maxIter = 500; + params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + params.lossFunctionParams = new Float64Array( [ 0.0 ] ); + params.fitIntercept = true; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dsgdTrainer( 'row-major', N, N, x, N, y, 1, w, 1, ws, 1, params ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( format( '%s:size=%d', pkg, N*N ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.native.js new file mode 100644 index 000000000000..b6c8d9406d86 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.native.js @@ -0,0 +1,127 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dsgdTrainer = tryRequire( resolve( __dirname, './../lib/dsgd_trainer.native.js' ) ); +var opts = { + 'skip': ( dsgdTrainer instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var ws = new Float64Array( N ); + var x = uniform( N*N, -10.0, 10.0, options ); + var y = uniform( N, -10.0, 10.0, options ); + var w = uniform( N, -0.05, 0.05, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var params; + var z; + var i; + + params = new Params(); + + params.penalty = 'l2'; + params.learningRate = 'constant'; + params.lossFunction = 'hinge'; + params.intercept = 0.0; + params.maxIter = 500; + params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + params.lossFunctionParams = new Float64Array( [ 0.0 ] ); + params.fitIntercept = true; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dsgdTrainer( 'row-major', N, N, x, N, y, 1, w, 1, ws, 1, params ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( format( '%s::native:size=%d', pkg, N*N ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..b313f6ec99b8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var pkg = require( './../package.json' ).name; +var dsgdTrainer = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var ws = new Float64Array( N ); + var x = uniform( N*N, -10.0, 10.0, options ); + var y = uniform( N, -10.0, 10.0, options ); + var w = uniform( N, -0.05, 0.05, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var params; + var z; + var i; + + params = new Params(); + + params.penalty = 'l2'; + params.learningRate = 'constant'; + params.lossFunction = 'hinge'; + params.intercept = 0.0; + params.maxIter = 500; + params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + params.lossFunctionParams = new Float64Array( [ 0.0 ] ); + params.fitIntercept = true; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dsgdTrainer( N, N, x, N, 1, 0, y, 1, 0, w, 1, 0, ws, 1, 0, params ); // eslint-disable-line max-len + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( format( '%s:ndarray:size=%d', pkg, N*N ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..17b0c6f752d0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,127 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Params = require( '@stdlib/ml/base/sgd/params/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dsgdTrainer = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dsgdTrainer instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var ws = new Float64Array( N ); + var x = uniform( N*N, -10.0, 10.0, options ); + var y = uniform( N, -10.0, 10.0, options ); + var w = uniform( N, -0.05, 0.05, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var params; + var z; + var i; + + params = new Params(); + + params.penalty = 'l2'; + params.learningRate = 'constant'; + params.lossFunction = 'hinge'; + params.intercept = 0.0; + params.maxIter = 500; + params.penaltyParams = new Float64Array( [ 2.5, 0.0 ] ); + params.learningRateParams = new Float64Array( [ 0.01, 0.0 ] ); + params.lossFunctionParams = new Float64Array( [ 0.0 ] ); + params.fitIntercept = true; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dsgdTrainer( N, N, x, N, 1, 0, y, 1, 0, w, 1, 0, ws, 1, 0, params ); // eslint-disable-line max-len + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( N ); + bench( format( '%s::native:ndarray:size=%d', pkg, N*N ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/Makefile b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/Makefile new file mode 100644 index 000000000000..cce2c865d7ad --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..ee77ddd0997a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/benchmark/c/benchmark.length.c @@ -0,0 +1,253 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd_trainer.h" +#include +#include +#include +#include +#include + +#define NAME "dsgd_trainer" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param N number of features +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int N ) { + double elapsed; + double *ws; + double *x; + double *y; + double *w; + double t; + int i; + int j; + + x = (double *) malloc( N * N * sizeof( double ) ); + y = (double *) malloc( N * sizeof( double ) ); + w = (double *) malloc( N * sizeof( double ) ); + ws = (double *) malloc( N * sizeof( double ) ); + for ( i = 0; i < N; i++ ) { + y[ i ] = random_uniform( -10.0, 10.0 ); // sgd regression + for ( j = 0; j < N; j++ ) { + w[ ( i*N ) + j ] = random_uniform( -0.05, 0.05 ); + } + x[ i ] = random_uniform( -10.0, 10.0 ); + } + struct stdlib_ml_sgd_params_float64_params params = { + .penaltyParams = { 2.5, 0.0 }, + .learningRateParams = { 0.01, 0.0 }, + .lossFunctionParams = { 0.0 }, + .intercept = 0.0, + .maxIter = 500, + .penalty = 2, // l2 + .learningRate = 0, // constant + .lossFunction = 0, // hinge + .fitIntercept = true + }; + + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + for ( j = 0; j < N; j++ ) { + ws[ j ] = 0.0; + } + stdlib_strided_dsgd_trainer( CblasRowMajor, N, N, x, N, y, 1, w, 1, ws, 1, params ); + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + free( w ); + free( ws ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param N number of features +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int N ) { + double elapsed; + double *ws; + double *x; + double *y; + double *w; + double t; + int i; + int j; + + x = (double *) malloc( N * N * sizeof( double ) ); + y = (double *) malloc( N * sizeof( double ) ); + w = (double *) malloc( N * sizeof( double ) ); + ws = (double *) malloc( N * sizeof( double ) ); + for ( i = 0; i < N; i++ ) { + y[ i ] = random_uniform( -10.0, 10.0 ); // sgd regression + for ( j = 0; j < N; j++ ) { + w[ ( i*N ) + j ] = random_uniform( -0.05, 0.05 ); + } + x[ i ] = random_uniform( -10.0, 10.0 ); + } + struct stdlib_ml_sgd_params_float64_params params = { + .penaltyParams = { 2.5, 0.0 }, + .learningRateParams = { 0.01, 0.0 }, + .lossFunctionParams = { 0.0 }, + .intercept = 0.0, + .maxIter = 500, + .penalty = 2, // l2 + .learningRate = 0, // constant + .lossFunction = 0, // hinge + .fitIntercept = true + }; + + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + for ( j = 0; j < N; j++ ) { + ws[ j ] = 0.0; + } + stdlib_strided_dsgd_trainer_ndarray( N, N, x, N, N, 0, y, 1, 0, w, 1, 0, ws, 1, 0, params ); + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%N ] != y[ i%N ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + free( w ); + free( ws ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int N; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:size=%d\n", NAME, N*N ); + elapsed = benchmark1( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:size=%d\n", NAME, N*N ); + elapsed = benchmark2( iter, N ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp new file mode 100644 index 000000000000..08de71a2020e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp @@ -0,0 +1,265 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt new file mode 100644 index 000000000000..2cab17fe04cd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt @@ -0,0 +1,160 @@ + +{{alias}}( order, trans, M, N, α, A, lda, x, sx, β, y, sy ) + Performs one of the matrix-vector operations `y = α*A*x + β*y` or + `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are + vectors, and `A` is an `M` by `N` matrix. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `M` or `N` is equal to `0`, the function returns `y` unchanged. + + If `α` equals `0` and `β` equals `1`, the function returns `y` unchanged. + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. + + trans: string + Specifies whether `A` should be transposed, conjugate-transposed, or not + transposed. + + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + α: number + Scalar constant. + + A: Float64Array + Input matrix. + + lda: integer + Stride of the first dimension of `A` (a.k.a., leading dimension of the + matrix `A`). + + x: Float64Array + First input vector. + + sx: integer + Index increment for `x`. + + β: number + Scalar constant. + + y: Float64Array + Second input vector. + + sy: integer + Index increment for `y`. + + Returns + ------- + y: Float64Array + Second input vector. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ord = 'row-major'; + > var trans = 'no-transpose'; + > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x, 1, 1.0, y, 1 ) + [ 4.0, 8.0 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x, -1, 1.0, y, -1 ) + [ 8.0, 4.0 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] ); + > A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 ); + > y0 + [ 0.0, 8.0, 4.0 ] + + +{{alias}}.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy ) + Performs one of the matrix-vector operations `y = α*A*x + β*y` or + `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and + `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + trans: string + Specifies whether `A` should be transposed, conjugate-transposed, or not + transposed. + + M: integer + Number of rows in `A`. + + N: integer + Number of columns in `A`. + + α: number + Scalar constant. + + A: Float64Array + Input matrix. + + sa1: integer + Stride of the first dimension of `A`. + + sa2: integer + Stride of the second dimension of `A`. + + oa: integer + Starting index for `A`. + + x: Float64Array + First input vector. + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + β: number + Scalar constant. + + y: Float64Array + Second input vector. + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + y: Float64Array + Second input vector. + + Examples + -------- + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); + > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var trans = 'no-transpose'; + > {{alias}}.ndarray( trans, 2, 2, 1, A, 2, 1, 0, x, 1, 0, 1, y, 1, 0 ) + [ 4.0, 8.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/index.d.ts new file mode 100644 index 000000000000..841babe49551 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/index.d.ts @@ -0,0 +1,134 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Layout } from '@stdlib/types/blas'; +import { Params } from '@stdlib/ml/base/sgd/params/float64'; + +/** +* Interface describing `dsgdTrainer`. +*/ +interface Routine { + /** + * Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + * + * @param order - storage layout + * @param trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed + * @param M - number of rows in the matrix `A` + * @param N - number of columns in the matrix `A` + * @param alpha - scalar constant + * @param A - input matrix + * @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) + * @param x - first input vector + * @param strideX - `x` stride length + * @param beta - scalar constant + * @param y - second input vector + * @param strideY - `y` stride length + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0 ] ); + * + * dsgdTrainer( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); + * // y => [ 7.0, 16.0 ] + */ + ( order: Layout, M: number, N: number, x: Float64Array, LDX: number, y: Float64Array, strideY: number, w: Float64Array, strideW: number, ws: Float64Array, strideWS: number, params: Params ): Float64Array; + + /** + * Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. + * + * @param trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed + * @param M - number of rows in the matrix `A` + * @param N - number of columns in the matrix `A` + * @param alpha - scalar constant + * @param A - input matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @param x - first input vector + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param beta - scalar constant + * @param y - second input vector + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0 ] ); + * + * dsgdTrainer.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); + * // y => [ 7.0, 16.0 ] + */ + ndarray( M: number, N: number, x: Float64Array, strideX1: number, strideX2: number, offsetX: number, y: Float64Array, strideY: number, offset: number, w: Float64Array, strideW: number, offsetW: number, ws: Float64Array, strideWS: number, offsetWS: number, params: Params ): Float64Array; +} + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param order - storage layout +* @param trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed +* @param M - number of rows in the matrix `A` +* @param N - number of columns in the matrix `A` +* @param alpha - scalar constant +* @param A - input matrix +* @param LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param x - first input vector +* @param strideX - `x` stride length +* @param beta - scalar constant +* @param y - second input vector +* @param strideY - `y` stride length +* @returns `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dsgdTrainer( 'row-major', 'no-transpose', 3, 3, 1.0, A, 3, x, -1, 1.0, y, -1 ); +* // y => [ 25.0, 16.0, 7.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* +* dsgdTrainer.ndarray( 'no-transpose', 3, 3, 1.0, A, 3, 1, 0, x, -1, 2, 1.0, y, -1, 2 ); +* // y => [ 25.0, 16.0, 7.0 ] +*/ +declare var dsgdTrainer: Routine; + + +// EXPORTS // + +export = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts new file mode 100644 index 000000000000..dd44acf1293f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts @@ -0,0 +1,517 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import dgemv = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 10, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( true, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( false, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( null, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( undefined, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( [], 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( {}, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( ( x: number ): number => x, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 10, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', true, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', false, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', null, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', undefined, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', [ '1' ], 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', {}, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', ( x: number ): number => x, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', '10', 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', true, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', false, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', null, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', undefined, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', [], 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', {}, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', ( x: number ): number => x, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, '10', 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, true, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, false, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, null, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, undefined, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, [], 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, {}, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, ( x: number ): number => x, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, '10', A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, true, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, false, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, null, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, undefined, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, [], A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, {}, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, ( x: number ): number => x, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, 10, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, '10', 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, true, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, false, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, null, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, undefined, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, [ '1' ], 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, {}, 10, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, ( x: number ): number => x, 10, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, '10', x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, true, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, false, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, null, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, undefined, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, [], x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, {}, x, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, ( x: number ): number => x, x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a Float64Array... +{ + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, 10, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, '10', 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, true, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, false, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, null, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, undefined, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, [ '1' ], 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, {}, 1, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, ( x: number ): number => x, 1, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, '10', 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, true, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, false, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, null, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, undefined, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, [], 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, {}, 1.0, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, ( x: number ): number => x, 1.0, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, '10', y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, true, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, false, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, null, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, undefined, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, [], y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, {}, y, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, 10, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, '10', 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, true, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, false, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, null, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, undefined, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, [ '1' ], 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, {}, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, '10' ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, true ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, false ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, null ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, undefined ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, [] ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, {} ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv(); // $ExpectError + dgemv( 'row-major' ); // $ExpectError + dgemv( 'row-major', 'no-transpose' ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0 ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y ); // $ExpectError + dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 10, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( true, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( false, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( null, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( undefined, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( [ '1' ], 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( {}, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( ( x: number ): number => x, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', '10', 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', true, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', false, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', null, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', undefined, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', [], 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', {}, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', ( x: number ): number => x, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, '10', 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, true, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, false, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, null, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, undefined, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, [], 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, {}, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, ( x: number ): number => x, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, '10', A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, true, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, false, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, null, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, undefined, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, [], A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, {}, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, ( x: number ): number => x, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, 10, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, '10', 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, true, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, false, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, null, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, undefined, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, [ '1' ], 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, {}, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, ( x: number ): number => x, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, '10', 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, true, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, false, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, null, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, undefined, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, [], 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, {}, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, ( x: number ): number => x, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, '10', 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, true, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, false, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, null, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, undefined, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, [], 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, {}, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, ( x: number ): number => x, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, '10', x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, true, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, false, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, null, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, undefined, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, [], x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, {}, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, ( x: number ): number => x, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a Float64Array... +{ + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, 10, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, '10', 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, true, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, false, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, null, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, undefined, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, [ '1' ], 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, {}, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, ( x: number ): number => x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, '10', 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, true, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, false, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, null, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, undefined, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, [], 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, {}, 0, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, ( x: number ): number => x, 0, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, '10', 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, true, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, false, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, null, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, undefined, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, [], 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, {}, 1.0, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, ( x: number ): number => x, 1.0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, '10', y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, true, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, false, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, null, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, undefined, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, [], y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, {}, y, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a thirteenth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, 10, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, '10', 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, true, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, false, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, null, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, undefined, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, [ '1' ], 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, {}, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, '10', 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, true, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, false, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, null, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, undefined, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, [], 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, {}, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifteenth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, '10' ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, true ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, false ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, null ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, undefined ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, [] ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, {} ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const A = new Float64Array( 20 ); + + dgemv.ndarray(); // $ExpectError + dgemv.ndarray( 'no-transpose' ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1 ); // $ExpectError + dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c new file mode 100644 index 000000000000..9814336e9541 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/shared.h" +#include + +int main( void ) { + // Define a 3x3 matrix stored in row-major order: + const double A[ 3*3 ] = { + 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, + 7.0, 8.0, 9.0 + }; + + // Define `x` and `y` vectors: + const double x[ 3 ] = { 1.0, 2.0, 3.0 }; + double y[ 3 ] = { 1.0, 2.0, 3.0 }; + + // Specify the number of elements along each dimension of `A`: + const int M = 3; + const int N = 3; + + // Perform the matrix-vector operation `y = α*A*x + β*y`: + c_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0, A, M, x, 1, 1.0, y, 1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } + + // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: + c_dgemv_ndarray( CblasNoTrans, M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi new file mode 100644 index 000000000000..4217944b5d20 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Struct for storing SGD parameters. +*/ +struct stdlib_ml_sgd_params_float64_params { + // Parameters specific to the regularization function being used: + double penaltyParams[ 2 ]; + + // Parameters specific to the learning rate scheduler being used: + double learningRateParams[ 2 ]; + + // Parameters specific to the loss function being used: + double lossFunctionParams[ 1 ]; + + // Initial intercept value: + double intercept; + + // Maximum number of iterations to run: + int32_t maxIter; + + // Regularization function to be used: + int8_t penalty; + + // Learning rate scheduler to be used: + int8_t learningRate; + + // Loss function to be used: + int8_t lossFunction; + + // Boolean indicating whether to include intercept: + bool fitIntercept; +}; + +/** +* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix. +*/ +void API_SUFFIX(stdlib_strided_dsgd_trainer)( const CBLAS_LAYOUT layout, const CBLAS_INT M, const CBLAS_INT N, const double *x, const CBLAS_INT LDX, const double *y, const CBLAS_INT strideY, double *w, const CBLAS_INT strideW, double *ws, const CBLAS_INT strideWS, const struct stdlib_ml_sgd_params_float64_params params ); + +/** +* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix using alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_dsgd_trainer_ndarray)( const CBLAS_INT M, const CBLAS_INT N, const double *x, const CBLAS_INT strideX1, const CBLAS_INT strideX2, const CBLAS_INT offsetX, const double *y, const CBLAS_INT strideY, const CBLAS_INT offsetY, double *w, const CBLAS_INT strideW, const CBLAS_INT offsetW, double *ws, const CBLAS_INT strideWS, const CBLAS_INT offsetWS, const struct stdlib_ml_sgd_params_float64_params params ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_ML_STRIDED_DSGD_TRAINER_H diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js index 329c096d5123..d8584484b201 100644 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/base.js @@ -21,6 +21,7 @@ // MODULES // var logger = require( 'debug' ); +var params2str = require( '@stdlib/ml/base/sgd/params/to-string' ); var ddot = require( '@stdlib/blas/base/ddot' ).ndarray; var daxpy = require( '@stdlib/blas/base/daxpy' ).ndarray; var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; @@ -44,32 +45,23 @@ var MAX_DLOSS = 1e12; * Trains a linear model with the squared epsilon-insensitive loss via stochastic gradient descent. * * @private -* @param {string} penalty - penalty type: `'l1'`, `'l2'`, or `'elasticnet'` -* @param {string} learningRate - schedule: `'constant'` (eta = eta0), `'invscaling'` (eta = eta0/t^powerT), `'basic'` (eta = 10/(10+t)), or `'pegasos'` (eta = 1/(lambda*t)) -* @param {boolean} fitIntercept - boolean indicating whether to fit an intercept term * @param {NonNegativeInteger} M - number of samples * @param {NonNegativeInteger} N - number of features -* @param {number} l1Ratio - elastic-net mixing parameter on the interval `[0,1]` (`0` => L2, `1` => L1); overridden for pure L1/L2 penalties -* @param {PositiveInteger} maxIter - number of epochs -* @param {number} eta0 - initial/base learning rate (used by `'constant'` and `'invscaling'`) -* @param {number} powerT - exponent for the inverse-scaling schedule (only used by `'invscaling'`) -* @param {number} epsilon - width of the insensitive region of the loss -* @param {number} lambda - regularization strength -* @param {number} intercept - initial intercept +* @param {Float64Array} x - `M` by `N` input matrix +* @param {integer} strideX1 - stride of the first dimension of `x` +* @param {integer} strideX2 - stride of the second dimension of `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float64Array} y - target vector * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Float64Array} w - weight vector * @param {integer} strideW - stride length for `w` * @param {NonNegativeInteger} offsetW - starting index for `w` -* @param {Float64Array} x - `M` by `N` input matrix -* @param {integer} strideX1 - stride of the first dimension of `x` -* @param {integer} strideX2 - stride of the second dimension of `x` -* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float64Array} workspace - workspace array * @param {integer} strideWS - stride length for `workspace` * @param {NonNegativeInteger} offsetWS - starting index for `workspace` -* @returns {Object} results object with `intercept` and `weights` +* @param {Params} params - parameters object +* @returns {Float64Array} `w` * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -80,7 +72,7 @@ var MAX_DLOSS = 1e12; * var w = new Float64Array( 2 ); * var workspace = new Float64Array( 2 ); * -* var out = dsgdTrainerSqEpsIns( +* var out = dsgdTrainer( * 'l2', 'invscaling', true, // penalty, learningRate, fitIntercept * 4, 2, 0.0, // M, N, l1Ratio * 1000, // maxIter @@ -93,12 +85,24 @@ var MAX_DLOSS = 1e12; * workspace, 1, 0 // workspace, strideWS, offsetWS * ); */ -function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, strideY, offsetY, w, strideW, offsetW, x, strideX1, strideX2, offsetX, workspace, strideWS, offsetWS ) { // eslint-disable-line max-params, max-len +function dsgdTrainer( M, N, x, strideX1, strideX2, offsetX, y, strideY, offsetY, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-params, max-len + var lossFunctionParams; + var learningRateParams; + var penaltyParams; + var lossFunction; + var learningRate; + var fitIntercept; var scaleFactor; + var intercept; + var penalty; + var decayFn; + var truncFn; + var maxIter; + var lossFn; var update; - var factor; var epoch; var dloss; + var lrFn; var eta; var ox; var oy; @@ -107,46 +111,53 @@ function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, var i; var u; - debug( 'Starting SGD trainer with squared epsilon insensitive loss...' ); - debug( 'M = %d, N = %d, penalty = %s, lr scheduler = %s, loss function = %s, eta0 = %s, ', M, N, penalty, learningRate, 'squared-epsilon-insensitive-loss', eta0 ); + penalty = params.penalty; + lossFunction = params.lossFunction; + learningRate = params.learningRate; + lrFn = LEARNING_RATE_METHODS[ learningRate ]; + lossFn = LOSS_FUNCTIONS[ lossFunction ]; + decayFn = DECAYS[ penalty ]; + truncFn = TRUNCATIONS[ penalty ]; + lossFunctionParams = params.lossFunctionParams; + learningRateParams = params.learningRateParams; + penaltyParams = params.penaltyParams; + fitIntercept = params.fitIntercept; + intercept = params.intercept; + maxIter = params.maxIter; + + debug( 'Starting SGD trainer with %i samples and %i features', M, N ); + debug( params2str( params ) ); /* - * w - (k*N) (feature vector) + * w - N (feature vector) * x - M*N (input vector) - * y - k (output vector) + * y - M (output vector) */ - /* - * DOUBTS? - * - should I include the intercept with the weight vector itself? - * - if yes, then should N be including intercept? - * - if no, then how do I show it to the user? should I have a `intercept` field in the results struct - * - * - Should we implement a standalone weight matrix just like how `ml/incr/sgd-regression` as well as - * the sklearn API did? They referred sofia-ml as far as I know. - */ + /** + * y -> [ ... ] (vector of size M, as there are M samples) + * w -> [ ... ] (vector of size N, as there are N weights, one per input feature) + * x -> [ ... ] (vector of size MxN, as there are N features per sample, M samples) + */ - // Do we set this here or expect higher level user to pass it? - if ( penalty === 'l2' ) { - l1Ratio = 0.0; - } else if ( penalty === 'l1' ) { - l1Ratio = 1.0; + if ( penalty === 2 ) { // l2 + penaltyParams[ 1 ] = 0.0; + } else if ( penalty === 1 ) { // l1 + penaltyParams[ 1 ] = 1.0; } - eta = eta0; t = 1; - scaleFactor = 1.0; u = 0.0; + scaleFactor = 1.0; for ( epoch = 1; epoch <= maxIter; epoch++ ) { ox = offsetX; oy = offsetY; for ( i = 0; i < M; i++ ) { p = ( scaleFactor*ddot( N, w, strideW, offsetW, x, strideX2, ox ) ) + intercept; // eslint-disable-line max-len - var params = []; // update later - eta = LEARNING_RATE_METHODS[ learningRate ]( t, params ); + eta = lrFn( t, learningRateParams ); // eslint-disable-line max-len - dloss = LOSS_FUNCTIONS[ lossFunction ]( y[ oy ], p, params ); + dloss = lossFn( y[ oy ], p, lossFunctionParams ); // eslint-disable-line max-len if ( dloss < -MAX_DLOSS ) { dloss = -MAX_DLOSS; } else if ( dloss > MAX_DLOSS ) { @@ -154,8 +165,7 @@ function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, } update = -eta * dloss; - var penaltyParams = []; - scaleFactor = DECAYS[ penalty ]( scaleFactor, penaltyParams ); + scaleFactor = decayFn( scaleFactor, eta, penaltyParams ); // eslint-disable-line max-len // if ( penalty === 'l2' || penalty === 'elasticnet' ) { // factor = 1.0 - ( ( 1.0 - l1Ratio ) * eta * lambda ); // scaleFactor *= max( 0.0, factor ); @@ -174,7 +184,7 @@ function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, intercept += update; } - u = TRUNCATIONS[ penalty ]( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, penaltyParams ); // eslint-disable-line max-len + u = truncFn( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, penaltyParams ); // eslint-disable-line max-len // if ( penalty === 'l1' || penalty === 'elasticnet' ) { // u += ( l1Ratio * eta * lambda ); // l1Penalty( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS ); // eslint-disable-line max-len @@ -194,22 +204,17 @@ function dsgdTrainerSqEpsIns( penalty, learningRate, lossFunction, fitIntercept, scaleFactor = 1.0; } - debug( 'Finished SGD trainer with squared epsilon insensitive loss.' ); + debug( 'Finished SGD trainer.' ); - return { - 'intercept': intercept, - 'weights': w - }; - - /* - * returning this doesn't look solid, I have to brainstorm here. - * we will have to either return `intercept`, or keep `intercept` inside the weight matrix, - * as we cant pass a number by reference as fn argument, so the `intercept` user passes won't be updated, instead - * a copy of that `intercept` is being updated here. - */ + if ( fitIntercept ) { + w[ offsetW + ( ( strideW * N ) + 1 ) ] = intercept; // We expect consumer to pass an array of size N+1 if they set `fitIntercept = true` + // TODO: Do a size check in sgd_trainer.js + // if `fitIntercept = true`, check if its size is N+1 + } + return w; } // EXPORTS // -module.exports = dsgdTrainerSqEpsIns; +module.exports = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js index 7b583de4b6d7..57843440820e 100644 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/decay.js @@ -25,12 +25,24 @@ var max = require( '@stdlib/math/base/special/max' ); // VARIABLES // -var DECAYS = { - 'elasticnet': l2Decay, - 'l1': identityDecay, - 'l2': l2Decay, - 'none': identityDecay -}; +/** +* Weight decay functions, indexed by penalty enumeration constant. +* +* @private +* @name DECAYS +* @constant +* @type {Array} +* +* @example +* var f = DECAYS[ 2 ]; +* // returns +*/ +var DECAYS = [ + l2Decay, // 0: elasticnet + identityDecay, // 1: l1 + l2Decay, // 2: l2 + identityDecay // 3: none +]; // FUNCTIONS // @@ -44,15 +56,16 @@ var DECAYS = { * * @private * @param {NonNegativeInteger} scaleFactor - current iteration. +* @param {NonNegativeInteger} eta - learning rate. * @param {Float64Array} params - strided array containing regularizer specific parameters. * @returns {number} scale factor */ -function identityDecay( scaleFactor, params ) { // eslint-disable-line no-unused-vars +function identityDecay( scaleFactor, eta, params ) { // eslint-disable-line no-unused-vars return scaleFactor; } /** -* Computes learning rate by applying the inverse scaling learning rate scheduler. +* Computes scale factor by applying the L2 decay. * * Note: * @@ -60,11 +73,12 @@ function identityDecay( scaleFactor, params ) { // eslint-disable-line no-unused * * @private * @param {NonNegativeInteger} scaleFactor - current iteration. +* @param {NonNegativeInteger} eta - learning rate. * @param {Float64Array} params - strided array containing regularizer specific parameters. * @returns {number} scale factor */ -function l2Decay( scaleFactor, params ) { - return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * params[ 0 ] * params[ 1 ] ) ); // eslint-disable-line max-len +function l2Decay( scaleFactor, eta, params ) { + return scaleFactor * max( 0.0, 1.0 - ( ( 1.0 - params[ 2 ] ) * eta * params[ 1 ] ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.js new file mode 100644 index 000000000000..6385bfdd8e35 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var resolvePenaltyStr = require( '@stdlib/ml/base/sgd/penalty-resolve-str' ); +var resolveLRStr = require( '@stdlib/ml/base/sgd/learning-rate-resolve-str' ); +var resolveLossFnStr = require( '@stdlib/ml/base/sgd/loss-function-resolve-str' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @private +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {Float64Array} x - `M` by `N` input matrix +* @param {NonNegativeInteger} LDX - stride of the first dimension of `x` (a.k.a., leading dimension of the matrix `x`) +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {Params} params - parameters object +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} thirteenth argument's `penalty` member must be a valid penalty +* @throws {TypeError} thirteenth argument's `learningRate` member must be a valid learning rate +* @throws {TypeError} thirteenth argument's `lossFunction` member must be a valid loss function +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} sixth argument must be non-zero +* @throws {RangeError} fifth argument must be a valid stride +* @throws {RangeError} eighth argument must be a valid stride +* @throws {RangeError} tenth argument must be a valid stride +* @throws {RangeError} twelfth argument must be a valid stride +* @returns {Float64Array} `w` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dsgdTrainer( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 16.0 ] +*/ +function dsgdTrainer( order, M, N, x, LDX, y, strideY, w, strideW, workspace, strideWS, params ) { // eslint-disable-line max-params, max-len + var iscm; + var lsfn; + var vala; + var sx1; + var sx2; + var ows; + var oy; + var ow; + var lr; + var p; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + p = resolvePenaltyStr( params.penalty ); + lr = resolveLRStr( params.learningRate ); + lsfn = resolveLossFnStr( params.lossFunction ); + if ( p === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `penalty` member must be a valid penalty. Value: `%s`.', params.penalty ) ); + } + if ( lr === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `learningRate` member must be a valid learning rate. Value: `%s`.', params.learningRate ) ); + } + if ( lsfn === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `lossFunction` member must be a valid loss function. Value: `%s`.', params.lossFunction ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + iscm = isColumnMajor( order ); + if ( iscm ) { + vala = M; + } else { + vala = N; + } + if ( LDX < max( 1, vala ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', vala, LDX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideY ) ); + } + if ( strideW === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideW ) ); + } + if ( strideWS === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + // Check if we can early return... + if ( M === 0 || N === 0 ) { + return w; + } + oy = stride2offset( M, strideY ); + ow = stride2offset( N, strideW ); + ows = stride2offset( N, strideWS ); + if ( iscm ) { + sx1 = 1; + sx2 = LDX; + } else { // order === 'row-major' + sx1 = LDX; + sx2 = 1; + } + return base( M, N, x, sx1, sx2, 0, y, strideY, oy, w, strideW, ow, workspace, strideWS, ows, params ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.native.js new file mode 100644 index 000000000000..75c5023bc440 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/dsgd_trainer.native.js @@ -0,0 +1,131 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var resolveOrder = require( '@stdlib/blas/base/layout-resolve-enum' ); +var resolvePenaltyStr = require( '@stdlib/ml/base/sgd/penalty-resolve-str' ); +var resolveLRStr = require( '@stdlib/ml/base/sgd/learning-rate-resolve-str' ); +var resolveLossFnStr = require( '@stdlib/ml/base/sgd/loss-function-resolve-str' ); +var format = require( '@stdlib/string/format' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @private +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {Float64Array} x - `M` by `N` input matrix +* @param {NonNegativeInteger} LDX - stride of the first dimension of `x` (a.k.a., leading dimension of the matrix `x`) +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {Params} params - parameters object +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} thirteenth argument's `penalty` member must be a valid penalty +* @throws {TypeError} thirteenth argument's `learningRate` member must be a valid learning rate +* @throws {TypeError} thirteenth argument's `lossFunction` member must be a valid loss function +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} sixth argument must be non-zero +* @throws {RangeError} fifth argument must be a valid stride +* @throws {RangeError} eighth argument must be a valid stride +* @throws {RangeError} tenth argument must be a valid stride +* @throws {RangeError} twelfth argument must be a valid stride +* @returns {Float64Array} `w` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dsgdTrainer( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 16.0 ] +*/ +function dsgdTrainer( order, M, N, x, LDX, y, strideY, w, strideW, workspace, strideWS, params ) { // eslint-disable-line max-params, max-len + var iscm; + var lsfn; + var vala; + var lr; + var p; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + p = resolvePenaltyStr( params.penalty ); + lr = resolveLRStr( params.learningRate ); + lsfn = resolveLossFnStr( params.lossFunction ); + if ( p === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `penalty` member must be a valid penalty. Value: `%s`.', params.penalty ) ); + } + if ( lr === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `learningRate` member must be a valid learning rate. Value: `%s`.', params.learningRate ) ); + } + if ( lsfn === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `lossFunction` member must be a valid loss function. Value: `%s`.', params.lossFunction ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + iscm = isColumnMajor( order ); + if ( iscm ) { + vala = M; + } else { + vala = N; + } + if ( LDX < max( 1, vala ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', vala, LDX ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideY ) ); + } + if ( strideW === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideW ) ); + } + if ( strideWS === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + // Check if we can early return... + if ( M === 0 || N === 0 ) { + return w; + } + return addon( resolveOrder( order ), M, N, x, LDX, y, strideY, w, strideW, workspace, strideWS, params ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/index.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/index.js new file mode 100644 index 000000000000..cba0a58050a2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/index.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 2 routine to perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @module @stdlib/ml/strided/dsgd-trainer +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsgdTrainer = require( '@stdlib/ml/strided/dsgd-trainer' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dsgdTrainer( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); +* // y => [ 7.0, 16.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsgdTrainer = require( '@stdlib/ml/strided/dsgd-trainer' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dsgdTrainer.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 16.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dsgdTrainer; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dsgdTrainer = main; +} else { + dsgdTrainer = tmp; +} + + +// EXPORTS // + +module.exports = dsgdTrainer; + +// exports: { "ndarray": "dsgdTrainer.ndarray" } diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js index 3c22b3e1a078..87045da1ff81 100644 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/learning_rate.js @@ -25,15 +25,49 @@ var pow = require( '@stdlib/math/base/special/pow' ); // VARIABLES // -var LEARNING_RATE_METHODS = { - 'basic': basic, - 'invscaling': invscaling, - 'pegasos': pegasos -}; +/** +* Learning rate schedulers, indexed by learning rate enumeration constant. +* +* @private +* @name LEARNING_RATE_METHODS +* @constant +* @type {Array} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var f = LEARNING_RATE_METHODS[ 2 ]; +* // returns +* +* var eta = f( 4.0, new Float64Array( [ 0.02, 0.5 ] ) ); +* // returns 0.01 +*/ +var LEARNING_RATE_METHODS = [ + basic, // 0: basic + constant, // 1: constant + invscaling, // 2: invscaling + pegasos // 3: pegasos +]; // FUNCTIONS // +/** +* Computes learning rate by applying the constant learning rate scheduler. +* +* Note: +* +* - Here `params` => `[ eta0 ]` +* +* @private +* @param {NonNegativeInteger} t - current iteration. +* @param {Float64Array} params - strided array containing scheduler specific parameters. +* @returns {number} learning rate +*/ +function constant( t, params ) { // eslint-disable-line no-unused-vars + return params[ 0 ]; +} + /** * Computes learning rate by applying the basic learning rate scheduler. * diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js index a60f0f1a3ada..35affce4b8d0 100644 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/loss.js @@ -20,72 +20,199 @@ // MODULES // -var hingeGradient = require( '@stdlib/ml/base/loss/float64/hinge-gradient' ); var logGradient = require( '@stdlib/ml/base/loss/float64/log-gradient' ); -var modifiedHuberGradient = require( '@stdlib/ml/base/loss/float64/modified-huber-gradient' ); +var huberGradient = require( '@stdlib/ml/base/loss/float64/huber-gradient' ); +var hingeGradient = require( '@stdlib/ml/base/loss/float64/hinge-gradient' ); var squaredHingeGradient = require( '@stdlib/ml/base/loss/float64/squared-hinge-gradient' ); var squaredErrorGradient = require( '@stdlib/ml/base/loss/float64/squared-error-gradient' ); -var huberGradient = require( '@stdlib/ml/base/loss/float64/huber-gradient' ); +var modifiedHuberGradient = require( '@stdlib/ml/base/loss/float64/modified-huber-gradient' ); var epsilonInsensitiveGradient = require( '@stdlib/ml/base/loss/float64/epsilon-insensitive-gradient' ); var squaredEpsilonInsensitiveGradient = require( '@stdlib/ml/base/loss/float64/squared-epsilon-insensitive-gradient' ); // VARIABLES // -var LOSS_FUNCTIONS = { - 'epsilon-insensitive': epsilonInsensitive, - 'hinge': hinge, - 'huber': huber, - 'log': log, - 'modified-huber': modifiedHuber, - 'perceptron': perceptron, - 'squared-error': squaredError, - 'squared-epsilon-insensitive': squaredEpsilonInsensitive, - 'squared-hinge': squaredHinge -}; +/** +* Loss function gradients, indexed by loss function enumeration constant. +* +* @private +* @name LOSS_FUNCTIONS +* @constant +* @type {Array} +* +* @example +* var f = LOSS_FUNCTIONS[ 1 ]; +* // returns +*/ +var LOSS_FUNCTIONS = [ + epsilonInsensitive, // 0: epsilon-insensitive + hinge, // 1: hinge + huber, // 2: huber + log, // 3: log + modifiedHuber, // 4: modified-huber + perceptron, // 5: perceptron + squaredEpsilonInsensitive, // 6: squared-epsilon-insensitive + squaredError, // 7: squared-error + squaredHinge // 8: squared-hinge +]; // FUNCTIONS // -// params => [ ] -function hinge( y, p, params ) { - hingeGradient( 1.0, 1.0, y, p ); +/** +* Computes the gradient of the hinge loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function hinge( y, p, params ) { // eslint-disable-line no-unused-vars + return hingeGradient( 1.0, 1.0, y, p ); } -// params => [ ] -function perceptron( y, p, params ) { - hingeGradient( 1.0, 0.0, y, p ); +/** +* Computes the gradient of the perceptron loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function perceptron( y, p, params ) { // eslint-disable-line no-unused-vars + return hingeGradient( 1.0, 0.0, y, p ); } -// params => [ ] -function log( y, p, params ) { - logGradient( 1.0, y, p ); +/** +* Computes the gradient of the log loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function log( y, p, params ) { // eslint-disable-line no-unused-vars + return logGradient( 1.0, y, p ); } -function squaredHinge( y, p, params ) { - squaredHingeGradient( 1.0, y, p ); +/** +* Computes the gradient of the squared hinge loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function squaredHinge( y, p, params ) { // eslint-disable-line no-unused-vars + return squaredHingeGradient( 1.0, y, p ); } -function modifiedHuber( y, p, params ) { - modifiedHuberGradient( 1.0, y, p ); +/** +* Computes the gradient of the modified Huber loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function modifiedHuber( y, p, params ) { // eslint-disable-line no-unused-vars + return modifiedHuberGradient( 1.0, y, p ); } -function squaredError( y, p, params ) { - squaredErrorGradient( 1.0, y, p ); +/** +* Computes the gradient of the squared error loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function squaredError( y, p, params ) { // eslint-disable-line no-unused-vars + return squaredErrorGradient( 1.0, y, p ); } -function huber( y, p, params ) { - huberGradient( 1.0, y, p ); +/** +* Computes the gradient of the Huber loss. +* +* Note: +* +* - Here `params` => `[ ]` (empty) +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ +function huber( y, p, params ) { // eslint-disable-line no-unused-vars + return huberGradient( 1.0, y, p ); } +/** +* Computes the gradient of the epsilon-insensitive loss. +* +* Note: +* +* - Here `params` => `[ epsilon ]` +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ function epsilonInsensitive( y, p, params ) { - epsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); + return epsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); } +/** +* Computes the gradient of the squared epsilon-insensitive loss. +* +* Note: +* +* - Here `params` => `[ epsilon ]` +* +* @private +* @param {number} y - target value +* @param {number} p - predicted value +* @param {Float64Array} params - strided array containing loss function specific parameters. +* @returns {number} loss gradient +*/ function squaredEpsilonInsensitive( y, p, params ) { - squaredEpsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); + return squaredEpsilonInsensitiveGradient( 1.0, params[ 0 ], y, p ); } -// MAIN // +// EXPORTS // +module.exports = LOSS_FUNCTIONS; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/main.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/main.js new file mode 100644 index 000000000000..bff16b5d4900 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsgdTrainer = require( './dsgd_trainer.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dsgdTrainer, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/native.js new file mode 100644 index 000000000000..faa45719b594 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsgdTrainer = require( './dsgd_trainer.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dsgdTrainer, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsgdTrainer; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.js new file mode 100644 index 000000000000..41c3bb7a6985 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.js @@ -0,0 +1,110 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolvePenaltyStr = require( '@stdlib/ml/base/sgd/penalty-resolve-str' ); +var resolveLRStr = require( '@stdlib/ml/base/sgd/learning-rate-resolve-str' ); +var resolveLossFnStr = require( '@stdlib/ml/base/sgd/loss-function-resolve-str' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {Float64Array} x - `M` by `N` input matrix +* @param {integer} strideX1 - stride of the first dimension of `x` +* @param {integer} strideX2 - stride of the second dimension of `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @param {Params} params - parameters object +* @throws {TypeError} first argument must be a valid transpose operation +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} tenth argument must be non-zero +* @throws {RangeError} fourteenth argument must be non-zero +* @returns {Float64Array} `w` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dgemv( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 16.0 ] +*/ +function dgemv( M, N, x, strideX1, strideX2, offsetX, y, strideY, offsetY, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-params, max-len + var lsfn; + var lr; + var p; + + p = resolvePenaltyStr( params.penalty ); + lr = resolveLRStr( params.learningRate ); + lsfn = resolveLossFnStr( params.lossFunction ); + if ( p === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `penalty` member must be a valid penalty. Value: `%s`.', params.penalty ) ); + } + if ( lr === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `learningRate` member must be a valid learning rate. Value: `%s`.', params.learningRate ) ); + } + if ( lsfn === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `lossFunction` member must be a valid loss function. Value: `%s`.', params.lossFunction ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideY ) ); + } + if ( strideW === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideW ) ); + } + if ( strideWS === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + // Check if we can early return... + if ( M === 0 || N === 0 ) { + return y; + } + return base( M, N, x, strideX1, strideX2, offsetX, y, strideY, offsetY, w, strideW, offsetW, workspace, strideWS, offsetWS, params ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dgemv; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.native.js new file mode 100644 index 000000000000..f6ae2721b18e --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/ndarray.native.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolvePenaltyStr = require( '@stdlib/ml/base/sgd/penalty-resolve-str' ); +var resolveLRStr = require( '@stdlib/ml/base/sgd/learning-rate-resolve-str' ); +var resolveLossFnStr = require( '@stdlib/ml/base/sgd/loss-function-resolve-str' ); +var format = require( '@stdlib/string/format' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param {NonNegativeInteger} M - number of samples +* @param {NonNegativeInteger} N - number of features +* @param {Float64Array} x - `M` by `N` input matrix +* @param {integer} strideX1 - stride of the first dimension of `x` +* @param {integer} strideX2 - stride of the second dimension of `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Float64Array} y - target vector +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Float64Array} w - weight vector +* @param {integer} strideW - stride length for `w` +* @param {NonNegativeInteger} offsetW - starting index for `w` +* @param {Float64Array} workspace - workspace array +* @param {integer} strideWS - stride length for `workspace` +* @param {NonNegativeInteger} offsetWS - starting index for `workspace` +* @param {Params} params - parameters object +* @throws {TypeError} first argument must be a valid transpose operation +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} tenth argument must be non-zero +* @throws {RangeError} fourteenth argument must be non-zero +* @returns {Float64Array} `w` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0 ] ); +* +* dgemv( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); +* // y => [ 7.0, 16.0 ] +*/ +function dgemv( M, N, x, strideX1, strideX2, offsetX, y, strideY, offsetY, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-params, max-len + var lsfn; + var lr; + var p; + + p = resolvePenaltyStr( params.penalty ); + lr = resolveLRStr( params.learningRate ); + lsfn = resolveLossFnStr( params.lossFunction ); + if ( p === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `penalty` member must be a valid penalty. Value: `%s`.', params.penalty ) ); + } + if ( lr === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `learningRate` member must be a valid learning rate. Value: `%s`.', params.learningRate ) ); + } + if ( lsfn === null ) { + throw new TypeError( format( 'invalid argument. Thirteenth argument\'s `lossFunction` member must be a valid loss function. Value: `%s`.', params.lossFunction ) ); + } + if ( M < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideY === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideY ) ); + } + if ( strideW === 0 ) { + throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideW ) ); + } + if ( strideWS === 0 ) { + throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) ); + } + // Check if we can early return... + if ( M === 0 || N === 0 ) { + return y; + } + addon.ndarray( M, N, x, strideX1, strideX2, offsetX, y, strideY, offsetY, w, strideW, offsetW, workspace, strideWS, offsetWS, params ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = dgemv; diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js index eb2bc7cd83c1..38356f4b3d6c 100644 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/lib/truncation.js @@ -26,12 +26,24 @@ var min = require( '@stdlib/math/base/special/min' ); // VARIABLES // -var TRUNCATIONS = { - 'elasticnet': l1Truncate, - 'l1': l1Truncate, - 'l2': noTruncation, - 'none': noTruncation -}; +/** +* Truncation functions, indexed by penalty enumeration constant. +* +* @private +* @name TRUNCATIONS +* @constant +* @type {Array} +* +* @example +* var f = TRUNCATIONS[ 2 ]; +* // returns +*/ +var TRUNCATIONS = [ + l1Truncation, // 0: elasticnet + l1Truncation, // 1: l1 + noTruncation, // 2: l2 + noTruncation // 3: none +]; // FUNCTIONS // @@ -46,6 +58,7 @@ var TRUNCATIONS = { * @private * @param {NonNegativeInteger} N - number of features (length of `w`) * @param {number} u - cumulative L1 penalty accumulated so far +* @param {NonNegativeInteger} eta - learning rate. * @param {number} scaleFactor - current scaling factor applied to the stored weights * @param {Float64Array} w - weight vector (updated in-place) * @param {integer} strideW - stride length for `w` @@ -56,7 +69,7 @@ var TRUNCATIONS = { * @param {Float64Array} params - strided array containing regularizer specific parameters. * @returns {void} */ -function noTruncation( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line no-unused-vars, max-len +function noTruncation( N, u, eta, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line no-unused-vars, max-len, max-params return u; } @@ -70,6 +83,7 @@ function noTruncation( N, u, scaleFactor, w, strideW, offsetW, workspace, stride * @private * @param {NonNegativeInteger} N - number of features (length of `w`) * @param {number} u - cumulative L1 penalty accumulated so far +* @param {NonNegativeInteger} eta - learning rate. * @param {number} scaleFactor - current scaling factor applied to the stored weights * @param {Float64Array} w - weight vector (updated in-place) * @param {integer} strideW - stride length for `w` @@ -80,7 +94,7 @@ function noTruncation( N, u, scaleFactor, w, strideW, offsetW, workspace, stride * @param {Float64Array} params - strided array containing regularizer specific parameters. * @returns {void} */ -function l1Truncate( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-len +function l1Truncation( N, u, eta, scaleFactor, w, strideW, offsetW, workspace, strideWS, offsetWS, params ) { // eslint-disable-line max-len, max-params var wsIdx; var idx; var z; @@ -97,7 +111,7 @@ function l1Truncate( N, u, scaleFactor, w, strideW, offsetW, workspace, strideWS } workspace[ wsIdx ] += scaleFactor * ( w[ idx ] - z ); } - return u * params[ 0 ] * params[ 1 ] * params[ 2 ]; + return u * eta * params[ 1 ] * params[ 2 ]; } diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/manifest.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/manifest.json new file mode 100644 index 000000000000..9a3252f0f793 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/manifest.json @@ -0,0 +1,541 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/dgemv_cblas.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-strided-float64array2d" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/dgemv.c", + "./src/dgemv_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/blas/base/dscal", + "@stdlib/blas/ext/base/dfill", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/package.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/package.json new file mode 100644 index 000000000000..afffbd15f7f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/ml/strided/dsgd-trainer", + "version": "0.0.0", + "description": "Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 2", + "dgemv", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c new file mode 100644 index 000000000000..ba7c224c2564 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c @@ -0,0 +1,124 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/argv_strided_float64array2d.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + CBLAS_INT xlen; + CBLAS_INT ylen; + CBLAS_INT sa1; + CBLAS_INT sa2; + + STDLIB_NAPI_ARGV( env, info, argv, argc, 12 ); + + STDLIB_NAPI_ARGV_INT32( env, layout, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, trans, argv, 1 ); + + STDLIB_NAPI_ARGV_INT64( env, M, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); + STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 6 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 9 ); + + if ( trans == CblasNoTrans ) { + xlen = N; + ylen = M; + } else { + xlen = M; + ylen = N; + } + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + } + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, xlen, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, ylen, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, M, N, sa1, sa2, argv, 5 ); + + API_SUFFIX(c_dgemv)( layout, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY ); + + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + CBLAS_INT xlen; + CBLAS_INT ylen; + + STDLIB_NAPI_ARGV( env, info, argv, argc, 15 ); + + STDLIB_NAPI_ARGV_INT32( env, trans, argv, 0 ); + + STDLIB_NAPI_ARGV_INT64( env, M, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 13 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 14 ); + STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, strideA2, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 7 ); + + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 11 ); + + if ( trans == CblasNoTrans ) { + xlen = N; + ylen = M; + } else { + xlen = M; + ylen = N; + } + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, xlen, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, ylen, strideY, argv, 12 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, M, N, strideA1, strideA2, argv, 4 ); + + API_SUFFIX(c_dgemv_ndarray)( trans, M, N, alpha, A, strideA1, strideA2, offsetA, X, strideX, offsetX, beta, Y, strideY, offsetY ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c new file mode 100644 index 000000000000..87894f033e66 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param layout storage layout +* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed +* @param M number of rows in the matrix `A` +* @param N number of columns in the matrix `A` +* @param alpha scalar constant +* @param A input matrix +* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param X first input vector +* @param strideX `X` stride length +* @param beta scalar constant +* @param Y second input vector +* @param strideY `Y` stride length +*/ +void API_SUFFIX(c_dgemv)( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { + CBLAS_INT vala; + CBLAS_INT xlen; + CBLAS_INT ylen; + CBLAS_INT sa1; + CBLAS_INT sa2; + CBLAS_INT ox; + CBLAS_INT oy; + CBLAS_INT v; + + // Perform input argument validation... + if ( layout != CblasRowMajor && layout != CblasColMajor ) { + c_xerbla( 1, "c_dgemv", "Error: invalid argument. First argument must be a valid storage layout. Value: `%d`.", layout ); + return; + } + if ( trans != CblasTrans && trans != CblasConjTrans && trans != CblasNoTrans ) { + c_xerbla( 2, "c_dgemv", "Error: invalid argument. Second argument must be a valid transpose operation. Value: `%d`.", trans ); + return; + } + if ( M < 0 ) { + c_xerbla( 3, "c_dgemv", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", M ); + return; + } + if ( N < 0 ) { + c_xerbla( 4, "c_dgemv", "Error: invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.", N ); + return; + } + if ( strideX == 0 ) { + c_xerbla( 9, "c_dgemv", "Error: invalid argument. Ninth argument must be nonzero. Value: `%d`.", strideX ); + return; + } + if ( strideY == 0 ) { + c_xerbla( 12, "c_dgemv", "Error: invalid argument. Twelfth argument must be nonzero. Value: `%d`.", strideY ); + return; + } + if ( layout == CblasColMajor ) { + v = M; + } else { + v = N; + } + // max(1, v) + if ( v < 1 ) { + vala = 1; + } else { + vala = v; + } + if ( LDA < vala ) { + c_xerbla( 10, "c_dgemv", "Error: invalid argument. Seventh argument must be greater than or equal to max(1,%d). Value: `%d`.", v, LDA ); + return; + } + // Check if we can early return... + if ( M == 0 || N == 0 || ( alpha == 0.0 && beta == 1.0 ) ) { + return; + } + if ( trans == CblasNoTrans ) { + xlen = N; + ylen = M; + } else { + xlen = M; + ylen = N; + } + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + } + ox = stdlib_strided_stride2offset( xlen, strideX ); + oy = stdlib_strided_stride2offset( ylen, strideY ); + API_SUFFIX(c_dgemv_ndarray)( trans, M, N, alpha, A, sa1, sa2, 0, X, strideX, ox, beta, Y, strideY, oy ); + return; +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c new file mode 100644 index 000000000000..1148dd26f9c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/dgemv_cblas.h" +#include "stdlib/blas/base/shared.h" + +/** +* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param layout storage layout +* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed +* @param M number of rows in the matrix `A` +* @param N number of columns in the matrix `A` +* @param alpha scalar constant +* @param A input matrix +* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param x first input vector +* @param strideX `x` stride length +* @param beta scalar constant +* @param y second input vector +* @param strideY `y` stride length +*/ +void API_SUFFIX(c_dgemv)( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { + API_SUFFIX(cblas_dgemv)( layout, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c new file mode 100644 index 000000000000..6e1592a58dc2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/ml/strided/dsgd-trainer.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" +#include "stdlib/blas/base/dscal.h" +#include "stdlib/blas/ext/base/dfill.h" +#include "stdlib/ndarray/base/assert/is_row_major.h" +#include + +/** +* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, using alternative indexing semantics and where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix. +* +* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed +* @param M number of rows in the matrix `A` +* @param N number of columns in the matrix `A` +* @param alpha scalar constant +* @param A input matrix +* @param strideA1 stride of the first dimension of `A` +* @param strideA2 stride of the second dimension of `A` +* @param offsetA starting index for `A` +* @param X first input vector +* @param strideX `X` stride length +* @param offsetX starting index for `X` +* @param beta scalar constant +* @param Y second input vector +* @param strideY `Y` stride length +* @param offsetY starting index for `Y` +*/ +void API_SUFFIX(c_dgemv_ndarray)( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + int64_t sa[ 2 ]; + CBLAS_INT xlen; + CBLAS_INT ylen; + CBLAS_INT da0; + CBLAS_INT da1; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT ia; + CBLAS_INT i0; + CBLAS_INT i1; + double tmp; + bool isrm; + + // Note on variable naming convention: da#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Perform input argument validation... + if ( trans != CblasTrans && trans != CblasConjTrans && trans != CblasNoTrans ) { + c_xerbla( 1, "c_dgemv_ndarray", "Error: invalid argument. First argument must be a valid transpose operation. Value: `%d`.", trans ); + return; + } + if ( M < 0 ) { + c_xerbla( 2, "c_dgemv_ndarray", "Error: invalid argument. Second argument must be a nonnegative integer. Value: `%d`.", M ); + return; + } + if ( N < 0 ) { + c_xerbla( 3, "c_dgemv_ndarray", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", N ); + return; + } + if ( strideX == 0 ) { + c_xerbla( 10, "c_dgemv_ndarray", "Error: invalid argument. Tenth argument must be nonzero. Value: `%d`.", strideX ); + return; + } + if ( strideY == 0 ) { + c_xerbla( 14, "c_dgemv_ndarray", "Error: invalid argument. Fourteenth argument must be nonzero. Value: `%d`.", strideY ); + return; + } + // Check whether we can avoid computation altogether... + if ( M == 0 || N == 0 || ( alpha == 0.0 && beta == 1.0 ) ) { + return; + } + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sa[ 0 ] = strideA1; + sa[ 1 ] = strideA2; + isrm = stdlib_ndarray_is_row_major( 2, sa ); + if ( trans == CblasNoTrans ) { + xlen = N; + ylen = M; + } else { + xlen = M; + ylen = N; + } + // Y = beta * Y + if ( beta == 0.0 ) { + API_SUFFIX(stdlib_strided_dfill_ndarray)( ylen, 0.0, Y, strideY, offsetY ); + } else if ( beta != 1.0 ) { + API_SUFFIX(c_dscal_ndarray)( ylen, beta, Y, strideY, offsetY ); + } + if ( alpha == 0.0 ) { + return; + } + // Form: Y = α*A*X + Y + if ( + ( !isrm && trans == CblasNoTrans ) || + ( isrm && trans != CblasNoTrans ) + ) { + if ( isrm ) { + // For row-major matrices, the last dimension has the fastest changing index... + da0 = strideA2; // offset increment for innermost loop + da1 = strideA1 - ( ylen*strideA2 ); // offset increment for outermost loop + } else { // isColMajor + // For column-major matrices, the first dimension has the fastest changing index... + da0 = strideA1; // offset increment for innermost loop + da1 = strideA2 - ( ylen*strideA1 ); // offset increment for outermost loop + } + ia = offsetA; + ix = offsetX; + for ( i1 = 0; i1 < xlen; i1++ ) { + tmp = alpha * X[ ix ]; + if ( tmp == 0.0 ) { + ia += da0 * ylen; + } else { + iy = offsetY; + for ( i0 = 0; i0 < ylen; i0++ ) { + Y[ iy ] += A[ ia ] * tmp; + iy += strideY; + ia += da0; + } + } + ix += strideX; + ia += da1; + } + return; + } + // Form: Y = α*A^T*X + Y + + // ( !isrm && trans != CblasNoTrans ) || ( isrm && trans == CblasNoTrans ) + if ( isrm ) { + // For row-major matrices, the last dimension has the fastest changing index... + da0 = strideA2; // offset increment for innermost loop + da1 = strideA1 - ( xlen*strideA2 ); // offset increment for outermost loop + } else { // isColMajor + // For column-major matrices, the first dimension has the fastest changing index... + da0 = strideA1; // offset increment for innermost loop + da1 = strideA2 - ( xlen*strideA1 ); // offset increment for outermost loop + } + ia = offsetA; + iy = offsetY; + for ( i1 = 0; i1 < ylen; i1++ ) { + tmp = 0.0; + ix = offsetX; + for ( i0 = 0; i0 < xlen; i0++ ) { + tmp += A[ ia ] * X[ ix ]; + ix += strideX; + ia += da0; + } + Y[ iy ] += alpha * tmp; + iy += strideY; + ia += da1; + } + return; +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json new file mode 100644 index 000000000000..33f237a34ca8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.0, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 0.5, 1.0, 1.5, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json new file mode 100644 index 000000000000..a87cd0111f38 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "strideA1": -2, + "strideA2": -5, + "offsetA": 14, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "M": 3, + "N": 3, + "alpha": 0.5, + "beta": 0.5, + "A": [ 6, 999, 0, 999, 0, 5, 999, 4, 999, 0, 3, 999, 2, 999, 1 ], + "x": [ 3.0, 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "y_out": [ 16.0, 6.0, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json new file mode 100644 index 000000000000..705194b01e71 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0, 13.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json new file mode 100644 index 000000000000..92da961fb13a --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 3.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 2, + "strideA2": 10, + "offsetA": 5, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json new file mode 100644 index 000000000000..6a262d2a7778 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 1.0, 999.0, 3.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 2, + "strideA2": 10, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json new file mode 100644 index 000000000000..c91c334cc3e2 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0, 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 3.0, 999.0, 5.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 2, + "strideA2": -10, + "offsetA": 15, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json new file mode 100644 index 000000000000..fae84fbff430 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 3.0, 999.0, 1.0, 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 4.0, 999.0, 2.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": -2, + "strideA2": 10, + "offsetA": 9, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json new file mode 100644 index 000000000000..e21c2724e2b7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 4.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 3.0, 999.0, 1.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": -2, + "strideA2": -10, + "offsetA": 19, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json new file mode 100644 index 000000000000..86fb6a0f8c12 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 1.0, 2.0, 3.0, 4.0 ], + "y": [ 1.0, 2.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 15.5, 36.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json new file mode 100644 index 000000000000..a0ec9dd61530 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], + "x": [ 0.0, 0.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 0.5, 1.0, 1.5, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json new file mode 100644 index 000000000000..59e66f7499ac --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 1.0, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], + "x": [ 0.0, 0.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 1.0, 2.0, 3.0, 4.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json new file mode 100644 index 000000000000..284eddccf93f --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": -1, + "offsetX": 1, + "strideY": -1, + "offsetY": 3, + "y_out": [ 12.0, 9.5, 7.0, 4.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json new file mode 100644 index 000000000000..e8ff2247130c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": -1, + "offsetX": 1, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0, 13.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json new file mode 100644 index 000000000000..3c275aa0a642 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 3, + "y_out": [ 11.5, 9.0, 6.5, 4.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json new file mode 100644 index 000000000000..08e3b227164d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json @@ -0,0 +1,20 @@ +{ + "order": "column-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 4, + "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 1, + "strideA2": 4, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 2.5, 6.0, 9.5, 13.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json new file mode 100644 index 000000000000..1bced86ae275 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.0, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 0.5, 1.0, 1.5, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json new file mode 100644 index 000000000000..555645d3c7cd --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "strideA1": -6, + "strideA2": -1, + "offsetA": 14, + "strideX": -1, + "offsetX": 2, + "strideY": -1, + "offsetY": 2, + "alpha": 0.5, + "beta": 0.5, + "M": 3, + "N": 3, + "A": [ 6, 5, 3, 999, 999, 999, 0, 4, 2, 999, 999, 999, 0, 0, 1 ], + "x": [ 1.0, 2.0, 3.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "y_out": [ 13.0, 8.0, 3.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json new file mode 100644 index 000000000000..1c345e420443 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0, 13.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json new file mode 100644 index 000000000000..c8c69c1071ba --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 1.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 6.0, 999.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 10, + "strideA2": 2, + "offsetA": 1, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json new file mode 100644 index 000000000000..f3ea02405b4d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 1.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 6.0, 999.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 8, + "strideA2": 2, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json new file mode 100644 index 000000000000..a7b79aa7d772 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 2.0, 999.0, 1.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 4.0, 999.0, 3.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 5.0, 999.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": 10, + "strideA2": -2, + "offsetA": 3, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json new file mode 100644 index 000000000000..14a0b13c491d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 5.0, 999.0, 6.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 2.0, 999.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": -10, + "strideA2": 2, + "offsetA": 21, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json new file mode 100644 index 000000000000..78a6ff3cc584 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json @@ -0,0 +1,18 @@ +{ + "trans": "no-transpose", + "M": 3, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "A": [ 999.0, 6.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 4.0, 999.0, 3.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 1.0, 999.0 ], + "x": [ 1.0, 2.0 ], + "y": [ 1.0, 2.0, 3.0 ], + "strideA1": -10, + "strideA2": -2, + "offsetA": 23, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json new file mode 100644 index 000000000000..ca04d44b2a20 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 1.0, 2.0, 3.0, 4.0 ], + "y": [ 1.0, 2.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 25.5, 31.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json new file mode 100644 index 000000000000..7a5af3e7dc61 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 0.0, 0.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 0.5, 1.0, 1.5, 2.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json new file mode 100644 index 000000000000..dd08640b3da7 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 1.0, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 0.0, 0.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 1.0, 2.0, 3.0, 4.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json new file mode 100644 index 000000000000..71fee7b136b8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": -1, + "offsetX": 1, + "strideY": -1, + "offsetY": 3, + "y_out": [ 12.0, 9.5, 7.0, 4.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json new file mode 100644 index 000000000000..3075694a1111 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": -1, + "offsetX": 1, + "strideY": 1, + "offsetY": 0, + "y_out": [ 3.0, 6.5, 10.0, 13.5 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json new file mode 100644 index 000000000000..d3ab52c45feb --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": -1, + "offsetY": 3, + "y_out": [ 11.5, 9.0, 6.5, 4.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json new file mode 100644 index 000000000000..d5fae06293fc --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json @@ -0,0 +1,20 @@ +{ + "order": "row-major", + "trans": "no-transpose", + "M": 4, + "N": 2, + "alpha": 0.5, + "beta": 0.5, + "lda": 2, + "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], + "x": [ 2.0, 1.0 ], + "y": [ 1.0, 2.0, 3.0, 4.0 ], + "strideA1": 2, + "strideA2": 1, + "offsetA": 0, + "strideX": 1, + "offsetX": 0, + "strideY": 1, + "offsetY": 0, + "y_out": [ 2.5, 6.0, 9.5, 13.0 ] +} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js new file mode 100644 index 000000000000..6e6257e70d91 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js @@ -0,0 +1,791 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dgemv = require( './../lib/dgemv.js' ); + + +// FIXTURES // + +var cnt = require( './fixtures/column_major_nt.json' ); +var ct = require( './fixtures/column_major_t.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cx = require( './fixtures/column_major_x_zeros.json' ); +var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); +var ca = require( './fixtures/column_major_alpha_zero.json' ); + +var rnt = require( './fixtures/row_major_nt.json' ); +var rt = require( './fixtures/row_major_t.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rx = require( './fixtures/row_major_x_zeros.json' ); +var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); +var ra = require( './fixtures/row_major_alpha_zero.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', function test( t ) { + t.strictEqual( dgemv.length, 12, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( value, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 1, + 0, + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), value, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid ninth argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), value, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid twelfth argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), value ); + }; + } +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (row-major)', function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (column-major)', function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ra; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ca; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js new file mode 100644 index 000000000000..90b9801682d1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js @@ -0,0 +1,799 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var cnt = require( './fixtures/column_major_nt.json' ); +var ct = require( './fixtures/column_major_t.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cx = require( './fixtures/column_major_x_zeros.json' ); +var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); +var ca = require( './fixtures/column_major_alpha_zero.json' ); +var rnt = require( './fixtures/row_major_nt.json' ); +var rt = require( './fixtures/row_major_t.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rx = require( './fixtures/row_major_x_zeros.json' ); +var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); +var ra = require( './fixtures/row_major_alpha_zero.json' ); + + +// VARIABLES // + +var dgemv = tryRequire( resolve( __dirname, './../lib/dgemv.native.js' ) ); +var opts = { + 'skip': ( dgemv instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 12', opts, function test( t ) { + t.strictEqual( dgemv.length, 12, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( value, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid seventh argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 1, + 0, + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), value, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid ninth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), value, data.beta, new Float64Array( data.y ), data.strideY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid twelfth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), value ); + }; + } +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (row-major)', opts, function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (column-major)', opts, function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ra; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ca; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js new file mode 100644 index 000000000000..58253939a980 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dgemv = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dgemv.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dgemv = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dgemv, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dgemv; + var main; + + main = require( './../lib/dgemv.js' ); + + dgemv = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dgemv, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js new file mode 100644 index 000000000000..0687216267e0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js @@ -0,0 +1,1025 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dgemv = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var cap = require( './fixtures/column_major_complex_access_pattern.json' ); +var cnt = require( './fixtures/column_major_nt.json' ); +var ct = require( './fixtures/column_major_t.json' ); +var coa = require( './fixtures/column_major_oa.json' ); +var csa1sa2 = require( './fixtures/column_major_sa1_sa2.json' ); +var csa1nsa2 = require( './fixtures/column_major_sa1n_sa2.json' ); +var csa1sa2n = require( './fixtures/column_major_sa1_sa2n.json' ); +var csa1nsa2n = require( './fixtures/column_major_sa1n_sa2n.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cx = require( './fixtures/column_major_x_zeros.json' ); +var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); +var ca = require( './fixtures/column_major_alpha_zero.json' ); +var rap = require( './fixtures/row_major_complex_access_pattern.json' ); +var rnt = require( './fixtures/row_major_nt.json' ); +var rt = require( './fixtures/row_major_t.json' ); +var roa = require( './fixtures/row_major_oa.json' ); +var rsa1sa2 = require( './fixtures/row_major_sa1_sa2.json' ); +var rsa1nsa2 = require( './fixtures/row_major_sa1n_sa2.json' ); +var rsa1sa2n = require( './fixtures/row_major_sa1_sa2n.json' ); +var rsa1nsa2n = require( './fixtures/row_major_sa1n_sa2n.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rx = require( './fixtures/row_major_x_zeros.json' ); +var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); +var ra = require( './fixtures/row_major_alpha_zero.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', function test( t ) { + t.strictEqual( dgemv.length, 15, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), value, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourteenth argument', function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), value, data.offsetY ); + }; + } +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (row-major)', function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (column-major)', function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ra; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ca; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `A` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1sa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `A` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1sa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the first dimension of `A` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1nsa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the first dimension of `A` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1nsa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the second dimension of `A` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1sa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the second dimension of `A` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1sa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides for `A` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1nsa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides for `A` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1nsa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset parameter for `A` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = roa; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset parameter for `A` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = coa; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `x` and `y` (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `x` and `y` (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rap; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cap; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js new file mode 100644 index 000000000000..0c195ceeda36 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js @@ -0,0 +1,1035 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// FIXTURES // + +var cap = require( './fixtures/column_major_complex_access_pattern.json' ); +var cnt = require( './fixtures/column_major_nt.json' ); +var ct = require( './fixtures/column_major_t.json' ); +var coa = require( './fixtures/column_major_oa.json' ); +var csa1sa2 = require( './fixtures/column_major_sa1_sa2.json' ); +var csa1nsa2 = require( './fixtures/column_major_sa1n_sa2.json' ); +var csa1sa2n = require( './fixtures/column_major_sa1_sa2n.json' ); +var csa1nsa2n = require( './fixtures/column_major_sa1n_sa2n.json' ); +var cxnyn = require( './fixtures/column_major_xnyn.json' ); +var cxpyn = require( './fixtures/column_major_xpyn.json' ); +var cxnyp = require( './fixtures/column_major_xnyp.json' ); +var cxpyp = require( './fixtures/column_major_xpyp.json' ); +var cx = require( './fixtures/column_major_x_zeros.json' ); +var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); +var ca = require( './fixtures/column_major_alpha_zero.json' ); + +var rap = require( './fixtures/row_major_complex_access_pattern.json' ); +var rnt = require( './fixtures/row_major_nt.json' ); +var rt = require( './fixtures/row_major_t.json' ); +var roa = require( './fixtures/row_major_oa.json' ); +var rsa1sa2 = require( './fixtures/row_major_sa1_sa2.json' ); +var rsa1nsa2 = require( './fixtures/row_major_sa1n_sa2.json' ); +var rsa1sa2n = require( './fixtures/row_major_sa1_sa2n.json' ); +var rsa1nsa2n = require( './fixtures/row_major_sa1n_sa2n.json' ); +var rxnyn = require( './fixtures/row_major_xnyn.json' ); +var rxpyn = require( './fixtures/row_major_xpyn.json' ); +var rxnyp = require( './fixtures/row_major_xnyp.json' ); +var rxpyp = require( './fixtures/row_major_xpyp.json' ); +var rx = require( './fixtures/row_major_x_zeros.json' ); +var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); +var ra = require( './fixtures/row_major_alpha_zero.json' ); + + +// VARIABLES // + +var dgemv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dgemv instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 15', opts, function test( t ) { + t.strictEqual( dgemv.length, 15, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid tenth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), value, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fourteenth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = rnt; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), value, data.offsetY ); + }; + } +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cnt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (row-major)', opts, function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input vector (column-major)', opts, function test( t ) { + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rt; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ct; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y ); + + out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxb; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ra; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = ca; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cx; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `A` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1sa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the strides of the first and second dimensions of `A` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1sa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the first dimension of `A` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1nsa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the first dimension of `A` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1nsa2; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the second dimension of `A` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1sa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride for the second dimension of `A` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1sa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides for `A` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rsa1nsa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides for `A` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = csa1nsa2n; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset parameter for `A` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = roa; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset parameter for `A` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = coa; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying `x` and `y` strides (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `x` stride (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyp; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative `y` stride (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxpyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `x` and `y` (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying negative strides for `x` and `y` (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cxnyn; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = rap; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { + var expected; + var data; + var out; + var a; + var x; + var y; + + data = cap; + + a = new Float64Array( data.A ); + x = new Float64Array( data.x ); + y = new Float64Array( data.y ); + + expected = new Float64Array( data.y_out ); + + out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); + t.strictEqual( out, y, 'returns expected value' ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); From 080263279785d8865d228dd812e507a9799e45ff Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Thu, 6 Aug 2026 23:34:22 +0530 Subject: [PATCH 4/4] remove: delete unfinished files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ml/strided/dsgd-trainer/README.md | 360 ------ .../ml/strided/dsgd-trainer/binding.gyp | 265 ----- .../ml/strided/dsgd-trainer/docs/repl.txt | 160 --- .../strided/dsgd-trainer/docs/types/test.ts | 517 -------- .../strided/dsgd-trainer/examples/c/Makefile | 146 --- .../strided/dsgd-trainer/examples/c/example.c | 54 - .../ml/strided/dsgd-trainer/examples/index.js | 61 - .../ml/strided/dsgd-trainer/include.gypi | 70 -- .../ml/strided/dsgd-trainer/manifest.json | 541 --------- .../ml/strided/dsgd-trainer/package.json | 72 -- .../ml/strided/dsgd-trainer/src/Makefile | 70 -- .../ml/strided/dsgd-trainer/src/addon.c | 124 -- .../ml/strided/dsgd-trainer/src/dgemv.c | 112 -- .../ml/strided/dsgd-trainer/src/dgemv_cblas.c | 41 - .../strided/dsgd-trainer/src/dgemv_ndarray.c | 167 --- .../fixtures/column_major_alpha_zero.json | 20 - .../column_major_complex_access_pattern.json | 18 - .../test/fixtures/column_major_nt.json | 20 - .../test/fixtures/column_major_oa.json | 18 - .../test/fixtures/column_major_sa1_sa2.json | 18 - .../test/fixtures/column_major_sa1_sa2n.json | 18 - .../test/fixtures/column_major_sa1n_sa2.json | 18 - .../test/fixtures/column_major_sa1n_sa2n.json | 18 - .../test/fixtures/column_major_t.json | 20 - .../test/fixtures/column_major_x_zeros.json | 20 - .../column_major_x_zeros_beta_one.json | 20 - .../test/fixtures/column_major_xnyn.json | 20 - .../test/fixtures/column_major_xnyp.json | 20 - .../test/fixtures/column_major_xpyn.json | 20 - .../test/fixtures/column_major_xpyp.json | 20 - .../test/fixtures/row_major_alpha_zero.json | 20 - .../row_major_complex_access_pattern.json | 18 - .../test/fixtures/row_major_nt.json | 20 - .../test/fixtures/row_major_oa.json | 18 - .../test/fixtures/row_major_sa1_sa2.json | 18 - .../test/fixtures/row_major_sa1_sa2n.json | 18 - .../test/fixtures/row_major_sa1n_sa2.json | 18 - .../test/fixtures/row_major_sa1n_sa2n.json | 18 - .../test/fixtures/row_major_t.json | 20 - .../test/fixtures/row_major_x_zeros.json | 20 - .../fixtures/row_major_x_zeros_beta_one.json | 20 - .../test/fixtures/row_major_xnyn.json | 20 - .../test/fixtures/row_major_xnyp.json | 20 - .../test/fixtures/row_major_xpyn.json | 20 - .../test/fixtures/row_major_xpyp.json | 20 - .../strided/dsgd-trainer/test/test.dgemv.js | 791 ------------- .../dsgd-trainer/test/test.dgemv.native.js | 799 ------------- .../ml/strided/dsgd-trainer/test/test.js | 82 -- .../strided/dsgd-trainer/test/test.ndarray.js | 1025 ---------------- .../dsgd-trainer/test/test.ndarray.native.js | 1035 ----------------- 50 files changed, 7068 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/manifest.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/package.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md deleted file mode 100644 index d3d1f9c2e274..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/README.md +++ /dev/null @@ -1,360 +0,0 @@ - - -# dgemv - -> Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`. - -
- -## Usage - -```javascript -var dgemv = require( '@stdlib/ml/strided/dsgd-trainer' ); -``` - -#### dgemv( order, trans, M, N, α, A, LDA, x, sx, β, y, sy ) - -Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); -var y = new Float64Array( [ 1.0, 1.0 ] ); - -dgemv( 'row-major', 'no-transpose', 2, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); -// y => [ 7.0, 16.0 ] -``` - -The function has the following parameters: - -- **order**: storage layout. -- **trans**: specifies whether `A` should be transposed, conjugate-transposed, or not transposed. -- **M**: number of rows in the matrix `A`. -- **N**: number of columns in the matrix `A`. -- **α**: scalar constant. -- **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. -- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). -- **x**: input [`Float64Array`][mdn-float64array]. -- **sx**: stride length for `x`. -- **β**: scalar constant. -- **y**: output [`Float64Array`][mdn-float64array]. -- **sy**: stride length for `y`. - -The stride parameters determine how operations are performed. For example, to iterate over every other element in `x` and `y`, - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); -var x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] ); -var y = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] ); - -dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x, 2, 1.0, y, 2 ); -// y => [ 4.0, 0.0, 8.0, 0.0 ] -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -// Initial arrays... -var x0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); -var y0 = new Float64Array( [ 0.0, 1.0, 1.0 ] ); -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - -// Create offset views... -var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -dgemv( 'row-major', 'no-transpose', 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 ); -// y0 => [ 0.0, 8.0, 4.0 ] -``` - - - -#### dgemv.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy ) - -Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var x = new Float64Array( [ 1.0, 1.0, 1.0 ] ); -var y = new Float64Array( [ 1.0, 1.0 ] ); - -dgemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); -// y => [ 7.0, 16.0 ] -``` - -The function has the following additional parameters: - -- **sa1**: stride of the first dimension of `A`. -- **sa2**: stride of the second dimension of `A`. -- **oa**: starting index for `A`. -- **ox**: starting index for `x`. -- **oy**: starting index for `y`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); -var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0 ] ); - -dgemv.ndarray( 'no-transpose', 2, 3, 1.0, A, 3, 1, 0, x, 1, 1, 1.0, y, -2, 2 ); -// y => [ 39, 8, 23, 10 ] -``` - -
- - - -
- -## Notes - -- `dgemv()` corresponds to the [BLAS][blas] level 2 function [`dgemv`][blas-dgemv]. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var dgemv = require( '@stdlib/ml/strided/dsgd-trainer' ); - -var opts = { - 'dtype': 'float64' -}; - -var M = 3; -var N = 3; - -var A = discreteUniform( M*N, 0, 255, opts ); -var x = discreteUniform( N, 0, 255, opts ); -var y = discreteUniform( M, 0, 255, opts ); - -dgemv( 'row-major', 'no-transpose', M, N, 1.0, A, N, x, -1, 1.0, y, -1 ); -console.log( y ); - -``` - -
- - - - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ml/strided/dsgd-trainer.h" -``` - -#### c_dgemv( layout, trans, M, N, alpha, \*A, LDA, \*X, strideX, beta, \*Y, strideY ) - -Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. - -```c -#include "stdlib/blas/base/shared.h" - -const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 }; -const double x[] = { 1.0, 2.0, 3.0 }; -double y[] = { 1.0, 2.0, 3.0 }; - -c_dgemv( CblasColMajor, CblasNoTrans, 3, 3, 1.0, A, 3, x, 1, 1.0, y, 1 ); -``` - -The function accepts the following arguments: - -- **layout**: `[in] CBLAS_LAYOUT` storage layout. -- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed. -- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`. -- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`. -- **alpha**: `[in] double` scalar constant. -- **A**: `[in] double*` input matrix. -- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). -- **X**: `[in] double*` first input vector. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **beta**: `[in] double` scalar constant. -- **Y**: `[inout] double*` second input vector. -- **strideY**: `[in] CBLAS_INT` stride length for `Y`. - -```c -void c_dgemv( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) -``` - -#### c_dgemv_ndarray( trans, M, N, alpha, \*A, sa1, sa2, oa, \*X, sx, ox, beta, \*Y, sy, oy ) - -Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. - -```c -#include "stdlib/blas/base/shared.h" - -const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 }; -const double x[] = { 1.0, 2.0, 3.0 }; -double y[] = { 1.0, 2.0, 3.0 }; - -c_dgemv_ndarray( CblasNoTrans, 3, 3, 1.0, A, 1, 3, 0, x, 1, 0, 1.0, y, 1, 0 ); -``` - -The function accepts the following arguments: - -- **trans**: `[in] CBLAS_TRANSPOSE` specifies whether `A` should be transposed, conjugate-transposed, or not transposed. -- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`. -- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`. -- **alpha**: `[in] double` scalar. -- **A**: `[in] double*` input matrix. -- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`. -- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`. -- **oa**: `[in] CBLAS_INT` starting index for `A`. -- **X**: `[in] double*` first input vector. -- **sx**: `[in] CBLAS_INT` stride length for `X`. -- **ox**: `[in] CBLAS_INT` starting index for `X`. -- **beta**: `[in] double` scalar. -- **Y**: `[inout] double*` second input vector. -- **sy**: `[in] CBLAS_INT` stride length for `Y`. -- **oy**: `[in] CBLAS_INT` starting index for `Y`. - -```c -void c_dgemv_ndarray( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/shared.h" -#include - -int main( void ) { - // Define a 3x3 matrix stored in row-major order: - const double A[ 3*3 ] = { - 1.0, 2.0, 3.0, - 4.0, 5.0, 6.0, - 7.0, 8.0, 9.0 - }; - - // Define `x` and `y` vectors: - const double x[ 3 ] = { 1.0, 2.0, 3.0 }; - double y[ 3 ] = { 1.0, 2.0, 3.0 }; - - // Specify the number of elements along each dimension of `A`: - const int M = 3; - const int N = 3; - - // Perform the matrix-vector operation `y = α*A*x + β*y`: - c_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0, A, M, x, 1, 1.0, y, 1 ); - - // Print the result: - for ( int i = 0; i < N; i++ ) { - printf( "y[ %i ] = %lf\n", i, y[ i ] ); - } - - // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: - c_dgemv_ndarray( CblasNoTrans, M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); - - // Print the result: - for ( int i = 0; i < N; i++ ) { - printf( "y[ %i ] = %lf\n", i, y[ i ] ); - } -} -``` - -
- - - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp deleted file mode 100644 index 08de71a2020e..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/binding.gyp +++ /dev/null @@ -1,265 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# A `.gyp` file for building a Node.js native add-on. -# -# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md -# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md -{ - # List of files to include in this file: - 'includes': [ - './include.gypi', - ], - - # Define variables to be used throughout the configuration for all targets: - 'variables': { - # Target name should match the add-on export name: - 'addon_target_name%': 'addon', - - # Fortran compiler (to override -Dfortran_compiler=): - 'fortran_compiler%': 'gfortran', - - # Fortran compiler flags: - 'fflags': [ - # Specify the Fortran standard to which a program is expected to conform: - '-std=f95', - - # Indicate that the layout is free-form source code: - '-ffree-form', - - # Aggressive optimization: - '-O3', - - # Enable commonly used warning options: - '-Wall', - - # Warn if source code contains problematic language features: - '-Wextra', - - # Warn if a procedure is called without an explicit interface: - '-Wimplicit-interface', - - # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): - '-fno-underscoring', - - # Warn if source code contains Fortran 95 extensions and C-language constructs: - '-pedantic', - - # Compile but do not link (output is an object file): - '-c', - ], - - # Set variables based on the host OS: - 'conditions': [ - [ - 'OS=="win"', - { - # Define the object file suffix: - 'obj': 'obj', - }, - { - # Define the object file suffix: - 'obj': 'o', - } - ], # end condition (OS=="win") - ], # end conditions - }, # end variables - - # Define compile targets: - 'targets': [ - - # Target to generate an add-on: - { - # The target name should match the add-on export name: - 'target_name': '<(addon_target_name)', - - # Define dependencies: - 'dependencies': [], - - # Define directories which contain relevant include headers: - 'include_dirs': [ - # Local include directory: - '<@(include_dirs)', - ], - - # List of source files: - 'sources': [ - '<@(src_files)', - ], - - # Settings which should be applied when a target's object files are used as linker input: - 'link_settings': { - # Define libraries: - 'libraries': [ - '<@(libraries)', - ], - - # Define library directories: - 'library_dirs': [ - '<@(library_dirs)', - ], - }, - - # C/C++ compiler flags: - 'cflags': [ - # Enable commonly used warning options: - '-Wall', - - # Aggressive optimization: - '-O3', - ], - - # C specific compiler flags: - 'cflags_c': [ - # Specify the C standard to which a program is expected to conform: - '-std=c99', - ], - - # C++ specific compiler flags: - 'cflags_cpp': [ - # Specify the C++ standard to which a program is expected to conform: - '-std=c++11', - ], - - # Linker flags: - 'ldflags': [], - - # Apply conditions based on the host OS: - 'conditions': [ - [ - 'OS=="mac"', - { - # Linker flags: - 'ldflags': [ - '-undefined dynamic_lookup', - '-Wl,-no-pie', - '-Wl,-search_paths_first', - ], - }, - ], # end condition (OS=="mac") - [ - 'OS!="win"', - { - # C/C++ flags: - 'cflags': [ - # Generate platform-independent code: - '-fPIC', - ], - }, - ], # end condition (OS!="win") - ], # end conditions - - # Define custom build actions for particular inputs: - 'rules': [ - { - # Define a rule for processing Fortran files: - 'extension': 'f', - - # Define the pathnames to be used as inputs when performing processing: - 'inputs': [ - # Full path of the current input: - '<(RULE_INPUT_PATH)' - ], - - # Define the outputs produced during processing: - 'outputs': [ - # Store an output object file in a directory for placing intermediate results (only accessible within a single target): - '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' - ], - - # Define the rule for compiling Fortran based on the host OS: - 'conditions': [ - [ - 'OS=="win"', - - # Rule to compile Fortran on Windows: - { - 'rule_name': 'compile_fortran_windows', - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', - - 'process_outputs_as_sources': 0, - - # Define the command-line invocation: - 'action': [ - '<(fortran_compiler)', - '<@(fflags)', - '<@(_inputs)', - '-o', - '<@(_outputs)', - ], - }, - - # Rule to compile Fortran on non-Windows: - { - 'rule_name': 'compile_fortran_linux', - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', - - 'process_outputs_as_sources': 1, - - # Define the command-line invocation: - 'action': [ - '<(fortran_compiler)', - '<@(fflags)', - '-fPIC', # generate platform-independent code - '<@(_inputs)', - '-o', - '<@(_outputs)', - ], - } - ], # end condition (OS=="win") - ], # end conditions - }, # end rule (extension=="f") - ], # end rules - }, # end target <(addon_target_name) - - # Target to copy a generated add-on to a standard location: - { - 'target_name': 'copy_addon', - - # Declare that the output of this target is not linked: - 'type': 'none', - - # Define dependencies: - 'dependencies': [ - # Require that the add-on be generated before building this target: - '<(addon_target_name)', - ], - - # Define a list of actions: - 'actions': [ - { - 'action_name': 'copy_addon', - 'message': 'Copying addon...', - - # Explicitly list the inputs in the command-line invocation below: - 'inputs': [], - - # Declare the expected outputs: - 'outputs': [ - '<(addon_output_dir)/<(addon_target_name).node', - ], - - # Define the command-line invocation: - 'action': [ - 'cp', - '<(PRODUCT_DIR)/<(addon_target_name).node', - '<(addon_output_dir)/<(addon_target_name).node', - ], - }, - ], # end actions - }, # end target copy_addon - ], # end targets -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt deleted file mode 100644 index 2cab17fe04cd..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/repl.txt +++ /dev/null @@ -1,160 +0,0 @@ - -{{alias}}( order, trans, M, N, α, A, lda, x, sx, β, y, sy ) - Performs one of the matrix-vector operations `y = α*A*x + β*y` or - `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are - vectors, and `A` is an `M` by `N` matrix. - - Indexing is relative to the first index. To introduce an offset, use typed - array views. - - If `M` or `N` is equal to `0`, the function returns `y` unchanged. - - If `α` equals `0` and `β` equals `1`, the function returns `y` unchanged. - - Parameters - ---------- - order: string - Row-major (C-style) or column-major (Fortran-style) order. - - trans: string - Specifies whether `A` should be transposed, conjugate-transposed, or not - transposed. - - M: integer - Number of rows in `A`. - - N: integer - Number of columns in `A`. - - α: number - Scalar constant. - - A: Float64Array - Input matrix. - - lda: integer - Stride of the first dimension of `A` (a.k.a., leading dimension of the - matrix `A`). - - x: Float64Array - First input vector. - - sx: integer - Index increment for `x`. - - β: number - Scalar constant. - - y: Float64Array - Second input vector. - - sy: integer - Index increment for `y`. - - Returns - ------- - y: Float64Array - Second input vector. - - Examples - -------- - // Standard usage: - > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var ord = 'row-major'; - > var trans = 'no-transpose'; - > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x, 1, 1.0, y, 1 ) - [ 4.0, 8.0 ] - - // Advanced indexing: - > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x, -1, 1.0, y, -1 ) - [ 8.0, 4.0 ] - - // Using typed array views: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] ); - > var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] ); - > A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( ord, trans, 2, 2, 1.0, A, 2, x1, -1, 1.0, y1, -1 ); - > y0 - [ 0.0, 8.0, 4.0 ] - - -{{alias}}.ndarray( trans, M, N, α, A, sa1, sa2, oa, x, sx, ox, β, y, sy, oy ) - Performs one of the matrix-vector operations `y = α*A*x + β*y` or - `y = α*A^T*x + β*y`, using alternative indexing semantics and where `α` and - `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. - - While typed array views mandate a view offset based on the underlying - buffer, the offset parameters support indexing semantics based on starting - indices. - - Parameters - ---------- - trans: string - Specifies whether `A` should be transposed, conjugate-transposed, or not - transposed. - - M: integer - Number of rows in `A`. - - N: integer - Number of columns in `A`. - - α: number - Scalar constant. - - A: Float64Array - Input matrix. - - sa1: integer - Stride of the first dimension of `A`. - - sa2: integer - Stride of the second dimension of `A`. - - oa: integer - Starting index for `A`. - - x: Float64Array - First input vector. - - sx: integer - Index increment for `x`. - - ox: integer - Starting index for `x`. - - β: number - Scalar constant. - - y: Float64Array - Second input vector. - - sy: integer - Index increment for `y`. - - oy: integer - Starting index for `y`. - - Returns - ------- - y: Float64Array - Second input vector. - - Examples - -------- - > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > var y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] ); - > var A = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var trans = 'no-transpose'; - > {{alias}}.ndarray( trans, 2, 2, 1, A, 2, 1, 0, x, 1, 0, 1, y, 1, 0 ) - [ 4.0, 8.0 ] - - See Also - -------- diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts deleted file mode 100644 index dd44acf1293f..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/docs/types/test.ts +++ /dev/null @@ -1,517 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dgemv = require( './index' ); - - -// TESTS // - -// The function returns a Float64Array... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectType Float64Array -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 10, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( true, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( false, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( null, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( undefined, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( [], 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( {}, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( ( x: number ): number => x, 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a string... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 10, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', true, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', false, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', null, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', undefined, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', [ '1' ], 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', {}, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', ( x: number ): number => x, 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', '10', 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', true, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', false, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', null, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', undefined, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', [], 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', {}, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', ( x: number ): number => x, 10, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, '10', 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, true, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, false, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, null, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, undefined, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, [], 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, {}, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, ( x: number ): number => x, 1.0, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, '10', A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, true, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, false, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, null, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, undefined, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, [], A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, {}, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, ( x: number ): number => x, A, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, 10, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, '10', 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, true, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, false, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, null, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, undefined, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, [ '1' ], 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, {}, 10, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, ( x: number ): number => x, 10, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a seventh argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, '10', x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, true, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, false, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, null, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, undefined, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, [], x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, {}, x, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, ( x: number ): number => x, x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided an eighth argument which is not a Float64Array... -{ - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, 10, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, '10', 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, true, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, false, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, null, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, undefined, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, [ '1' ], 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, {}, 1, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, ( x: number ): number => x, 1, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a ninth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, '10', 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, true, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, false, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, null, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, undefined, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, [], 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, {}, 1.0, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, ( x: number ): number => x, 1.0, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a tenth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, '10', y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, true, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, false, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, null, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, undefined, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, [], y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, {}, y, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, ( x: number ): number => x, y, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided an eleventh argument which is not a Float64Array... -{ - const x = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, 10, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, '10', 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, true, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, false, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, null, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, undefined, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, [ '1' ], 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, {}, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a twelfth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, '10' ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, true ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, false ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, null ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, undefined ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, [] ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, {} ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv(); // $ExpectError - dgemv( 'row-major' ); // $ExpectError - dgemv( 'row-major', 'no-transpose' ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0 ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y ); // $ExpectError - dgemv( 'row-major', 'no-transpose', 10, 10, 1.0, A, 10, x, 1, 1.0, y, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a Float64Array... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectType Float64Array -} - -// The compiler throws an error if the function is provided a first argument which is not a string... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 10, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( true, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( false, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( null, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( undefined, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( [ '1' ], 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( {}, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( ( x: number ): number => x, 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', '10', 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', true, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', false, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', null, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', undefined, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', [], 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', {}, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', ( x: number ): number => x, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, '10', 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, true, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, false, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, null, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, undefined, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, [], 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, {}, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, ( x: number ): number => x, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, '10', A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, true, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, false, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, null, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, undefined, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, [], A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, {}, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, ( x: number ): number => x, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, 10, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, '10', 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, true, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, false, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, null, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, undefined, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, [ '1' ], 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, {}, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, ( x: number ): number => x, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, '10', 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, true, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, false, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, null, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, undefined, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, [], 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, {}, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, ( x: number ): number => x, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a seventh argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, '10', 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, true, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, false, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, null, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, undefined, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, [], 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, {}, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, ( x: number ): number => x, 0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided an eighth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, '10', x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, true, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, false, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, null, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, undefined, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, [], x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, {}, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, ( x: number ): number => x, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a ninth argument which is not a Float64Array... -{ - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, 10, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, '10', 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, true, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, false, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, null, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, undefined, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, [ '1' ], 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, {}, 1, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, ( x: number ): number => x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a tenth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, '10', 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, true, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, false, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, null, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, undefined, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, [], 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, {}, 0, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, ( x: number ): number => x, 0, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided an eleventh argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, '10', 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, true, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, false, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, null, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, undefined, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, [], 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, {}, 1.0, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, ( x: number ): number => x, 1.0, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a twelfth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, '10', y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, true, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, false, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, null, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, undefined, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, [], y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, {}, y, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, ( x: number ): number => x, y, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a thirteenth argument which is not a Float64Array... -{ - const x = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, 10, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, '10', 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, true, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, false, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, null, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, undefined, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, [ '1' ], 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, {}, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourteenth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, '10', 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, true, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, false, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, null, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, undefined, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, [], 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, {}, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifteenth argument which is not a number... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, '10' ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, true ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, false ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, null ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, undefined ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, [] ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, {} ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - const y = new Float64Array( 10 ); - const A = new Float64Array( 20 ); - - dgemv.ndarray(); // $ExpectError - dgemv.ndarray( 'no-transpose' ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1 ); // $ExpectError - dgemv.ndarray( 'no-transpose', 10, 10, 1.0, A, 10, 1, 0, x, 1, 0, 1.0, y, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile deleted file mode 100644 index 25ced822f96a..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c deleted file mode 100644 index 9814336e9541..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/c/example.c +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/shared.h" -#include - -int main( void ) { - // Define a 3x3 matrix stored in row-major order: - const double A[ 3*3 ] = { - 1.0, 2.0, 3.0, - 4.0, 5.0, 6.0, - 7.0, 8.0, 9.0 - }; - - // Define `x` and `y` vectors: - const double x[ 3 ] = { 1.0, 2.0, 3.0 }; - double y[ 3 ] = { 1.0, 2.0, 3.0 }; - - // Specify the number of elements along each dimension of `A`: - const int M = 3; - const int N = 3; - - // Perform the matrix-vector operation `y = α*A*x + β*y`: - c_dgemv( CblasRowMajor, CblasNoTrans, M, N, 1.0, A, M, x, 1, 1.0, y, 1 ); - - // Print the result: - for ( int i = 0; i < N; i++ ) { - printf( "y[ %i ] = %lf\n", i, y[ i ] ); - } - - // Perform the matrix-vector operation `y = α*A*x + β*y` using alternative indexing semantics: - c_dgemv_ndarray( CblasNoTrans, M, N, 1.0, A, N, 1, 0, x, 1, 0, 1.0, y, 1, 0 ); - - // Print the result: - for ( int i = 0; i < N; i++ ) { - printf( "y[ %i ] = %lf\n", i, y[ i ] ); - } -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js deleted file mode 100644 index 94fd74d8e05a..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/examples/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random/array/uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); -var dsgdTrainerSqEpsIns = require( './../lib/base.js' ); - -var M = 100000; // number of samples -var N = 20; // number of features - -var opts = { - 'dtype': 'float64' -}; - -// Generate a random `MxN` design matrix and a random target vector: -var x = uniform( M*N, -10.0, 10.0, opts ); -var y = uniform( M, -50.0, 50.0, opts ); - -// Allocate the weight vector and the per-feature L1 shrinkage workspace: -var w = new Float64Array( N ); -var workspace = new Float64Array( N ); - -// Configure the training hyperparameters: -var penalty = 'elasticnet'; -var fitIntercept = true; -var l1Ratio = 0.15; -var maxIter = 20; -var learningRate = 'invscaling'; -var eta0 = 0.01; -var powerT = 0.25; -var epsilon = 0.0; -var lambda = 1.0e-5; -var intercept = 0.0; - -// Train a linear model via plain SGD with an elastic-net penalty: -var out = dsgdTrainerSqEpsIns( penalty, learningRate, fitIntercept, M, N, l1Ratio, maxIter, eta0, powerT, epsilon, lambda, intercept, y, 1, 0, w, 1, 0, x, N, 1, 0, workspace, 1, 0 ); // eslint-disable-line max-len - -var j; -console.log( 'Estimated intercept: %d', out.intercept ); -console.log( '' ); -console.log( 'feature | estimated weight' ); -for ( j = 0; j < N; j++ ) { - console.log( '%d\t| %d', j, out.weights[ j ] ); -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi deleted file mode 100644 index 4217944b5d20..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/include.gypi +++ /dev/null @@ -1,70 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# A GYP include file for building a Node.js native add-on. -# -# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. -# -# Main documentation: -# -# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md -# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md -# -# Variable nesting hacks: -# -# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi -# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 -{ - # Define variables to be used throughout the configuration for all targets: - 'variables': { - 'variables': { - # Host BLAS library (to override -Dblas=): - 'blas%': '', - - # Path to BLAS library (to override -Dblas_dir=): - 'blas_dir%': '', - }, # end variables - - # Source directory: - 'src_dir': './src', - - # Include directories: - 'include_dirs': [ - '<@(blas_dir)', - '=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdmath", - "mathematics", - "math", - "blas", - "level 2", - "dgemv", - "linear", - "algebra", - "subroutines", - "array", - "ndarray", - "float64", - "double", - "float64array" - ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile deleted file mode 100644 index 7733b6180cb4..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2025 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - - -# RULES # - -#/ -# Removes generated files for building an add-on. -# -# @example -# make clean-addon -#/ -clean-addon: - $(QUIET) -rm -f *.o *.node - -.PHONY: clean-addon - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: clean-addon - -.PHONY: clean diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c deleted file mode 100644 index ba7c224c2564..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/addon.c +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_int32.h" -#include "stdlib/napi/argv_double.h" -#include "stdlib/napi/argv_strided_float64array.h" -#include "stdlib/napi/argv_strided_float64array2d.h" -#include - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - CBLAS_INT xlen; - CBLAS_INT ylen; - CBLAS_INT sa1; - CBLAS_INT sa2; - - STDLIB_NAPI_ARGV( env, info, argv, argc, 12 ); - - STDLIB_NAPI_ARGV_INT32( env, layout, argv, 0 ); - STDLIB_NAPI_ARGV_INT32( env, trans, argv, 1 ); - - STDLIB_NAPI_ARGV_INT64( env, M, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 3 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); - STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 6 ); - - STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 4 ); - STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 9 ); - - if ( trans == CblasNoTrans ) { - xlen = N; - ylen = M; - } else { - xlen = M; - ylen = N; - } - if ( layout == CblasColMajor ) { - sa1 = 1; - sa2 = LDA; - } else { // layout == CblasRowMajor - sa1 = LDA; - sa2 = 1; - } - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, xlen, strideX, argv, 7 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, ylen, strideY, argv, 10 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, M, N, sa1, sa2, argv, 5 ); - - API_SUFFIX(c_dgemv)( layout, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY ); - - return NULL; -} - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon_method( napi_env env, napi_callback_info info ) { - CBLAS_INT xlen; - CBLAS_INT ylen; - - STDLIB_NAPI_ARGV( env, info, argv, argc, 15 ); - - STDLIB_NAPI_ARGV_INT32( env, trans, argv, 0 ); - - STDLIB_NAPI_ARGV_INT64( env, M, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 9 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 10 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 13 ); - STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 14 ); - STDLIB_NAPI_ARGV_INT64( env, strideA1, argv, 5 ); - STDLIB_NAPI_ARGV_INT64( env, strideA2, argv, 6 ); - STDLIB_NAPI_ARGV_INT64( env, offsetA, argv, 7 ); - - STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); - STDLIB_NAPI_ARGV_DOUBLE( env, beta, argv, 11 ); - - if ( trans == CblasNoTrans ) { - xlen = N; - ylen = M; - } else { - xlen = M; - ylen = N; - } - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, xlen, strideX, argv, 8 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, ylen, strideY, argv, 12 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY2D( env, A, M, N, strideA1, strideA2, argv, 4 ); - - API_SUFFIX(c_dgemv_ndarray)( trans, M, N, alpha, A, strideA1, strideA2, offsetA, X, strideX, offsetX, beta, Y, strideY, offsetY ); - - return NULL; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c deleted file mode 100644 index 87894f033e66..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv.c +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/blas/base/xerbla.h" -#include "stdlib/strided/base/stride2offset.h" - -/** -* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix. -* -* @param layout storage layout -* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed -* @param M number of rows in the matrix `A` -* @param N number of columns in the matrix `A` -* @param alpha scalar constant -* @param A input matrix -* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) -* @param X first input vector -* @param strideX `X` stride length -* @param beta scalar constant -* @param Y second input vector -* @param strideY `Y` stride length -*/ -void API_SUFFIX(c_dgemv)( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { - CBLAS_INT vala; - CBLAS_INT xlen; - CBLAS_INT ylen; - CBLAS_INT sa1; - CBLAS_INT sa2; - CBLAS_INT ox; - CBLAS_INT oy; - CBLAS_INT v; - - // Perform input argument validation... - if ( layout != CblasRowMajor && layout != CblasColMajor ) { - c_xerbla( 1, "c_dgemv", "Error: invalid argument. First argument must be a valid storage layout. Value: `%d`.", layout ); - return; - } - if ( trans != CblasTrans && trans != CblasConjTrans && trans != CblasNoTrans ) { - c_xerbla( 2, "c_dgemv", "Error: invalid argument. Second argument must be a valid transpose operation. Value: `%d`.", trans ); - return; - } - if ( M < 0 ) { - c_xerbla( 3, "c_dgemv", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", M ); - return; - } - if ( N < 0 ) { - c_xerbla( 4, "c_dgemv", "Error: invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.", N ); - return; - } - if ( strideX == 0 ) { - c_xerbla( 9, "c_dgemv", "Error: invalid argument. Ninth argument must be nonzero. Value: `%d`.", strideX ); - return; - } - if ( strideY == 0 ) { - c_xerbla( 12, "c_dgemv", "Error: invalid argument. Twelfth argument must be nonzero. Value: `%d`.", strideY ); - return; - } - if ( layout == CblasColMajor ) { - v = M; - } else { - v = N; - } - // max(1, v) - if ( v < 1 ) { - vala = 1; - } else { - vala = v; - } - if ( LDA < vala ) { - c_xerbla( 10, "c_dgemv", "Error: invalid argument. Seventh argument must be greater than or equal to max(1,%d). Value: `%d`.", v, LDA ); - return; - } - // Check if we can early return... - if ( M == 0 || N == 0 || ( alpha == 0.0 && beta == 1.0 ) ) { - return; - } - if ( trans == CblasNoTrans ) { - xlen = N; - ylen = M; - } else { - xlen = M; - ylen = N; - } - if ( layout == CblasColMajor ) { - sa1 = 1; - sa2 = LDA; - } else { // layout == CblasRowMajor - sa1 = LDA; - sa2 = 1; - } - ox = stdlib_strided_stride2offset( xlen, strideX ); - oy = stdlib_strided_stride2offset( ylen, strideY ); - API_SUFFIX(c_dgemv_ndarray)( trans, M, N, alpha, A, sa1, sa2, 0, X, strideX, ox, beta, Y, strideY, oy ); - return; -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c deleted file mode 100644 index 1148dd26f9c9..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_cblas.c +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/dgemv_cblas.h" -#include "stdlib/blas/base/shared.h" - -/** -* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. -* -* @param layout storage layout -* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed -* @param M number of rows in the matrix `A` -* @param N number of columns in the matrix `A` -* @param alpha scalar constant -* @param A input matrix -* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) -* @param x first input vector -* @param strideX `x` stride length -* @param beta scalar constant -* @param y second input vector -* @param strideY `y` stride length -*/ -void API_SUFFIX(c_dgemv)( const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, const double beta, double *Y, const CBLAS_INT strideY ) { - API_SUFFIX(cblas_dgemv)( layout, trans, M, N, alpha, A, LDA, X, strideX, beta, Y, strideY ); -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c deleted file mode 100644 index 6e1592a58dc2..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/src/dgemv_ndarray.c +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ml/strided/dsgd-trainer.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/blas/base/xerbla.h" -#include "stdlib/blas/base/dscal.h" -#include "stdlib/blas/ext/base/dfill.h" -#include "stdlib/ndarray/base/assert/is_row_major.h" -#include - -/** -* Performs one of the matrix-vector operations `Y = α*A*X + β*Y` or `Y = α*A^T*X + β*Y`, using alternative indexing semantics and where `α` and `β` are scalars, `X` and `Y` are vectors, and `A` is an `M` by `N` matrix. -* -* @param trans specifies whether `A` should be transposed, conjugate-transposed, or not transposed -* @param M number of rows in the matrix `A` -* @param N number of columns in the matrix `A` -* @param alpha scalar constant -* @param A input matrix -* @param strideA1 stride of the first dimension of `A` -* @param strideA2 stride of the second dimension of `A` -* @param offsetA starting index for `A` -* @param X first input vector -* @param strideX `X` stride length -* @param offsetX starting index for `X` -* @param beta scalar constant -* @param Y second input vector -* @param strideY `Y` stride length -* @param offsetY starting index for `Y` -*/ -void API_SUFFIX(c_dgemv_ndarray)( const CBLAS_TRANSPOSE trans, const CBLAS_INT M, const CBLAS_INT N, const double alpha, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double beta, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { - int64_t sa[ 2 ]; - CBLAS_INT xlen; - CBLAS_INT ylen; - CBLAS_INT da0; - CBLAS_INT da1; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT ia; - CBLAS_INT i0; - CBLAS_INT i1; - double tmp; - bool isrm; - - // Note on variable naming convention: da#, i# where # corresponds to the loop number, with `0` being the innermost loop... - - // Perform input argument validation... - if ( trans != CblasTrans && trans != CblasConjTrans && trans != CblasNoTrans ) { - c_xerbla( 1, "c_dgemv_ndarray", "Error: invalid argument. First argument must be a valid transpose operation. Value: `%d`.", trans ); - return; - } - if ( M < 0 ) { - c_xerbla( 2, "c_dgemv_ndarray", "Error: invalid argument. Second argument must be a nonnegative integer. Value: `%d`.", M ); - return; - } - if ( N < 0 ) { - c_xerbla( 3, "c_dgemv_ndarray", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", N ); - return; - } - if ( strideX == 0 ) { - c_xerbla( 10, "c_dgemv_ndarray", "Error: invalid argument. Tenth argument must be nonzero. Value: `%d`.", strideX ); - return; - } - if ( strideY == 0 ) { - c_xerbla( 14, "c_dgemv_ndarray", "Error: invalid argument. Fourteenth argument must be nonzero. Value: `%d`.", strideY ); - return; - } - // Check whether we can avoid computation altogether... - if ( M == 0 || N == 0 || ( alpha == 0.0 && beta == 1.0 ) ) { - return; - } - // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... - sa[ 0 ] = strideA1; - sa[ 1 ] = strideA2; - isrm = stdlib_ndarray_is_row_major( 2, sa ); - if ( trans == CblasNoTrans ) { - xlen = N; - ylen = M; - } else { - xlen = M; - ylen = N; - } - // Y = beta * Y - if ( beta == 0.0 ) { - API_SUFFIX(stdlib_strided_dfill_ndarray)( ylen, 0.0, Y, strideY, offsetY ); - } else if ( beta != 1.0 ) { - API_SUFFIX(c_dscal_ndarray)( ylen, beta, Y, strideY, offsetY ); - } - if ( alpha == 0.0 ) { - return; - } - // Form: Y = α*A*X + Y - if ( - ( !isrm && trans == CblasNoTrans ) || - ( isrm && trans != CblasNoTrans ) - ) { - if ( isrm ) { - // For row-major matrices, the last dimension has the fastest changing index... - da0 = strideA2; // offset increment for innermost loop - da1 = strideA1 - ( ylen*strideA2 ); // offset increment for outermost loop - } else { // isColMajor - // For column-major matrices, the first dimension has the fastest changing index... - da0 = strideA1; // offset increment for innermost loop - da1 = strideA2 - ( ylen*strideA1 ); // offset increment for outermost loop - } - ia = offsetA; - ix = offsetX; - for ( i1 = 0; i1 < xlen; i1++ ) { - tmp = alpha * X[ ix ]; - if ( tmp == 0.0 ) { - ia += da0 * ylen; - } else { - iy = offsetY; - for ( i0 = 0; i0 < ylen; i0++ ) { - Y[ iy ] += A[ ia ] * tmp; - iy += strideY; - ia += da0; - } - } - ix += strideX; - ia += da1; - } - return; - } - // Form: Y = α*A^T*X + Y - - // ( !isrm && trans != CblasNoTrans ) || ( isrm && trans == CblasNoTrans ) - if ( isrm ) { - // For row-major matrices, the last dimension has the fastest changing index... - da0 = strideA2; // offset increment for innermost loop - da1 = strideA1 - ( xlen*strideA2 ); // offset increment for outermost loop - } else { // isColMajor - // For column-major matrices, the first dimension has the fastest changing index... - da0 = strideA1; // offset increment for innermost loop - da1 = strideA2 - ( xlen*strideA1 ); // offset increment for outermost loop - } - ia = offsetA; - iy = offsetY; - for ( i1 = 0; i1 < ylen; i1++ ) { - tmp = 0.0; - ix = offsetX; - for ( i0 = 0; i0 < xlen; i0++ ) { - tmp += A[ ia ] * X[ ix ]; - ix += strideX; - ia += da0; - } - Y[ iy ] += alpha * tmp; - iy += strideY; - ia += da1; - } - return; -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json deleted file mode 100644 index 33f237a34ca8..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_alpha_zero.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.0, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 0.5, 1.0, 1.5, 2.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json deleted file mode 100644 index a87cd0111f38..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_complex_access_pattern.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "strideA1": -2, - "strideA2": -5, - "offsetA": 14, - "strideX": -1, - "offsetX": 2, - "strideY": -1, - "offsetY": 2, - "M": 3, - "N": 3, - "alpha": 0.5, - "beta": 0.5, - "A": [ 6, 999, 0, 999, 0, 5, 999, 4, 999, 0, 3, 999, 2, 999, 1 ], - "x": [ 3.0, 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "y_out": [ 16.0, 6.0, 2.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json deleted file mode 100644 index 705194b01e71..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_nt.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0, 13.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json deleted file mode 100644 index 92da961fb13a..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_oa.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 3.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 2, - "strideA2": 10, - "offsetA": 5, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json deleted file mode 100644 index 6a262d2a7778..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 1.0, 999.0, 3.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 2, - "strideA2": 10, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json deleted file mode 100644 index c91c334cc3e2..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1_sa2n.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 4.0, 999.0, 6.0, 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 3.0, 999.0, 5.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 2, - "strideA2": -10, - "offsetA": 15, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json deleted file mode 100644 index fae84fbff430..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 3.0, 999.0, 1.0, 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 4.0, 999.0, 2.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": -2, - "strideA2": 10, - "offsetA": 9, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json deleted file mode 100644 index e21c2724e2b7..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_sa1n_sa2n.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 4.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 3.0, 999.0, 1.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": -2, - "strideA2": -10, - "offsetA": 19, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json deleted file mode 100644 index 86fb6a0f8c12..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_t.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 1.0, 2.0, 3.0, 4.0 ], - "y": [ 1.0, 2.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 15.5, 36.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json deleted file mode 100644 index a0ec9dd61530..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], - "x": [ 0.0, 0.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 0.5, 1.0, 1.5, 2.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json deleted file mode 100644 index 59e66f7499ac..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_x_zeros_beta_one.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 1.0, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0 ], - "x": [ 0.0, 0.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 1.0, 2.0, 3.0, 4.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json deleted file mode 100644 index 284eddccf93f..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyn.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": -1, - "offsetX": 1, - "strideY": -1, - "offsetY": 3, - "y_out": [ 12.0, 9.5, 7.0, 4.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json deleted file mode 100644 index e8ff2247130c..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xnyp.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": -1, - "offsetX": 1, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0, 13.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json deleted file mode 100644 index 3c275aa0a642..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyn.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": -1, - "offsetY": 3, - "y_out": [ 11.5, 9.0, 6.5, 4.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json deleted file mode 100644 index 08e3b227164d..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/column_major_xpyp.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "column-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 4, - "A": [ 1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 1, - "strideA2": 4, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 2.5, 6.0, 9.5, 13.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json deleted file mode 100644 index 1bced86ae275..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_alpha_zero.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.0, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 0.5, 1.0, 1.5, 2.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json deleted file mode 100644 index 555645d3c7cd..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_complex_access_pattern.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "strideA1": -6, - "strideA2": -1, - "offsetA": 14, - "strideX": -1, - "offsetX": 2, - "strideY": -1, - "offsetY": 2, - "alpha": 0.5, - "beta": 0.5, - "M": 3, - "N": 3, - "A": [ 6, 5, 3, 999, 999, 999, 0, 4, 2, 999, 999, 999, 0, 0, 1 ], - "x": [ 1.0, 2.0, 3.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "y_out": [ 13.0, 8.0, 3.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json deleted file mode 100644 index 1c345e420443..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_nt.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0, 13.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json deleted file mode 100644 index c8c69c1071ba..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_oa.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 1.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 6.0, 999.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 10, - "strideA2": 2, - "offsetA": 1, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json deleted file mode 100644 index f3ea02405b4d..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 1.0, 999.0, 2.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 5.0, 999.0, 6.0, 999.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 8, - "strideA2": 2, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json deleted file mode 100644 index a7b79aa7d772..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1_sa2n.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 2.0, 999.0, 1.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 4.0, 999.0, 3.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 6.0, 999.0, 5.0, 999.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": 10, - "strideA2": -2, - "offsetA": 3, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json deleted file mode 100644 index 14a0b13c491d..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 5.0, 999.0, 6.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 3.0, 999.0, 4.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 1.0, 999.0, 2.0, 999.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": -10, - "strideA2": 2, - "offsetA": 21, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json deleted file mode 100644 index 78a6ff3cc584..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_sa1n_sa2n.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "trans": "no-transpose", - "M": 3, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "A": [ 999.0, 6.0, 999.0, 5.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 4.0, 999.0, 3.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 999.0, 2.0, 999.0, 1.0, 999.0 ], - "x": [ 1.0, 2.0 ], - "y": [ 1.0, 2.0, 3.0 ], - "strideA1": -10, - "strideA2": -2, - "offsetA": 23, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json deleted file mode 100644 index ca04d44b2a20..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_t.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 1.0, 2.0, 3.0, 4.0 ], - "y": [ 1.0, 2.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 25.5, 31.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json deleted file mode 100644 index 7a5af3e7dc61..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 0.0, 0.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 0.5, 1.0, 1.5, 2.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json deleted file mode 100644 index dd08640b3da7..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_x_zeros_beta_one.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 1.0, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 0.0, 0.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 1.0, 2.0, 3.0, 4.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json deleted file mode 100644 index 71fee7b136b8..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyn.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": -1, - "offsetX": 1, - "strideY": -1, - "offsetY": 3, - "y_out": [ 12.0, 9.5, 7.0, 4.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json deleted file mode 100644 index 3075694a1111..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xnyp.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": -1, - "offsetX": 1, - "strideY": 1, - "offsetY": 0, - "y_out": [ 3.0, 6.5, 10.0, 13.5 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json deleted file mode 100644 index d3ab52c45feb..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyn.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": -1, - "offsetY": 3, - "y_out": [ 11.5, 9.0, 6.5, 4.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json deleted file mode 100644 index d5fae06293fc..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/fixtures/row_major_xpyp.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "order": "row-major", - "trans": "no-transpose", - "M": 4, - "N": 2, - "alpha": 0.5, - "beta": 0.5, - "lda": 2, - "A": [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - "x": [ 2.0, 1.0 ], - "y": [ 1.0, 2.0, 3.0, 4.0 ], - "strideA1": 2, - "strideA2": 1, - "offsetA": 0, - "strideX": 1, - "offsetX": 0, - "strideY": 1, - "offsetY": 0, - "y_out": [ 2.5, 6.0, 9.5, 13.0 ] -} diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js deleted file mode 100644 index 6e6257e70d91..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.js +++ /dev/null @@ -1,791 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var dgemv = require( './../lib/dgemv.js' ); - - -// FIXTURES // - -var cnt = require( './fixtures/column_major_nt.json' ); -var ct = require( './fixtures/column_major_t.json' ); -var cxnyn = require( './fixtures/column_major_xnyn.json' ); -var cxpyn = require( './fixtures/column_major_xpyn.json' ); -var cxnyp = require( './fixtures/column_major_xnyp.json' ); -var cxpyp = require( './fixtures/column_major_xpyp.json' ); -var cx = require( './fixtures/column_major_x_zeros.json' ); -var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); -var ca = require( './fixtures/column_major_alpha_zero.json' ); - -var rnt = require( './fixtures/row_major_nt.json' ); -var rt = require( './fixtures/row_major_t.json' ); -var rxnyn = require( './fixtures/row_major_xnyn.json' ); -var rxpyn = require( './fixtures/row_major_xpyn.json' ); -var rxnyp = require( './fixtures/row_major_xnyp.json' ); -var rxpyp = require( './fixtures/row_major_xpyp.json' ); -var rx = require( './fixtures/row_major_x_zeros.json' ); -var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); -var ra = require( './fixtures/row_major_alpha_zero.json' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 12', function test( t ) { - t.strictEqual( dgemv.length, 12, 'returns expected value' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid first argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( value, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid second argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid third argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid fourth argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid seventh argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 1, - 0, - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), value, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid ninth argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), value, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid twelfth argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), value ); - }; - } -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (row-major)', function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (column-major)', function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ra; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ca; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js deleted file mode 100644 index 90b9801682d1..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.dgemv.native.js +++ /dev/null @@ -1,799 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// FIXTURES // - -var cnt = require( './fixtures/column_major_nt.json' ); -var ct = require( './fixtures/column_major_t.json' ); -var cxnyn = require( './fixtures/column_major_xnyn.json' ); -var cxpyn = require( './fixtures/column_major_xpyn.json' ); -var cxnyp = require( './fixtures/column_major_xnyp.json' ); -var cxpyp = require( './fixtures/column_major_xpyp.json' ); -var cx = require( './fixtures/column_major_x_zeros.json' ); -var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); -var ca = require( './fixtures/column_major_alpha_zero.json' ); -var rnt = require( './fixtures/row_major_nt.json' ); -var rt = require( './fixtures/row_major_t.json' ); -var rxnyn = require( './fixtures/row_major_xnyn.json' ); -var rxpyn = require( './fixtures/row_major_xpyn.json' ); -var rxnyp = require( './fixtures/row_major_xnyp.json' ); -var rxpyp = require( './fixtures/row_major_xpyp.json' ); -var rx = require( './fixtures/row_major_x_zeros.json' ); -var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); -var ra = require( './fixtures/row_major_alpha_zero.json' ); - - -// VARIABLES // - -var dgemv = tryRequire( resolve( __dirname, './../lib/dgemv.native.js' ) ); -var opts = { - 'skip': ( dgemv instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 12', opts, function test( t ) { - t.strictEqual( dgemv.length, 12, 'returns expected value' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( value, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid fourth argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid seventh argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 1, - 0, - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), value, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid ninth argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), value, data.beta, new Float64Array( data.y ), data.strideY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid twelfth argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.order, data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.LDA, new Float64Array( data.x ), data.strideX, data.beta, new Float64Array( data.y ), value ); - }; - } -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (row-major)', opts, function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (column-major)', opts, function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, 0, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.order, data.trans, data.M, 0, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.order, data.trans, data.M, data.N, 0.0, a, data.lda, x, data.strideX, 1.0, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ra; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ca; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.order, data.trans, data.M, data.N, data.alpha, a, data.lda, x, data.strideX, data.beta, y, data.strideY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js deleted file mode 100644 index 58253939a980..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var dgemv = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof dgemv.ndarray, 'function', 'method is a function' ); - t.end(); -}); - -tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { - var dgemv = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( dgemv, mock, 'returns expected value' ); - t.end(); - - function tryRequire() { - return mock; - } - - function mock() { - // Mock... - } -}); - -tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { - var dgemv; - var main; - - main = require( './../lib/dgemv.js' ); - - dgemv = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( dgemv, main, 'returns expected value' ); - t.end(); - - function tryRequire() { - return new Error( 'Cannot find module' ); - } -}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js deleted file mode 100644 index 0687216267e0..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.js +++ /dev/null @@ -1,1025 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var dgemv = require( './../lib/ndarray.js' ); - - -// FIXTURES // - -var cap = require( './fixtures/column_major_complex_access_pattern.json' ); -var cnt = require( './fixtures/column_major_nt.json' ); -var ct = require( './fixtures/column_major_t.json' ); -var coa = require( './fixtures/column_major_oa.json' ); -var csa1sa2 = require( './fixtures/column_major_sa1_sa2.json' ); -var csa1nsa2 = require( './fixtures/column_major_sa1n_sa2.json' ); -var csa1sa2n = require( './fixtures/column_major_sa1_sa2n.json' ); -var csa1nsa2n = require( './fixtures/column_major_sa1n_sa2n.json' ); -var cxnyn = require( './fixtures/column_major_xnyn.json' ); -var cxpyn = require( './fixtures/column_major_xpyn.json' ); -var cxnyp = require( './fixtures/column_major_xnyp.json' ); -var cxpyp = require( './fixtures/column_major_xpyp.json' ); -var cx = require( './fixtures/column_major_x_zeros.json' ); -var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); -var ca = require( './fixtures/column_major_alpha_zero.json' ); -var rap = require( './fixtures/row_major_complex_access_pattern.json' ); -var rnt = require( './fixtures/row_major_nt.json' ); -var rt = require( './fixtures/row_major_t.json' ); -var roa = require( './fixtures/row_major_oa.json' ); -var rsa1sa2 = require( './fixtures/row_major_sa1_sa2.json' ); -var rsa1nsa2 = require( './fixtures/row_major_sa1n_sa2.json' ); -var rsa1sa2n = require( './fixtures/row_major_sa1_sa2n.json' ); -var rsa1nsa2n = require( './fixtures/row_major_sa1n_sa2n.json' ); -var rxnyn = require( './fixtures/row_major_xnyn.json' ); -var rxpyn = require( './fixtures/row_major_xpyn.json' ); -var rxnyp = require( './fixtures/row_major_xnyp.json' ); -var rxpyp = require( './fixtures/row_major_xpyp.json' ); -var rx = require( './fixtures/row_major_x_zeros.json' ); -var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); -var ra = require( './fixtures/row_major_alpha_zero.json' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 15', function test( t ) { - t.strictEqual( dgemv.length, 15, 'returns expected value' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid first argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid second argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid third argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid tenth argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), value, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid fourteenth argument', function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), value, data.offsetY ); - }; - } -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (row-major)', function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (column-major)', function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ra; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ca; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the strides of the first and second dimensions of `A` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1sa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the strides of the first and second dimensions of `A` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1sa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the first dimension of `A` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1nsa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the first dimension of `A` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1nsa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the second dimension of `A` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1sa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the second dimension of `A` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1sa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative strides for `A` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1nsa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative strides for `A` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1nsa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying an offset parameter for `A` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = roa; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying an offset parameter for `A` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = coa; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying negative strides for `x` and `y` (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying negative strides for `x` and `y` (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (row-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rap; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (column-major)', function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cap; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js b/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js deleted file mode 100644 index 0c195ceeda36..000000000000 --- a/lib/node_modules/@stdlib/ml/strided/dsgd-trainer/test/test.ndarray.native.js +++ /dev/null @@ -1,1035 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -// MODULES // - -var resolve = require( 'path' ).resolve; -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// FIXTURES // - -var cap = require( './fixtures/column_major_complex_access_pattern.json' ); -var cnt = require( './fixtures/column_major_nt.json' ); -var ct = require( './fixtures/column_major_t.json' ); -var coa = require( './fixtures/column_major_oa.json' ); -var csa1sa2 = require( './fixtures/column_major_sa1_sa2.json' ); -var csa1nsa2 = require( './fixtures/column_major_sa1n_sa2.json' ); -var csa1sa2n = require( './fixtures/column_major_sa1_sa2n.json' ); -var csa1nsa2n = require( './fixtures/column_major_sa1n_sa2n.json' ); -var cxnyn = require( './fixtures/column_major_xnyn.json' ); -var cxpyn = require( './fixtures/column_major_xpyn.json' ); -var cxnyp = require( './fixtures/column_major_xnyp.json' ); -var cxpyp = require( './fixtures/column_major_xpyp.json' ); -var cx = require( './fixtures/column_major_x_zeros.json' ); -var cxb = require( './fixtures/column_major_x_zeros_beta_one.json' ); -var ca = require( './fixtures/column_major_alpha_zero.json' ); - -var rap = require( './fixtures/row_major_complex_access_pattern.json' ); -var rnt = require( './fixtures/row_major_nt.json' ); -var rt = require( './fixtures/row_major_t.json' ); -var roa = require( './fixtures/row_major_oa.json' ); -var rsa1sa2 = require( './fixtures/row_major_sa1_sa2.json' ); -var rsa1nsa2 = require( './fixtures/row_major_sa1n_sa2.json' ); -var rsa1sa2n = require( './fixtures/row_major_sa1_sa2n.json' ); -var rsa1nsa2n = require( './fixtures/row_major_sa1n_sa2n.json' ); -var rxnyn = require( './fixtures/row_major_xnyn.json' ); -var rxpyn = require( './fixtures/row_major_xpyn.json' ); -var rxnyp = require( './fixtures/row_major_xnyp.json' ); -var rxpyp = require( './fixtures/row_major_xpyp.json' ); -var rx = require( './fixtures/row_major_x_zeros.json' ); -var rxb = require( './fixtures/row_major_x_zeros_beta_one.json' ); -var ra = require( './fixtures/row_major_alpha_zero.json' ); - - -// VARIABLES // - -var dgemv = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( dgemv instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dgemv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 15', opts, function test( t ) { - t.strictEqual( dgemv.length, 15, 'returns expected value' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 'foo', - 'bar', - 'beep', - 'boop' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( value, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, value, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - -1, - -2, - -3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, value, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid tenth argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), value, data.offsetX, data.beta, new Float64Array( data.y ), data.strideY, data.offsetY ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid fourteenth argument', opts, function test( t ) { - var values; - var data; - var i; - - data = rnt; - - values = [ - 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - dgemv( data.trans, data.M, data.N, data.alpha, new Float64Array( data.A ), data.strideA1, data.strideA2, data.offsetA, new Float64Array( data.x ), data.strideX, data.offsetX, data.beta, new Float64Array( data.y ), value, data.offsetY ); - }; - } -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, no-transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, no-transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cnt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (row-major, transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` (column-major, transpose)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (row-major)', opts, function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a reference to the second input vector (column-major)', opts, function test( t ) { - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if either `M` or `N` is `0`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, 0, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - out = dgemv( data.trans, data.M, 0, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rt; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0` and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ct; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y ); - - out = dgemv( data.trans, data.M, data.N, 0.0, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, 1.0, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is `1`, the function returns the second input vector unchanged (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxb; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ra; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `α` is `0`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = ca; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `x` contains only zeros and `β` is not `1`, the function scales the second input vector by `β` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cx; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the strides of the first and second dimensions of `A` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1sa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the strides of the first and second dimensions of `A` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1sa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the first dimension of `A` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1nsa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the first dimension of `A` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1nsa2; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the second dimension of `A` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1sa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a negative stride for the second dimension of `A` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1sa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative strides for `A` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rsa1nsa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports negative strides for `A` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = csa1nsa2n; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying an offset parameter for `A` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = roa; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying an offset parameter for `A` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = coa; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying `x` and `y` strides (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `x` stride (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyp; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a negative `y` stride (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxpyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying negative strides for `x` and `y` (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying negative strides for `x` and `y` (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cxnyn; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (row-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = rap; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports complex access patterns (column-major)', opts, function test( t ) { - var expected; - var data; - var out; - var a; - var x; - var y; - - data = cap; - - a = new Float64Array( data.A ); - x = new Float64Array( data.x ); - y = new Float64Array( data.y ); - - expected = new Float64Array( data.y_out ); - - out = dgemv( data.trans, data.M, data.N, data.alpha, a, data.strideA1, data.strideA2, data.offsetA, x, data.strideX, data.offsetX, data.beta, y, data.strideY, data.offsetY ); - t.strictEqual( out, y, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -});