Repository navigation
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
AryanSharma48
left a comment
There was a problem hiding this comment.
@yb175 Left some comments on the initial pass
| * - a two-dimensional input ndarray corresponding to `A`. | ||
| * - a two-dimensional output ndarray corresponding to `B`. | ||
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. | ||
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
There was a problem hiding this comment.
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. | |
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. |
In PR for dtril, changing dtype to 'int32' was only applied to the code examples and tests (scalar2ndarray( 0, { 'dtype': 'int32' } )), not the prose parameter descriptions. Let's revert this back to maintain consistency across the ndarray BLAS packages.
| * | ||
| * - a two-dimensional input ndarray corresponding to `A`. | ||
| * - a two-dimensional output ndarray corresponding to `B`. | ||
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
There was a problem hiding this comment.
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. | |
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. |
| - a two-dimensional output ndarray corresponding to `B`. | ||
| - a zero-dimensional ndarray specifying the diagonal above which to | ||
| ignore. | ||
| - a zero-dimensional int32 ndarray specifying the diagonal above which |
There was a problem hiding this comment.
| - a zero-dimensional int32 ndarray specifying the diagonal above which | |
| - a zero-dimensional ndarray specifying the diagonal above which |
| * - a two-dimensional input ndarray corresponding to `A`. | ||
| * - a two-dimensional output ndarray corresponding to `B`. | ||
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. | ||
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
There was a problem hiding this comment.
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. | |
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. |
| * | ||
| * - a two-dimensional input ndarray corresponding to `A`. | ||
| * - a two-dimensional output ndarray corresponding to `B`. | ||
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
There was a problem hiding this comment.
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. | |
| * - a zero-dimensional ndarray specifying the diagonal above which to ignore. |
| - a two-dimensional input ndarray corresponding to `A`. | ||
| - a two-dimensional output ndarray corresponding to `B`. | ||
| - a zero-dimensional ndarray specifying the diagonal above which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal. | ||
| - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal. |
There was a problem hiding this comment.
| - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal. | |
| - a zero-dimensional ndarray specifying the diagonal above which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal. |
| The function accepts an ordered list of ndarrays: | ||
| - **arrays**: `[in] struct ndarray**` containing `A`, `B`, and `k` in that order. | ||
| - `[in]` two-dimensional complex64 input ndarray `A`. | ||
| - `[out]` two-dimensional complex64 output ndarray `B`. | ||
| - `[in]` zero-dimensional int32 ndarray `k`, the diagonal offset. | ||
| The `k` value must be representable as an int32. A value of zero selects the main diagonal; positive values include diagonals above it, and negative values include diagonals below it. |
There was a problem hiding this comment.
| The function accepts an ordered list of ndarrays: | |
| - **arrays**: `[in] struct ndarray**` containing `A`, `B`, and `k` in that order. | |
| - `[in]` two-dimensional complex64 input ndarray `A`. | |
| - `[out]` two-dimensional complex64 output ndarray `B`. | |
| - `[in]` zero-dimensional int32 ndarray `k`, the diagonal offset. | |
| The `k` value must be representable as an int32. A value of zero selects the main diagonal; positive values include diagonals above it, and negative values include diagonals below it. | |
| The function accepts the following arguments: | |
| - **arrays**: `[in] struct ndarray**` list containing the following ndarrays: | |
| - `[in] struct ndarray*` a two-dimensional input ndarray. | |
| - `[inout] struct ndarray*` a two-dimensional output ndarray. | |
| - `[in] struct ndarray*` a zero-dimensional ndarray specifying the diagonal above which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal. |
There was a problem hiding this comment.
Following dtril:
- Use the canonical intro phrasing "The function accepts the following arguments:".
- Document B as [inout] because elements outside the lower triangular region are left unmodified.
- Include struct ndarray* type annotations on each sub-item.
- Keep the diagonal description inline as in dtril.
| void stdlib_blas_ext_ctril( const struct ndarray *arrays[] ) { | ||
| const struct ndarray *A = arrays[ 0 ]; | ||
| const struct ndarray *B = arrays[ 1 ]; | ||
| const struct ndarray *karr = arrays[ 2 ]; | ||
|
|
||
| const int64_t *shape = stdlib_ndarray_shape( A ); | ||
| const CBLAS_INT M = (CBLAS_INT)shape[ 0 ]; | ||
| const CBLAS_INT N = (CBLAS_INT)shape[ 1 ]; | ||
|
|
||
| const CBLAS_INT strideA1 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 0 ); | ||
| const CBLAS_INT strideA2 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 1 ); | ||
| const CBLAS_INT offsetA = (CBLAS_INT)stdlib_ndarray_offset_elements( A ); | ||
| const CBLAS_INT strideB1 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 0 ); | ||
| const CBLAS_INT strideB2 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 1 ); | ||
| const CBLAS_INT offsetB = (CBLAS_INT)stdlib_ndarray_offset_elements( B ); | ||
|
|
||
| int32_t k; | ||
| if ( stdlib_ndarray_get_int32( karr, NULL, &k ) != 0 ) { | ||
| return; | ||
| } | ||
|
|
||
| const stdlib_complex64_t *dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | ||
| stdlib_complex64_t *dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | ||
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); | ||
| } |
There was a problem hiding this comment.
| void stdlib_blas_ext_ctril( const struct ndarray *arrays[] ) { | |
| const struct ndarray *A = arrays[ 0 ]; | |
| const struct ndarray *B = arrays[ 1 ]; | |
| const struct ndarray *karr = arrays[ 2 ]; | |
| const int64_t *shape = stdlib_ndarray_shape( A ); | |
| const CBLAS_INT M = (CBLAS_INT)shape[ 0 ]; | |
| const CBLAS_INT N = (CBLAS_INT)shape[ 1 ]; | |
| const CBLAS_INT strideA1 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 0 ); | |
| const CBLAS_INT strideA2 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 1 ); | |
| const CBLAS_INT offsetA = (CBLAS_INT)stdlib_ndarray_offset_elements( A ); | |
| const CBLAS_INT strideB1 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 0 ); | |
| const CBLAS_INT strideB2 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 1 ); | |
| const CBLAS_INT offsetB = (CBLAS_INT)stdlib_ndarray_offset_elements( B ); | |
| int32_t k; | |
| if ( stdlib_ndarray_get_int32( karr, NULL, &k ) != 0 ) { | |
| return; | |
| } | |
| const stdlib_complex64_t *dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | |
| stdlib_complex64_t *dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | |
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); | |
| } | |
| void stdlib_blas_ext_ctril( const struct ndarray *arrays[] ) { | |
| const struct ndarray *A = arrays[ 0 ]; | |
| const struct ndarray *B = arrays[ 1 ]; | |
| const struct ndarray *karr = arrays[ 2 ]; | |
| const int64_t *shape = stdlib_ndarray_shape( A ); | |
| const CBLAS_INT M = (CBLAS_INT)shape[ 0 ]; | |
| const CBLAS_INT N = (CBLAS_INT)shape[ 1 ]; | |
| const CBLAS_INT strideA1 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 0 ); | |
| const CBLAS_INT strideA2 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 1 ); | |
| const CBLAS_INT offsetA = (CBLAS_INT)stdlib_ndarray_offset_elements( A ); | |
| const CBLAS_INT strideB1 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 0 ); | |
| const CBLAS_INT strideB2 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 1 ); | |
| const CBLAS_INT offsetB = (CBLAS_INT)stdlib_ndarray_offset_elements( B ); | |
| const stdlib_complex64_t *dataA; | |
| stdlib_complex64_t *dataB; | |
| int32_t k; | |
| if ( stdlib_ndarray_get_int32( karr, NULL, &k ) != 0 ) { | |
| return; | |
| } | |
| dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | |
| dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | |
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, (CBLAS_INT)k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); | |
| } |
There was a problem hiding this comment.
To adhere to C89/C90 standards, let's move all variable declarations to the top of the function before any statements (avoiding declarations after the if check). Also, let's explicitly cast k to (CBLAS_INT)k when calling the strided function.
There was a problem hiding this comment.
Please align benchmark.length.c with the canonical C benchmark pattern in merged PR #15659 . Standard stdlib C benchmarks use the static double benchmark( int iterations, int N ) signature, standard printf( "should not return NaN\n" ) on stdout, and regular TAP summary via print_summary( count, count ) without custom int *passed parameters.
|
Thanks @AryanSharma48 for review , fixed first pass comments ! |
| static double benchmark( int iterations, int len ) { | ||
| enum STDLIB_NDARRAY_INDEX_MODE imode; | ||
| static double benchmark( int iterations, int N ) { | ||
| int n = N; |
There was a problem hiding this comment.
| int n = N; | |
| * @param n number of matrix rows and columns | |
| * @return elapsed time in seconds | |
| */ | |
| static double benchmark( int iterations, int n ) { |
| shape[ 1 ] = n; | ||
| strides[ 0 ] = (int64_t)n * STDLIB_NDARRAY_COMPLEX64_BYTES_PER_ELEMENT; | ||
| strides[ 1 ] = STDLIB_NDARRAY_COMPLEX64_BYTES_PER_ELEMENT; | ||
| kstrides[ 0 ] = STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT; |
There was a problem hiding this comment.
| kstrides[ 0 ] = STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT; | |
| kstrides[ 0 ] = 0; |
| elapsed = benchmark( iter, len ); | ||
| printf( "# c::%s:size=%d\n", NAME, n*n ); | ||
| elapsed = benchmark( iter, n ); | ||
| print_results( iter, elapsed ); |
There was a problem hiding this comment.
Missing TAP ok line.
| print_results( iter, elapsed ); | |
| print_results( iter, elapsed ); | |
| printf( "ok %d benchmark finished\n", count ); |
There was a problem hiding this comment.
| var ctril = require( './../lib/main.js' ); |
| - a zero-dimensional ndarray specifying the diagonal above which to | ||
| ignore. | ||
| - a zero-dimensional ndarray specifying the diagonal above which | ||
| to ignore. |
There was a problem hiding this comment.
Keep the original wrapping.
| to ignore. | |
| - a zero-dimensional ndarray specifying the diagonal above which to | |
| ignore. |
| #include "stdlib/ndarray/index_modes.h" | ||
| #include "stdlib/ndarray/orders.h" | ||
| #include "stdlib/ndarray/base/bytes_per_element.h" | ||
| #include "stdlib/complex/float32/ctor.h" |
There was a problem hiding this comment.
| #include "stdlib/complex/float32/ctor.h" | |
| #include "stdlib/complex/float32/ctor.h" | |
| #include "stdlib/complex/float32/real.h" | |
| #include "stdlib/complex/float32/imag.h" |
| 2 * STDLIB_NDARRAY_COMPLEX64_BYTES_PER_ELEMENT, | ||
| STDLIB_NDARRAY_COMPLEX64_BYTES_PER_ELEMENT | ||
| }; | ||
| int64_t kstrides[] = { STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT }; |
There was a problem hiding this comment.
| int64_t kstrides[] = { STDLIB_NDARRAY_INT32_BYTES_PER_ELEMENT }; | |
| int64_t kstrides[] = { 0 }; |
| for ( int i = 0; i < 4; i++ ) { | ||
| stdlib_complex64_parts_t parts; | ||
| parts.value = dataB[ i ]; | ||
| printf( "dataB[ %i ] = (%f, %f)\n", i, parts.parts[ 0 ], parts.parts[ 1 ] ); |
There was a problem hiding this comment.
Use the accessors.
| printf( "dataB[ %i ] = (%f, %f)\n", i, parts.parts[ 0 ], parts.parts[ 1 ] ); | |
| printf( "dataB[ %i ] = (%f, %f)\n", i, stdlib_complex64_real( dataB[ i ] ), stdlib_complex64_imag( dataB[ i ] ) ); |
| * | ||
| * ## Notes | ||
| * | ||
| * - The function expects the following ndarrays: | ||
| * | ||
| * - a two-dimensional input ndarray corresponding to `A`. | ||
| * - a two-dimensional output ndarray corresponding to `B`. | ||
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
There was a problem hiding this comment.
Headers only keep the one-line description.
| * | |
| * ## Notes | |
| * | |
| * - The function expects the following ndarrays: | |
| * | |
| * - a two-dimensional input ndarray corresponding to `A`. | |
| * - a two-dimensional output ndarray corresponding to `B`. | |
| * - a zero-dimensional int32 ndarray specifying the diagonal above which to ignore. |
| const struct ndarray *A = arrays[ 0 ]; | ||
| const struct ndarray *B = arrays[ 1 ]; | ||
| const struct ndarray *karr = arrays[ 2 ]; | ||
|
|
||
| const int64_t *shape = stdlib_ndarray_shape( A ); | ||
| const CBLAS_INT M = (CBLAS_INT)shape[ 0 ]; | ||
| const CBLAS_INT N = (CBLAS_INT)shape[ 1 ]; | ||
|
|
||
| const CBLAS_INT strideA1 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 0 ); | ||
| const CBLAS_INT strideA2 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 1 ); | ||
| const CBLAS_INT offsetA = (CBLAS_INT)stdlib_ndarray_offset_elements( A ); | ||
| const CBLAS_INT strideB1 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 0 ); | ||
| const CBLAS_INT strideB2 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 1 ); | ||
| const CBLAS_INT offsetB = (CBLAS_INT)stdlib_ndarray_offset_elements( B ); | ||
| const stdlib_complex64_t *dataA; | ||
| stdlib_complex64_t *dataB; | ||
| int32_t k; | ||
| if ( stdlib_ndarray_get_int32( karr, NULL, &k ) != 0 ) { | ||
| return; | ||
| } | ||
|
|
||
| dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | ||
| dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | ||
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, (CBLAS_INT)k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); |
There was a problem hiding this comment.
Merged packages read k directly (e.g. zwxsa), same as ztril.
| const struct ndarray *A = arrays[ 0 ]; | |
| const struct ndarray *B = arrays[ 1 ]; | |
| const struct ndarray *karr = arrays[ 2 ]; | |
| const int64_t *shape = stdlib_ndarray_shape( A ); | |
| const CBLAS_INT M = (CBLAS_INT)shape[ 0 ]; | |
| const CBLAS_INT N = (CBLAS_INT)shape[ 1 ]; | |
| const CBLAS_INT strideA1 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 0 ); | |
| const CBLAS_INT strideA2 = (CBLAS_INT)stdlib_ndarray_stride_elements( A, 1 ); | |
| const CBLAS_INT offsetA = (CBLAS_INT)stdlib_ndarray_offset_elements( A ); | |
| const CBLAS_INT strideB1 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 0 ); | |
| const CBLAS_INT strideB2 = (CBLAS_INT)stdlib_ndarray_stride_elements( B, 1 ); | |
| const CBLAS_INT offsetB = (CBLAS_INT)stdlib_ndarray_offset_elements( B ); | |
| const stdlib_complex64_t *dataA; | |
| stdlib_complex64_t *dataB; | |
| int32_t k; | |
| if ( stdlib_ndarray_get_int32( karr, NULL, &k ) != 0 ) { | |
| return; | |
| } | |
| dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | |
| dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | |
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, (CBLAS_INT)k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); | |
| const struct ndarray *A = arrays[ 0 ]; | |
| const struct ndarray *B = arrays[ 1 ]; | |
| int32_t k; | |
| stdlib_ndarray_get_int32( arrays[ 2 ], NULL, &k ); | |
| const CBLAS_INT M = stdlib_ndarray_dimension( A, 0 ); | |
| const CBLAS_INT N = stdlib_ndarray_dimension( A, 1 ); | |
| const CBLAS_INT strideA1 = stdlib_ndarray_stride_elements( A, 0 ); | |
| const CBLAS_INT strideA2 = stdlib_ndarray_stride_elements( A, 1 ); | |
| const CBLAS_INT offsetA = stdlib_ndarray_offset_elements( A ); | |
| const CBLAS_INT strideB1 = stdlib_ndarray_stride_elements( B, 0 ); | |
| const CBLAS_INT strideB2 = stdlib_ndarray_stride_elements( B, 1 ); | |
| const CBLAS_INT offsetB = stdlib_ndarray_offset_elements( B ); | |
| const stdlib_complex64_t *dataA = (const stdlib_complex64_t *)stdlib_ndarray_data( A ); | |
| stdlib_complex64_t *dataB = (stdlib_complex64_t *)stdlib_ndarray_data( B ); | |
| API_SUFFIX(stdlib_strided_ctril_ndarray)( M, N, k, dataA, strideA1, strideA2, offsetA, dataB, strideB1, strideB2, offsetB ); |
| "@stdlib/ndarray/orders", | ||
| "@stdlib/ndarray/base/bytes-per-element" | ||
| "@stdlib/ndarray/base/bytes-per-element", | ||
| "@stdlib/complex/float32/ctor" |
There was a problem hiding this comment.
| "@stdlib/complex/float32/ctor" | |
| "@stdlib/complex/float32/ctor", | |
| "@stdlib/complex/float32/real", | |
| "@stdlib/complex/float32/imag" |
|
|
||
| ## C APIs | ||
|
|
||
| <section class="intro"> |
There was a problem hiding this comment.
| <section class="intro"> | |
| <!-- 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"> |
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <section class="usage"> |
There was a problem hiding this comment.
| <section class="usage"> | |
| <!-- C usage documentation. --> | |
| <section class="usage"> |
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main( void ) { |
There was a problem hiding this comment.
The usage block should be a short snippet without int main(), like in zwxsa.
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> |
There was a problem hiding this comment.
| <section class="notes"> | |
| <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | |
| <section class="notes"> |
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> |
There was a problem hiding this comment.
| <section class="examples"> | |
| <!-- C API usage examples. --> | |
| <section class="examples"> |
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main( void ) { |
There was a problem hiding this comment.
This should match examples/c/example.c exactly (comments and blank lines are missing).
|
@yb175 Left a few suggestions, PTAL ; |
|
@ujjwalv01 done the requested changes , please have a look ! |
Resolves part of #14819.
Description
This pull request:
blas/ext/base/ndarray/ctril.int32ndarray for the diagonal offsetk.Related Issues
This pull request has the following related issues:
blas/ext/base/ndarraypackages #14819Questions
No.
Other
The
int32scalar approach follows the discussion in #14471 .Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
AI assistance was used to update tests and benchmarks, and prepare documentation.
@stdlib-js/reviewers