Skip to content

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

0PrashantYadav0
Copy link
Contributor

Resolves None.

Description

What is the purpose of this pull request?

This pull request:

  • add c implementation for dlacpy

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves None.

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.


@stdlib-js/reviewers

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@stdlib-bot stdlib-bot added LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Review A pull request which needs code review. labels Feb 13, 2025
@0PrashantYadav0
Copy link
Contributor Author

/stdlib update-copyright-years

@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 13, 2025

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dlacpy $\color{green}950/950$
$\color{green}+100.00\%$
$\color{green}47/47$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}950/950$
$\color{green}+100.00\%$

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

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Feb 13, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Feb 13, 2025
@0PrashantYadav0 0PrashantYadav0 marked this pull request as draft February 13, 2025 11:25
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Feb 13, 2025
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
…ectories

---
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
    status: na
  - task: lint_package_json
    status: passed
  - 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: na
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
…unctions

---
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
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: failed
---
---
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
    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: na
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@0PrashantYadav0 0PrashantYadav0 marked this pull request as ready for review February 13, 2025 14:45
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Feb 13, 2025
@0PrashantYadav0 0PrashantYadav0 changed the title feat: added C implementation for lapack/base/dlacpy feat: add C implementation for lapack/base/dlacpy Feb 13, 2025
@0PrashantYadav0
Copy link
Contributor Author

@kgryte Please review this pr if possible. thank you.

@kgryte kgryte self-requested a review March 15, 2025 02:10
Signed-off-by: Athan <kgryte@gmail.com>
* @param strideB2 stride of the second dimension of `B`
* @param offsetB starting index for `B`
*/
void API_SUFFIX(c_copy_all)( const CBLAS_INT M, const CBLAS_INT N, const 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 ) {
Copy link
Member

Choose a reason for hiding this comment

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

These should be private functions. Right now, you are exposing them outside the translation unit. That is not desired.

* @param strideB2 stride of the second dimension of `B`
* @param offsetB starting index for `B`
*/
void API_SUFFIX(c_copy_upper)( const CBLAS_INT M, const CBLAS_INT N, const 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 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Make static.

* @param strideB2 stride of the second dimension of `B`
* @param offsetB starting index for `B`
*/
void API_SUFFIX(c_copy_lower)( const CBLAS_INT M, const CBLAS_INT N, const 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 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Make static.

}

for ( i1 = 0; i1 < N; i1++ ) {
for ( i0 = 0; i0 <= stdlib_base_fast_min( i1, M-1 ); i0++ ) {
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't be using fast_min. That is for doubles. Instead, either define an internal function or a macro for returning the min of two integers.

ib = offsetB;
if ( stdlib_ndarray_is_row_major( 2, strides ) ) {
for ( i1 = 0; i1 < M; i1++ ) {
for ( i0 = 0; i0 <= stdlib_base_fast_min( i1, N-1 ); i0++ ) {
Copy link
Member

Choose a reason for hiding this comment

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

Same thing.

#include "stdlib/lapack/base/dlacpy.h"
#include "stdlib/blas/base/shared.h"
#include "stdlib/strided/base/stride2offset.h"
#include "stdlib/math/base/special/fast/min.h"
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't be using this API.

sb2 = LDB;
} else { // order === 'row-major'
if ( LDA < N ) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. You should be using xerbla. The JS implementation raises exceptions. That follows BLAS/LAPACK. We should do the same here.

Copy link
Member

Choose a reason for hiding this comment

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

See CBLAS.

/**
* Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics.
*
* @private
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @private

Why is this annotation here?

* @param M number of rows in matrix `A`
* @param N number of columns in matrix `A`
* @param A input matrix
* @param strideA1 stride of the first dimension of `A`
Copy link
Member

Choose a reason for hiding this comment

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

Prefer at least two spaces between a parameter and its description. Will require re-aligning all descriptions.

*/
void API_SUFFIX(c_dlacpy_ndarray)( const CBLAS_UPLO uplo, const CBLAS_INT M, const CBLAS_INT N, const 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 ) {
if ( uplo == CblasUpper ) {
c_copy_upper( M, N, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB );
Copy link
Member

Choose a reason for hiding this comment

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

If you are wrapping c_copy_upper in API_SUFFIX, you need to do the same here. Applies below, as well.

STDLIB_NAPI_ARGV_INT64( env, LDA, argv, 5 );
STDLIB_NAPI_ARGV_INT64( env, LDB, argv, 7 );

STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, A, M*N, 1, argv, 4 );
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. You need to be using argv_strided_float64array2d. Applies here and below.

STDLIB_NAPI_ARGV_INT64( env, strideB2, argv, 9 );
STDLIB_NAPI_ARGV_INT64( env, offsetB, argv, 10 );

STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, A, M*N, 1, argv, 3 );
Copy link
Member

Choose a reason for hiding this comment

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

Same comments.

// 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`:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copies all or part of a matrix `A` to another matrix `B`:
// Copy the upper triangular part of a matrix `A` to another matrix `B`:

printf( "B[ %i ] = %f\n", i, B[ i ] );
}

// Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics:
// Copy the lower triangular part of a matrix `A` to another matrix `B` using alternative indexing semantics:

TODO
The function accepts the following arguments:

- **order**: `[in] CBLAS_LAYOUT` storage layout of `A` and `B`
Copy link
Member

Choose a reason for hiding this comment

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

All these descriptions are missing ending periods.

TODO
#include "stdlib/blas/base/shared.h"

double A[] = { 1.0, 2.0, 3.0, 4.0 };
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
double A[] = { 1.0, 2.0, 3.0, 4.0 };
const double A[] = { 1.0, 2.0, 3.0, 4.0 };

This array is not mutated. Applies here and below.

```c
#include "stdlib/blas/base/shared.h"

double A[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
Copy link
Member

Choose a reason for hiding this comment

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

Why do these arrays have an odd number of elements?


The function accepts the following arguments:

- **uplo**: `[in] CBLAS_UPLO` specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A`
Copy link
Member

Choose a reason for hiding this comment

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

Periods.

Comment on lines +300 to +301

return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return 0;

This isn't needed.

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left initial comments. As a general comment, you need to pay more attention to detail when submitting PRs. At this point, you've made over 130 PRs to the project, and I'd expect a higher level of quality.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. C Issue involves or relates to C. Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Mar 15, 2025
@0PrashantYadav0
Copy link
Contributor Author

@kgryte Thank you for your review. I will make sure to pay more attention to details as well as improve the quality of pr even more. As i open this pr way back it have some issues i will resolve them soon.

@kgryte
Copy link
Member

kgryte commented Apr 30, 2025

@0PrashantYadav0 Are you planning on updating this PR or should we close this out?

@0PrashantYadav0
Copy link
Contributor Author

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Apr 30, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Issue involves or relates to C. Feature Issue or pull request for adding a new feature. LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants