From eb3cdcf5b60cb3b200765c7cea9d2a5974c27b2c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 29 Aug 2025 12:16:14 +0000 Subject: [PATCH] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index ddc7ad3..acf44e7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,7 +29,7 @@ var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); var zeros = require( '@stdlib/array-base-zeros' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -105,7 +105,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array: strides = zeros( N ); @@ -121,7 +121,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -130,7 +130,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 48bc45f..03ee17b 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" },