Skip to content

feat: add blas/ext/axpb#12861

Open
anandkaranubc wants to merge 10 commits into
stdlib-js:developfrom
anandkaranubc:feat/axpb
Open

feat: add blas/ext/axpb#12861
anandkaranubc wants to merge 10 commits into
stdlib-js:developfrom
anandkaranubc:feat/axpb

Conversation

@anandkaranubc

Copy link
Copy Markdown
Contributor

Resolves stdlib-js/metr-issue-tracker#639

Description

What is the purpose of this pull request?

This pull request:

  • adds blas/ext/base/axpb

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

Used Cursor+VS Code code-generation tools to help assist with the feature.


@stdlib-js/reviewers

---
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: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - 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: passed
  - task: lint_license_headers
    status: passed
---
@anandkaranubc anandkaranubc requested a review from a team June 14, 2026 03:04
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Needs Review A pull request which needs code review. labels Jun 14, 2026
@stdlib-bot

stdlib-bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
blas/ext/axpb $\\color{red}346/348$
$\\color{green}+0.00\\%$
$\\color{red}37/38$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{red}346/348$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@anandkaranubc

Copy link
Copy Markdown
Contributor Author

Total implementation time: 202 minutes 😅

I finally was able to implement this, @kgryte! 😮‍💨

@anandkaranubc anandkaranubc added Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. METR Pull request associated with the METR project. labels Jun 14, 2026
anandkaranubc and others added 2 commits June 13, 2026 20:07
---
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: passed
  - 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
