Skip to content

Commit

Permalink
refactor: update descriptions, tests, and implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Apr 16, 2024
1 parent e29f733 commit 16c849a
Show file tree
Hide file tree
Showing 27 changed files with 411 additions and 150 deletions.
14 changes: 6 additions & 8 deletions lib/node_modules/@stdlib/blas/base/idamax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# idamax

> Find the index of the first element having maximum absolute value.
> Find the index of the first element having the maximum absolute value.
<section class="usage">

Expand All @@ -32,7 +32,7 @@ var idamax = require( '@stdlib/blas/base/idamax' );

#### idamax( N, x, strideX )

Finds the index of the first element having maximum absolute value.
Finds the index of the first element having the maximum absolute value.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -49,7 +49,7 @@ The function has the following parameters:
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: index increment for `x`.

The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to find index of element having maximum absolute value traversing every other value,
The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to traverse every other value,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -71,16 +71,14 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
// Create an offset view:
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Find index of element having maximum absolute value for every other element...
// Find index of element having the maximum absolute value:
var idx = idamax( 3, x1, 2 );
// returns 2
```

If either `N` is less than `1` or `strideX` is less than or equal to `0`, the function returns `0`.

#### idamax.ndarray( N, x, strideX, offset )

Finds the index of the first element having maximum absolute value using alternative indexing semantics.
Finds the index of the first element having the maximum absolute value using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -95,7 +93,7 @@ The function has the following additional parameters:

- **offsetX**: starting index.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to find the index of the element having the maximum absolute value starting from second index,
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to start from the second index,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down
31 changes: 24 additions & 7 deletions lib/node_modules/@stdlib/blas/base/idamax/benchmark/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ else
fPIC ?= -fPIC
endif

# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
INCLUDE ?=

# List of source files:
c_src := ../../src/idamax.c
SOURCE_FILES ?=

# List of libraries (e.g., `-lopenblas -lpthread`):
LIBRARIES ?=

# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
LIBPATH ?=

# List of C targets:
c_targets := benchmark.length.out
Expand All @@ -79,11 +88,15 @@ c_targets := benchmark.length.out
# RULES #

#/
# Compiles C source files.
# Compiles source files.
#
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
# @param {string} [CFLAGS] - C compiler options
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`)
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
# @param {string} [SOURCE_FILES] - list of source files
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
#
# @example
# make
Expand All @@ -99,12 +112,16 @@ all: $(c_targets)
# Compiles C source files.
#
# @private
# @param {string} CC - C compiler
# @param {string} CFLAGS - C compiler flags
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
# @param {string} CC - C compiler (e.g., `gcc`)
# @param {string} CFLAGS - C compiler options
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
# @param {string} SOURCE_FILES - list of source files
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
#/
$(c_targets): %.out: %.c
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)

