Skip to content

Commit 2032173

Browse files
committed
chore: cleanup
--- 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: 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: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c15c12d commit 2032173

3 files changed

Lines changed: 54 additions & 55 deletions

File tree

lib/node_modules/@stdlib/stats/base/ndarray/dmaxsorted/README.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ console.log( v );
104104

105105
## C APIs
106106

107-
<section class="intro">
107+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
108108

109-
Computes the maximum value of a sorted one-dimensional double-precision floating-point ndarray.
109+
<section class="intro">
110110

111111
</section>
112112

113113
<!-- /.intro -->
114114

115+
<!-- C usage documentation. -->
116+
115117
<section class="usage">
116118

117119
### Usage
@@ -125,7 +127,6 @@ Computes the maximum value of a sorted one-dimensional double-precision floating
125127
Computes the maximum value of a sorted one-dimensional double-precision floating-point ndarray.
126128

127129
```c
128-
#include "stdlib/stats/base/ndarray/dmaxsorted.h"
129130
#include "stdlib/ndarray/ctor.h"
130131
#include "stdlib/ndarray/dtypes.h"
131132
#include "stdlib/ndarray/index_modes.h"
@@ -141,7 +142,7 @@ int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
141142

142143
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
143144

144-
// Compute the maximum:
145+
// Compute the maximum value:
145146
const struct ndarray *arrays[] = { x };
146147
double v = stdlib_stats_dmaxsorted( arrays );
147148
// returns 4.0
@@ -188,49 +189,49 @@ double stdlib_stats_dmaxsorted( const struct ndarray *arrays[] );
188189
#include <stdio.h>
189190

190191
int main( void ) {
191-
// Create a sorted data buffer:
192-
const double data[] = { -4.0, -2.0, 1.0, 3.0, 5.0, 7.0 };
192+
// Create a sorted data buffer:
193+
const double data[] = { -4.0, -2.0, 1.0, 3.0, 5.0, 7.0 };
193194

194-
// Specify the number of array dimensions:
195-
const int64_t ndims = 1;
195+
// Specify the number of array dimensions:
196+
const int64_t ndims = 1;
196197

197-
// Specify the array shape:
198-
int64_t shape[] = { 4 };
198+
// Specify the array shape:
199+
int64_t shape[] = { 4 };
199200

200-
// Specify the array strides:
201-
int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
201+
// Specify the array strides:
202+
int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
202203

203-
// Specify the byte offset:
204-
const int64_t offset = 0;
204+
// Specify the byte offset:
205+
const int64_t offset = 0;
205206

206-
// Specify the array order:
207-
const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
207+
// Specify the array order:
208+
const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
208209

209-
// Specify the index mode:
210-
const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
210+
// Specify the index mode:
211+
const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
211212

212-
// Specify the subscript index modes:
213-
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
214-
const int64_t nsubmodes = 1;
213+
// Specify the subscript index modes:
214+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
215+
const int64_t nsubmodes = 1;
215216

216-
// Create an ndarray:
217-
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
218-
if ( x == NULL ) {
217+
// Create an ndarray:
218+
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
219+
if ( x == NULL ) {
219220
fprintf( stderr, "Error allocating memory.\n" );
220221
exit( 1 );
221-
}
222+
}
222223

223-
// Define a list of ndarrays:
224-
const struct ndarray *arrays[] = { x };
224+
// Define a list of ndarrays:
225+
const struct ndarray *arrays[] = { x };
225226

226-
// Compute the maximum:
227-
double v = stdlib_stats_dmaxsorted( arrays );
227+
// Compute the maximum value:
228+
double v = stdlib_stats_dmaxsorted( arrays );
228229

229-
// Print the result:
230-
printf( "max: %lf\n", v );
230+
// Print the result:
231+
printf( "max: %lf\n", v );
231232

232-
// Free allocated memory:
233-
stdlib_ndarray_free( x );
233+
// Free allocated memory:
234+
stdlib_ndarray_free( x );
234235
}
235236
```
236237

