-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add blas/base/cgemv
#10485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add blas/base/cgemv
#10485
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3220a2a
docs: repl file updated
DivitJain26 33b2fe7
docs: package.json updated
DivitJain26 f70680c
chores: clean up in base.js
DivitJain26 c38fd95
chore: clean up in base.js
DivitJain26 f73c3f5
docs: description updated
DivitJain26 486945a
docs: comments updated
DivitJain26 59d8037
docs: typo corrected
DivitJain26 d7deb46
test: benchmark updated
DivitJain26 f8b34d8
test: fixtures and tests added of conjugate-transpose
DivitJain26 6a579e1
chore: clean up
DivitJain26 17e309c
chore: clean up
DivitJain26 1d34d00
Merge branch 'develop' into Blas/Base/CGEMV
DivitJain26 1454451
test: cover zero-beta branch
DivitJain26 7fe33f1
test: cover zero-beta branch in ndarray
DivitJain26 264ecd4
test: remove strideA1 and strideA2 validations and tests
DivitJain26 29e0eda
refactor: update index increment to stride addition
DivitJain26 a393955
Merge remote-tracking branch 'upstream/develop' into Blas/Base/CGEMV
stdlib-bot 4bb7daf
chore: clean up in benchmarks
DivitJain26 3db65c8
chore: clean up in index.d.ts
DivitJain26 dcd87a5
chore: clean up in docs
DivitJain26 7d40bfd
chore: clean up in example
DivitJain26 5c44017
chore: clean up in lib
DivitJain26 ea48227
chore: clean up in readme
DivitJain26 5203da8
Apply suggestions from code review
kgryte 6a74265
docs: fix comment
kgryte 1921795
Apply suggestions from code review
kgryte e085499
Apply suggestions from code review
kgryte c9692c3
Apply suggestions from code review
kgryte f7f5a83
test: clean-up
kgryte c20d54c
fix: pass correct argument
kgryte 58d7af6
test: fix failing tests
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,314 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # cgemv | ||
|
|
||
| > Perform one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` or `y = α*A^H*x + β*y` for complex-valued data. | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var cgemv = require( '@stdlib/blas/base/cgemv' ); | ||
| ``` | ||
|
|
||
| #### cgemv( 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` or `y = α*A^H*x + β*y` where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Complex64Array = require( '@stdlib/array/complex64' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
|
|
||
| var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] ); | ||
| var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0 ] ); | ||
| var y = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| cgemv( 'column-major', 'no-transpose', 4, 2, alpha, A, 4, x, 1, beta, y, 1 ); | ||
| // y => <Complex64Array>[ -10.0, 11.0, -12.0, 14.0, -14.0, 17.0, -16.0, 20.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 [`Complex64Array`][@stdlib/array/complex64]. | ||
| - **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). | ||
| - **x**: input [`Complex64Array`][@stdlib/array/complex64]. | ||
| - **sx**: stride length for `x`. | ||
| - **β**: scalar constant. | ||
| - **y**: output [`Complex64Array`][@stdlib/array/complex64]. | ||
| - **sy**: stride length for `y`. | ||
|
|
||
| The stride parameters determine how elements are accessed. For example, to iterate over every other element in `x` and `y`, | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Complex64Array = require( '@stdlib/array/complex64' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
|
|
||
| var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] ); | ||
| var x = new Complex64Array( [ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0 ] ); | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
| var y = new Complex64Array( [ 1.0, 1.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 3.0, 3.0, 0.0, 0.0, 4.0, 4.0 ] ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| cgemv( 'column-major', 'no-transpose', 4, 2, alpha, A, 4, x, 3, beta, y, 2 ); | ||
|
kgryte marked this conversation as resolved.
Outdated
|
||
| // y => <Complex64Array>[ -10.0, 11.0, 0.0, 0.0, -12.0, 14.0, 0.0, 0.0, -14.0, 17.0, 0.0, 0.0, -16.0, 20.0 ] | ||
| ``` | ||
|
|
||
| Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||
|
|
||
| <!-- eslint-disable stdlib/capitalized-comments --> | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Complex64Array = require( '@stdlib/array/complex64' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
|
|
||
| // Initial arrays... | ||
| var x0 = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0 ] ); | ||
| var y0 = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); | ||
| var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| // Create offset views... | ||
| var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd complex element | ||
| var y1 = new Complex64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd complex element | ||
|
|
||
| cgemv( 'column-major', 'no-transpose', 4, 2, alpha, A, 4, x1, 1, beta, y1, 1 ); | ||
| // y1 => <Complex64Array>[ -10.0, 11.0, -12.0, 14.0, -14.0, 17.0, -16.0, 20.0 ] | ||
| ``` | ||
|
|
||
| <!-- lint disable maximum-heading-length --> | ||
|
|
||
| #### cgemv.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` or `y = α*A^H*x + β*y` using alternative indexing semantics and where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix. | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Complex64Array = require( '@stdlib/array/complex64' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
|
|
||
| var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] ); | ||
| var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0 ] ); | ||
| var y = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| cgemv.ndarray( 'no-transpose', 4, 2, alpha, A, 1, 4, 0, x, 1, 0, beta, y, 1, 0 ); | ||
| // y => <Complex64Array>[ -10.0, 11.0, -12.0, 14.0, -14.0, 17.0, -16.0, 20.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, | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Complex64Array = require( '@stdlib/array/complex64' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
|
|
||
| var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] ); | ||
| var x = new Complex64Array( [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0 ] ); | ||
| var y = new Complex64Array( [ 4.0, 4.0, 0.0, 0.0, 3.0, 3.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0 ] ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| cgemv.ndarray( 'no-transpose', 4, 2, alpha, A, 1, 4, 0, x, 1, 1, beta, y, -2, 6 ); | ||
| // y => <Complex64Array>[ -16.0, 20.0, 0.0, 0.0, -14.0, 17.0, 0.0, 0.0, -12.0, 14.0, 0.0, 0.0, -10.0, 11.0 ] | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - `cgemv()` corresponds to the [BLAS][blas] level 2 function [`cgemv`][cgemv]. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | ||
| var Complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
| var filledarrayBy = require( '@stdlib/array/filled-by' ); | ||
| var logEach = require( '@stdlib/console/log-each' ); | ||
| var cgemv = require( '@stdlib/blas/base/cgemv' ); | ||
|
|
||
| function rand() { | ||
| return new Complex64( discreteUniform( 0, 255 ), discreteUniform( -128, 127 ) ); | ||
| } | ||
|
|
||
| var M = 3; | ||
| var N = 3; | ||
|
|
||
| var A = filledarrayBy( M*N, 'complex64', rand ); | ||
| var x = filledarrayBy( N, 'complex64', rand ); | ||
| var y = filledarrayBy( M, 'complex64', rand ); | ||
|
|
||
| var alpha = new Complex64( 0.5, 0.5 ); | ||
| var beta = new Complex64( 0.5, -0.5 ); | ||
|
|
||
| cgemv( 'column-major', 'no-transpose', M, N, alpha, A, 4, x, 1, beta, y, 1 ); | ||
|
|
||
| // Print the results: | ||
| logEach( '%s', x ); | ||
|
|
||
| cgemv.ndarray( 'no-transpose', M, N, alpha, A, 1, 4, 0, x, 1, 0, beta, y, 1, 0 ); | ||
|
|
||
| // Print the results: | ||
| logEach( '%s', x ); | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- C interface documentation. --> | ||
|
|
||
| * * * | ||
|
|
||
| <section class="c"> | ||
|
|
||
| ## C APIs | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- C usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ### Usage | ||
|
|
||
| ```c | ||
| TODO | ||
| ``` | ||
|
|
||
| #### TODO | ||
|
|
||
| TODO. | ||
|
|
||
| ```c | ||
| TODO | ||
| ``` | ||
|
|
||
| TODO | ||
|
|
||
| ```c | ||
| TODO | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- C API usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ### Examples | ||
|
|
||
| ```c | ||
| TODO | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.c --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| [blas]: http://www.netlib.org/blas | ||
|
|
||
| [cgemv]: https://www.netlib.org/lapack/explore-html/d7/dda/group__gemv_ga44c85a0d7ecd60a6bc8ca27b222d7792.html#ga44c85a0d7ecd60a6bc8ca27b222d7792 | ||
|
|
||
| [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
|
||
| [@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.