#/
# Runs compiled benchmarks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ double rand_double( void ) {
double benchmark( int iterations, int len ) {
double elapsed;
double x[ len ];
double idx;
double t;
int idx;
int i;

for ( i = 0; i < len; i++ ) {
Expand All @@ -111,14 +111,14 @@ double benchmark( int iterations, int len ) {
t = tic();
for ( i = 0; i < iterations; i++ ) {
idx = c_idamax( len, x, 1 );
if ( idx != idx ) {
printf( "should not return NaN\n" );
if ( idx < -2 ) {
printf( "unexpected result\n" );
break;
}
}
elapsed = tic() - t;
if ( idx != idx ) {
printf( "should not return NaN\n" );
if ( idx < -2 ) {
printf( "unexpected result\n" );
}
return elapsed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ end function idamax
integer, intent(in) :: iterations, len
! ..
! Local scalars:
integer :: idx
double precision :: elapsed, r
double precision :: t1, t2
integer :: idx
integer :: i
! ..
! Local arrays:
Expand All @@ -150,16 +150,16 @@ end function idamax
! ..
do i = 1, len
call random_number( r )
x( i ) = ( r*2000.0 ) - 1000.0
x( i ) = ( r*2000.0d0 ) - 1000.0d0
end do
! ..
idx = -1
call cpu_time( t1 )
! ..
idx = 0
do i = 1, iterations
idx = idamax( len, x, 1 )
if ( idx /= idx ) then
print '(A)', 'should not return NaN'
if ( idx < 0 .OR. idx > len ) then
print '(A)', 'unexpected result'
exit
end if
end do
Expand All @@ -168,8 +168,8 @@ end function idamax
! ..
elapsed = t2 - t1
! ..
if ( idx /= idx ) then
print '(A)', 'should not return NaN'
if ( idx < 0 .OR. idx > len ) then
print '(A)', 'unexpected result'
end if
! ..
! Deallocate arrays:
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

{{alias}}( N, x, strideX )
Finds the index of the first element having maximum absolute value.
Finds the index of the first element having the maximum absolute value.

The `N` and `strideX` parameters determine which elements in `x` are
accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use typed
array views.

If `N < 1` or `strideX <= 0`, the function returns `0`.
If `N < 1` or `strideX <= 0`, the function returns `-1`.

Parameters
----------
Expand All @@ -35,18 +35,18 @@

// Using `N` and `strideX` parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0 ] );
> var idx = {{alias}}( 2, x, 2 )
> idx = {{alias}}( 2, x, 2 )
1

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var idx = {{alias}}( 3, x1, 1 )
> idx = {{alias}}( 3, x1, 1 )
2


{{alias}}.ndarray( N, x, strideX, offsetX )
Finds the index of the first element having maximum absolute value using
Finds the index of the first element having the maximum absolute value using
alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
Expand Down Expand Up @@ -81,7 +81,7 @@

// Using an index offset:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
> var idx = {{alias}}.ndarray( 3, x, 2, 1 )
> idx = {{alias}}.ndarray( 3, x, 2, 1 )
2

See Also
Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/blas/base/idamax/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
interface Routine {
/**
* Finds the index of the first element having maximum absolute value.
* Finds the index of the first element having the maximum absolute value.
*
* @param N - number of indexed elements
* @param x - input array
Expand All @@ -41,7 +41,7 @@ interface Routine {
( N: number, x: Float64Array, strideX: number ): number;

/**
* Finds the index of the first element having maximum absolute value using alternative indexing semantics.
* Finds the index of the first element having the maximum absolute value using alternative indexing semantics.
*
* @param N - number of indexed elements
* @param x - input array
Expand All @@ -61,7 +61,7 @@ interface Routine {
}

/**
* Finds the index of the first element having maximum absolute value.
* Finds the index of the first element having the maximum absolute value.
*
* @param N - number of indexed elements
* @param x - input array
Expand All @@ -81,8 +81,8 @@ interface Routine {
*
* var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
*
* var idx = idamax.ndarray( x.length, x, 1, 1 );
* // returns 2
* var idx = idamax.ndarray( x.length, x, 1, 0 );
* // returns 3
*/
declare var idamax: Routine;

Expand Down
33 changes: 25 additions & 8 deletions lib/node_modules/@stdlib/blas/base/idamax/examples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ else
fPIC ?= -fPIC
endif

# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
INCLUDE ?=

# List of source files:
c_src := ../../src/idamax.c
SOURCE_FILES ?=

# List of libraries (e.g., `-lopenblas -lpthread`):
LIBRARIES ?=

# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
LIBPATH ?=

# List of C targets:
c_targets := example.out
Expand All @@ -79,11 +88,15 @@ c_targets := example.out
# RULES #

#/
# Compiles C source files.
# Compiles source files.
#
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
# @param {string} [CFLAGS] - C compiler options
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`)
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
# @param {string} [SOURCE_FILES] - list of source files
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
#
# @example
# make
Expand All @@ -99,15 +112,19 @@ all: $(c_targets)
# Compiles C source files.
#
# @private
# @param {string} CC - C compiler
# @param {string} CFLAGS - C compiler flags
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
# @param {string} CC - C compiler (e.g., `gcc`)
# @param {string} CFLAGS - C compiler options
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
# @param {string} SOURCE_FILES - list of source files
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
#/
$(c_targets): %.out: %.c
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)

#/
# Runs compiled benchmarks.
# Runs compiled examples.
#
# @example
# make run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#endif

/**
* Finds the index of the first element having maximum absolute value.
* Finds the index of the first element having the maximum absolute value.
*/
int c_idamax( const int N, const double *X, const int strideX );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#endif

/**
* Finds the index of the first element having maximum absolute value.
* Finds the index of the first element having the maximum absolute value.
*/
int cblas_idamax( const int N, const double *X, const int strideX );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
#endif

/**
* Finds the index of the first element having maximum absolute value.
* Finds the index of the first element having the maximum absolute value.
*/
void idamaxsub( const int *, const double *, const int *, int * );

Expand Down
Loading

0 comments on commit 16c849a

Please sign in to comment.