lib/node_modules/@stdlib/stats/base/ndarray/dmaxsorted/benchmark/c/benchmark.length.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void print_version( void ) {
5050
*/
5151
static void print_summary( int total, int passing ) {
5252
printf( "#\n" );
53-
printf( "1..%d\n", total );
53+
printf( "1..%d\n", total ); // TAP plan
5454
printf( "# total %d\n", total );
5555
printf( "# pass %d\n", passing );
5656
printf( "#\n" );
@@ -94,19 +94,19 @@ static double rand_double( void ) {
9494
}
9595

9696
/**
97-
* Runs benchmark.
97+
* Runs a benchmark.
9898
*
9999
* @param iterations number of iterations
100100
* @param len array length
101101
* @return elapsed time in seconds
102102
*/
103103
static double benchmark( int iterations, int len ) {
104104
enum STDLIB_NDARRAY_INDEX_MODE imode;
105-
const struct ndarray *arrays[1];
105+
const struct ndarray *arrays[ 1 ];
106106
enum STDLIB_NDARRAY_ORDER order;
107-
int8_t submodes[1];
108-
int64_t strides[1];
109-
int64_t shape[1];
107+
int8_t submodes[ 1 ];
108+
int64_t strides[ 1 ];
109+
int64_t shape[ 1 ];
110110
int64_t nsubmodes;
111111
struct ndarray *x;
112112
int64_t offset;
@@ -118,19 +118,17 @@ static double benchmark( int iterations, int len ) {
118118
int i;
119119

120120
ndims = 1;
121-
shape[0] = len;
122-
strides[0] = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
121+
shape[ 0 ] = len;
122+
strides[ 0 ] = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
123123
offset = 0;
124124
order = STDLIB_NDARRAY_ROW_MAJOR;
125125
imode = STDLIB_NDARRAY_INDEX_ERROR;
126-
submodes[0] = imode;
126+
submodes[ 0 ] = imode;
127127
nsubmodes = 1;
128128

129-
data = (double *) malloc( len * sizeof(double) );
130-
double start = -( (double)len / 2.0 );
131-
double step = 1.0;
129+
data = (double *) malloc( len * sizeof( double ) );
132130
for ( i = 0; i < len; i++ ) {
133-
data[i] = start + ( step * i );
131+
data[ i ] = (double)i;
134132
}
135133
// cppcheck-suppress invalidPointerCast
136134
x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
@@ -156,23 +154,25 @@ static double benchmark( int iterations, int len ) {
156154
return elapsed;
157155
}
158156

159-
160157
/**
161158
* Main execution sequence.
162159
*/
163160
int main( void ) {
164161
double elapsed;
165-
int count = 0;
162+
int count;
166163
int iter;
167164
int len;
168-
int i, j;
165+
int i;
166+
int j;
169167

170-
print_version();
168+
// Use the current time to seed the random number generator:
169+
srand( time( NULL ) );
171170

171+
print_version();
172+
count = 0;
172173
for ( i = MIN; i <= MAX; i++ ) {
173174
len = pow( 10, i );
174175
iter = ITERATIONS / pow( 10, i-1 );
175-
176176
for ( j = 0; j < REPEATS; j++ ) {
177177
count += 1;
178178
printf( "# c::%s:len=%d\n", NAME, len );
@@ -181,7 +181,5 @@ int main( void ) {
181181
printf( "ok %d benchmark finished\n", count );
182182
}
183183
}
184-
185184
print_summary( count, count );
186-
return 0;
187185
}

lib/node_modules/@stdlib/stats/base/ndarray/dmaxsorted/examples/c/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stdio.h>
2828

2929
int main( void ) {
30-
// Create a sorted data buffer (ascending):
30+
// Create a sorted data buffer:
3131
const double data[] = { -8.0, -6.0, -4.0, -2.0, 1.0, 3.0, 5.0, 7.0 };
3232

3333
// Specify the number of array dimensions:
@@ -63,7 +63,7 @@ int main( void ) {
6363
// Define a list of ndarrays:
6464
const struct ndarray *arrays[] = { x };
6565

66-
// Compute the maximum value (sorted input):
66+
// Compute the maximum value:
6767
double v = stdlib_stats_dmaxsorted( arrays );
6868

6969
// Print the result:

0 commit comments

Comments
 (0)