Skip to content
 
 

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

sgemm

NPM version Build Status Coverage Status

Perform the matrix-matrix operation C = alpha*op(A)*op(B) + beta*C.

Usage

import sgemm from 'https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-ndarray-sgemm@deno/mod.js';

sgemm( arrays )

Performs the matrix-matrix operation C = alpha*op(A)*op(B) + beta*C, where op(X) is either op(X) = X or op(X) = X^T, alpha and beta are scalars, A, B, and C are matrices, with op(A) an M by K matrix, op(B) a K by N matrix, and C an M by N matrix.

import Float32Matrix from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-matrix-float32@deno/mod.js';
import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-scalar@deno/mod.js';
import resolveEnum from 'https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-transpose-operation-resolve-enum@deno/mod.js';

var A = new Float32Matrix( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
var B = new Float32Matrix( [ [ 1.0, 1.0 ], [ 0.0, 1.0 ] ] );
var C = new Float32Matrix( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );

var transA = scalar2ndarray( resolveEnum( 'no-transpose' ), {
    'dtype': 'int32'
});
var transB = scalar2ndarray( resolveEnum( 'no-transpose' ), {
    'dtype': 'int32'
});
var alpha = scalar2ndarray( 1.0, {
    'dtype': 'float32'
});
var beta = scalar2ndarray( 1.0, {
    'dtype': 'float32'
});

var out = sgemm( [ A, B, C, transA, transB, alpha, beta ] );
// returns <ndarray>[ [ 2.0, 5.0 ], [ 6.0, 11.0 ] ]

var bool = ( out === C );
// returns true

The function has the following parameters:

  • arrays: array-like object containing the following ndarrays:

    • a two-dimensional input ndarray corresponding to A.
    • a two-dimensional input ndarray corresponding to B.
    • a two-dimensional input/output ndarray corresponding to C.
    • a zero-dimensional ndarray specifying whether A should be transposed, conjugate-transposed, or not transposed.
    • a zero-dimensional ndarray specifying whether B should be transposed, conjugate-transposed, or not transposed.
    • a zero-dimensional ndarray containing a scalar constant corresponding to alpha.
    • a zero-dimensional ndarray containing a scalar constant corresponding to beta.

Examples

import discreteUniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-discrete-uniform@deno/mod.js';
import scalar2ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-from-scalar@deno/mod.js';
import resolveEnum from 'https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-transpose-operation-resolve-enum@deno/mod.js';
import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@deno/mod.js';
import sgemm from 'https://cdn.jsdelivr.net/gh/stdlib-js/blas-base-ndarray-sgemm@deno/mod.js';

var opts = {
    'dtype': 'float32'
};

var A = discreteUniform( [ 3, 4 ], 0, 10, opts );
var B = discreteUniform( [ 4, 2 ], 0, 10, opts );
var C = discreteUniform( [ 3, 2 ], 0, 10, opts );

var transA = scalar2ndarray( resolveEnum( 'no-transpose' ), {
    'dtype': 'int32'
});
var transB = scalar2ndarray( resolveEnum( 'no-transpose' ), {
    'dtype': 'int32'
});
var alpha = scalar2ndarray( 1.0, opts );
var beta = scalar2ndarray( 1.0, opts );

var out = sgemm( [ A, B, C, transA, transB, alpha, beta ] );
console.log( ndarray2array( out ) );

Notice

This package is part of stdlib, a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.

Releases

Packages

Contributors

Languages