All files numel.js

100% Statements 105/105
100% Branches 4/4
100% Functions 1/1
100% Lines 105/105

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 1063x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 103x 103x 9x 9x 94x 103x 3x 3x 3x 3x 3x  
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 ceil = require( '@stdlib/math/base/special/ceil' );
 
 
// MAIN //
 
/**
* Computes the number of indexed elements in a strided array.
*
* @private
* @param {NonNegativeInteger} len - array length
* @param {integer} stride - array stride
* @param {NonNegativeInteger} offset - array offset
* @returns {NonNegativeInteger} number of indexed elements
*
* @example
* var N = numel( 10, -2, 9 );
* // returns 5
*
* N = numel( 10, -2, 8 );
* // returns 5
*
* N = numel( 10, -2, 7 );
* // returns 4
*
* N = numel( 10, -2, 6 );
* // returns 4
*
* N = numel( 10, -2, 5 );
* // returns 3
*
* @example
* var N = numel( 10, -3, 9 );
* // returns 4
*
* N = numel( 10, -3, 8 );
* // returns 3
*
* N = numel( 10, -3, 7 );
* // returns 3
*
* N = numel( 10, -3, 6 );
* // returns 3
*
* N = numel( 10, -3, 5 );
* // returns 2
*
* @example
* var N = numel( 10, 2, 0 );
* // returns 5
*
* N = numel( 10, 2, 1 );
* // returns 5
*
* N = numel( 10, 2, 2 );
* // returns 4
*
* N = numel( 10, 2, 3 );
* // returns 4
*
* @example
* var N = numel( 10, 3, 0 );
* // returns 4
*
* N = numel( 10, 3, 1 );
* // returns 3
*
* N = numel( 10, 3, 2 );
* // returns 3
*
* N = numel( 10, 3, 3 );
* // returns 3
*/
function numel( len, stride, offset ) {
	if ( stride < 0 ) {
		return ceil( (offset+1) / -stride );
	}
	return ceil( (len-offset) / stride );
}
 
 
// EXPORTS //
 
module.exports = numel;