-
-
Notifications
You must be signed in to change notification settings - Fork 813
feat: add C implementation for lapack/base/dlacpy
#5210
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
base: develop
Are you sure you want to change the base?
Changes from all commits
8c6f4c5
888933c
eaacff9
b84901f
8d24b7d
39dfc37
b3261cf
6e01521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -188,21 +188,68 @@ console.log( ndarray2array( B, shape, strides, 0, order ) ); | |||||
### Usage | ||||||
|
||||||
```c | ||||||
TODO | ||||||
#include "stdlib/lapack/base/dlacpy.h" | ||||||
``` | ||||||
|
||||||
#### TODO | ||||||
#### c_dlacpy( order, uplo, M, N, \*A, LDA, \*B, LDB ) | ||||||
|
||||||
TODO. | ||||||
Copies all or part of a matrix `A` to another matrix `B`. | ||||||
|
||||||
```c | ||||||
TODO | ||||||
#include "stdlib/blas/base/shared.h" | ||||||
|
||||||
double A[] = { 1.0, 2.0, 3.0, 4.0 }; | ||||||
double B[] = { 0.0, 0.0, 0.0, 0.0 }; | ||||||
|
||||||
c_dlacpy( CblasColMajor, CblasUpper, 2, 2, A, 2, B, 2 ); | ||||||
``` | ||||||
|
||||||
TODO | ||||||
The function accepts the following arguments: | ||||||
|
||||||
- **order**: `[in] CBLAS_LAYOUT` storage layout of `A` and `B` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these descriptions are missing ending periods. |
||||||
- **uplo**: `[in] CBLAS_UPLO` specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` | ||||||
- **M**: `[in] CBLAS_INT` number of rows in matrix `A` | ||||||
- **N**: `[in] CBLAS_INT` number of columns in matrix `A` | ||||||
- **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`) | ||||||
- **B**: `[in] double*` output matrix | ||||||
- **LDB**: `[in] CBLAS_INT` stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`) | ||||||
|
||||||
```c | ||||||
TODO | ||||||
void c_dlacpy( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT M, const CBLAS_INT N, double *A, const CBLAS_INT LDA, double *B, const CBLAS_INT LDB ) | ||||||
``` | ||||||
|
||||||
<!--lint disable maximum-heading-length--> | ||||||
|
||||||
#### c_dlacpy_ndarray( uplo, M, N, \*A, strideA1, strideA2, offsetA, \*B, strideB1, strideB2, offsetB ) | ||||||
|
||||||
Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics. | ||||||
|
||||||
```c | ||||||
#include "stdlib/blas/base/shared.h" | ||||||
|
||||||
double A[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do these arrays have an odd number of elements? |
||||||
double B[] = { 0.0, 0.0, 0.0, 0.0, 0.0 }; | ||||||
|
||||||
c_dlacpy_ndarray( CblasUpper, 2, 2, A, 2, 1, 1, B, 2, 1, 2 ); | ||||||
``` | ||||||
|
||||||
The function accepts the following arguments: | ||||||
|
||||||
- **uplo**: `[in] CBLAS_UPLO` specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Periods. |
||||||
- **M**: `[in] CBLAS_INT` number of rows in matrix `A` | ||||||
- **N**: `[in] CBLAS_INT` number of columns in matrix `A` | ||||||
- **A**: `[in] double*` input matrix | ||||||
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A` | ||||||
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A` | ||||||
- **offsetB**: `[in] CBLAS_INT` starting index for `A` | ||||||
- **B**: `[in] double*` output matrix | ||||||
- **strideB1**: `[in] CBLAS_INT` stride of the first dimension of `B` | ||||||
- **strideB2**: `[in] CBLAS_INT` stride of the second dimension of `B` | ||||||
- **offsetB**: `[in] CBLAS_INT` starting index for `B` | ||||||
|
||||||
```c | ||||||
void c_dlacpy_ndarray( const CBLAS_UPLO uplo, const CBLAS_INT M, const CBLAS_INT N, double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, double *B, const CBLAS_INT strideB1, const CBLAS_INT strideB2, const CBLAS_INT offsetB ) | ||||||
``` | ||||||
|
||||||
</section> | ||||||
|
@@ -224,7 +271,35 @@ TODO | |||||
### Examples | ||||||
|
||||||
```c | ||||||
TODO | ||||||
#include "stdlib/lapack/base/dlacpy.h" | ||||||
#include "stdlib/blas/base/shared.h" | ||||||
|
||||||
int main( void ) { | ||||||
// Create strided arrays: | ||||||
const double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 }; | ||||||
double B[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; | ||||||
|
||||||
// Specify the number of elements along each dimension of `A`: | ||||||
const int N = 3; | ||||||
|
||||||
// Copies all or part of a matrix `A` to another matrix `B`: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
c_dlacpy( CblasColMajor, CblasUpper, N, N, A, N, B, N ); | ||||||
|
||||||
// Print the result: | ||||||
for ( int i = 0; i < N*N; i++ ) { | ||||||
printf( "B[ %i ] = %f\n", i, B[ i ] ); | ||||||
} | ||||||
|
||||||
// Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
c_dlacpy_ndarray( CblasLower, N, N, A, 1, N, 0, B, 1, N, 0 ); | ||||||
|
||||||
// Print the result: | ||||||
for ( int i = 0; i < N*N; i++ ) { | ||||||
printf( "B[ %i ] = %f\n", i, B[ i ] ); | ||||||
} | ||||||
|
||||||
return 0; | ||||||
Comment on lines
+300
to
+301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This isn't needed. |
||||||
} | ||||||
``` | ||||||
|
||||||
</section> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* @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 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 tryRequire = require( '@stdlib/utils/try-require' ); | ||
var pkg = require( './../package.json' ).name; | ||
|
||
|
||
// VARIABLES // | ||
|
||
var dlacpy = tryRequire( resolve( __dirname, './../lib/dlacpy.native.js' ) ); | ||
var opts = { | ||
'skip': ( dlacpy instanceof Error ) | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} N - number of elements along each dimension | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( N ) { | ||
var options; | ||
var A; | ||
var B; | ||
|
||
options = { | ||
'dtype': 'float64' | ||
}; | ||
|
||
A = uniform( N*N, -10.0, 10.0, options ); | ||
B = uniform( N*N, -10.0, 10.0, options ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = dlacpy( 'column-major', 'all', N, N, A, N, B, N ); | ||
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( pkg+':native::order=column-major,size='+(N*N), opts, f ); | ||
} | ||
} | ||
|
||
main(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* @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 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 tryRequire = require( '@stdlib/utils/try-require' ); | ||
var pkg = require( '@stdlib/lapack/base/dlacpy/package.json' ).name; | ||
|
||
|
||
// VARIABLES // | ||
|
||
var dlacpy = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); | ||
var opts = { | ||
'skip': ( dlacpy instanceof Error ) | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} N - number of elements along each dimension | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( N ) { | ||
var options; | ||
var A; | ||
var B; | ||
|
||
options = { | ||
'dtype': 'float64' | ||
}; | ||
|
||
A = uniform( N*N, -10.0, 10.0, options ); | ||
B = uniform( N*N, -10.0, 10.0, options ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = dlacpy( 'all', N, N, A, 1, N, 0, B, 1, N, 0 ); | ||
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( pkg+'::native:ndarray:order=column-major,size='+(N*N), opts, f ); | ||
} | ||
} | ||
|
||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This array is not mutated. Applies here and below.