---
@anandkaranubc anandkaranubc changed the title feat: add blas/ext/base/axpb feat: add blas/ext/axpb Jun 14, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Jun 14, 2026
var bench = require( '@stdlib/bench' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var uniform = require( '@stdlib/random/array/uniform' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var uniform = require( '@stdlib/random/array/uniform' );
var uniform = require( '@stdlib/random/uniform' );

You should be using the API to generate random ndarrays directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we are doing this in blas/ext/cusum, but that should likely be updated in order to use top-level APIs. Feel free to make a METR task to update the top-level blas/ext/* APIs (where appropriate).

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var uniform = require( '@stdlib/random/array/uniform' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var ndarray = require( '@stdlib/ndarray/base/ctor' );

* ## Notes
*
* - The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**).
* - By default, the function multiplies each element by `1.0` and adds `0.0` (i.e., performs a no-op).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are alpha and beta optional parameters? This seems odd to me. I would expect them to be mandatory, as that is the entire point of axpb.

Comment on lines +35 to +40
type Alpha = ndarray | number | ComplexLike;

/**
* Beta parameter.
*/
type Beta = ndarray | number | ComplexLike;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of separate types, I would suggest doing something like type ScalarArgument = ndarray | ... and then, in your signatures, do alpha: ScalarArgument, beta: ScalarArgument, etc.

@@ -0,0 +1,50 @@

{{alias}}( x[, alpha][, beta][, options] )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this sort of signature is going to lead to all sorts of argument juggling, especially as you have no way of distinguishing between alpha and beta when wanting to only provide beta.

TL;DR: make alpha and beta mandatory arguments, similar to have the searchElement argument in index-of is mandatory.

Comment on lines +26 to +41
// Create a data buffer:
var xbuf = discreteUniform( 10, -100, 100, {
'dtype': 'generic'
});

// Define the shape of the input array:
var shape = [ 5, 2 ];

// Define the array strides:
var sx = [ 2, 1 ];

// Define the index offset:
var ox = 0;

// Create an input ndarray:
var x = new ndarray( 'generic', xbuf, shape, sx, ox, 'row-major' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the top-level random/discrete-uniform package. Then you can avoid all this manual ndarray creation noise.

'default': gaxpb
};
var options = {
'strictTraversalOrder': true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

@kgryte kgryte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left initial comments. TL;DR: this needs to be refactored to make alpha and beta mandatory. This should simplify your argument juggling logic significantly.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Jun 14, 2026
---
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: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - 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: passed
  - task: lint_license_headers
    status: passed
---
@anandkaranubc anandkaranubc added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Jun 14, 2026
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/benchmark/benchmark.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/index.d.ts Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/test.ts Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/test.ts Outdated
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/test.ts Outdated
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/types/test.ts Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/repl.txt Outdated

alpha: ndarray|number
Scalar constant to multiply. May be either a scalar value, or an ndarray
having a floating-point or "generic" data type. If provided an ndarray,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
having a floating-point or "generic" data type. If provided an ndarray,
having a numeric or "generic" data type. If provided an ndarray,

Given this change, you'll need to rewrap this description.

Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/blas/ext/axpb/docs/repl.txt Outdated

beta: ndarray|number
Scalar constant to add. May be either a scalar value, or an ndarray
having a floating-point or "generic" data type. Broadcasting semantics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
having a floating-point or "generic" data type. Broadcasting semantics
having a numeric or "generic" data type. Broadcasting semantics

Rewrap.

beta: ndarray|number
Scalar constant to add. May be either a scalar value, or an ndarray
having a floating-point or "generic" data type. Broadcasting semantics
are the same as for alpha.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just copy, paste, and modify the broadcasting semantics description from alpha. This makes very explicit that broadcasting is purely related to x and options.dims, and that there are no broadcasting semantics between alpha and beta.

Function options.

options.dims: Array<integer> (optional)
List of dimensions over which to perform operation. If not provided, the

@kgryte kgryte Jun 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means "flattening" during the operation, which I think is the right behavior, by default, for this API.

Comment thread lib/node_modules/@stdlib/blas/ext/axpb/examples/index.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment on lines +34 to +36
var idtypes0 = dtypes( 'floating_point_and_generic' ); // alpha ndarray
var idtypes1 = dtypes( 'floating_point_and_generic' ); // beta ndarray
var odtypes = dtypes( 'floating_point_and_generic' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we limited to floating-point data types here?

Couldn't I reasonably have, say, an int32 input array x, alpha = 5, and beta = 3 and have that delegate to gaxpb?

Suggested change
var idtypes0 = dtypes( 'floating_point_and_generic' ); // alpha ndarray
var idtypes1 = dtypes( 'floating_point_and_generic' ); // beta ndarray
var odtypes = dtypes( 'floating_point_and_generic' );
var idtypes0 = dtypes( 'numeric_and_generic' ); // alpha ndarray
var idtypes1 = dtypes( 'numeric_and_generic' ); // beta ndarray
var odtypes = dtypes( 'numeric_and_generic' );

throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );
}
if ( nargs < 3 ) {
throw new TypeError( 'invalid invocation. Insufficient arguments. Must provide an ndarray, alpha, and beta.' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new TypeError( 'invalid invocation. Insufficient arguments. Must provide an ndarray, alpha, and beta.' );
throw new TypeError( 'invalid invocation. Insufficient arguments. Must provide at least three arguments.' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimize future copy-paste mistakes.

// Broadcast alpha and beta to match the appropriate shape...

// Case: axpb( x, alpha_scalar, beta_scalar, ??? )
if ( isScalar( alpha ) && isScalar( beta ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do a lot of repeated isScalar( alpha ) and isScalar( beta ) here. Call once for both and assign the result to internal variables (e.g., isScalarAlpha = isScalar( alpha ), etc).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then can do explicit alpha and beta validation.

if ( !isScalarAlpha && !isndarrayLike( alpha ) ) {
	throw new TypeError( format( 'invalid argument. Second argument must be an ndarray, a number, or a complex number. Value: `%s`.', alpha ) );
}

And you can do all this before you hit L129. Meaning, you can take care of your validation up front, rather than have it intermingled with delegation and broadcasting logic.

}
}
// Case: axpb( x, alpha_ndarray, beta_ndarray, ??? )
else if ( isndarrayLike( alpha ) && isndarrayLike( beta ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the various conditionals, you have a decent amount of repeated logic. You should have a series of four conditionals after caching whether alpha and beta are scalars:

  • if isScalarAlpha, broadcastScalar
  • else maybeBroadcastArray
  • if isScalarBeta, broadcastScalar
  • else maybeBroadcastArray

That should be it. No combined conditions (e.g., if scalar alpha AND ndarray beta, do x and y and if ndarray alpha and ndarray beta, do z and y, etc etc). If you do things up front, you can handle each argument on its own.

beta = maybeBroadcastArray( beta, sh );
}
} else {
if ( !isScalar( alpha ) && !isndarrayLike( alpha ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, recognize that isndarrayLike checks are relatively expensive, as they involve materializing various meta data. If we do them, we want to only do them once, and, if the knowledge is needed again, make sure we cache the result in a variable.


The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a floating-point or "generic" [data type][@stdlib/ndarray/dtypes].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a floating-point or "generic" [data type][@stdlib/ndarray/dtypes].
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes].

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a floating-point or "generic" [data type][@stdlib/ndarray/dtypes].
- **alpha**: scalar constant to multiply. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] alpha must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] alpha must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **alpha**: scalar constant to multiply. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] alpha must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] alpha must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
- **alpha**: scalar constant to multiply. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] `alpha` must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] `alpha` must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].


- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a floating-point or "generic" [data type][@stdlib/ndarray/dtypes].
- **alpha**: scalar constant to multiply. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] alpha must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] alpha must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
- **beta**: scalar constant to add. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. Broadcasting semantics are the same as for alpha.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **beta**: scalar constant to add. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. Broadcasting semantics are the same as for alpha.
- **beta**: scalar constant to add. May be a numeric scalar (number or complex number) or an [ndarray][@stdlib/ndarray/ctor] having a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Broadcasting semantics are the same as for alpha.

I would also be more explicit regarding the broadcasting behavior, rather than just referring to alpha. If you want to avoid duplication, consider moving the broadcast discussion to the ## Notes section below and then saying "Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by options.dims. For more discussion, see the notes below." for both alpha and beta.

Comment on lines +76 to +100
Both `alpha` and `beta` can be complex numbers:

```javascript
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );

var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] );

var alpha = new Complex128( 2.0, 1.0 );
var beta = new Complex128( 1.0, 0.0 );

var y = axpb( x, alpha, beta );
// returns <ndarray>[ <Complex128>[ 1.0, 5.0 ], <Complex128>[ 3.0, 11.0 ] ]
```

The function also supports complex-valued floating-point ndarrays:

```javascript
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );

var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] );

var y = axpb( x, 2.0, 1.0 );
// returns <ndarray>[ <Complex128>[ 3.0, 4.0 ], <Complex128>[ 7.0, 8.0 ] ]
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples are a bit weak. Instead, I suggest consolidating into a single example which demonstrates the behavior when alpha and/or beta are/is real-valued and x is complex-valued. This highlights both that complex arrays are accepted and that real-values are casted to the dtype of x.

Comment on lines +148 to +150
});

// Print the input ndarray:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
// Print the input ndarray:
});

}
throw new TypeError( format( 'invalid argument. Third argument must be either an ndarray, a number, or a complex number. Value: `%s`.', beta ) );
}
// Case: axpb( x, alpha, beta )

@kgryte kgryte Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing which is not handled here is when alpha and beta are real-valued ndarrays and x is complex-valued. For real scalars, they are converted to complex-valued ndarrays. However, it doesn't seem that is the case for alpha and beta which are already ndarrays.

However, this also applies to blas/ext/cusum where we do real-to-complex conversion for scalar initial values, but not ndarray initial values.

Not sure the best approach, as we will want to consistently apply the same logic across relevant packages.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. METR Pull request associated with the METR project. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add blas/ext/axpb

3 participants