|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# dindexOfLessThanEqual |
| 22 | + |
| 23 | +> Return the first index of an element in a one-dimensional double-precision floating-point ndarray which is less than or equal to a specified search element. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var dindexOfLessThanEqual = require( '@stdlib/blas/ext/base/ndarray/dindex-of-less-than-equal' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### dindexOfLessThanEqual( arrays ) |
| 40 | + |
| 41 | +Returns the first index of an element in a one-dimensional double-precision floating-point ndarray which is less than or equal to a specified search element. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); |
| 45 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 46 | + |
| 47 | +var x = new Float64Vector( [ 3.0, 4.0, 1.0, 2.0 ] ); |
| 48 | + |
| 49 | +var searchElement = scalar2ndarray( 2.0, { |
| 50 | + 'dtype': 'float64' |
| 51 | +}); |
| 52 | + |
| 53 | +var fromIndex = scalar2ndarray( 0, { |
| 54 | + 'dtype': 'generic' |
| 55 | +}); |
| 56 | + |
| 57 | +var idx = dindexOfLessThanEqual( [ x, searchElement, fromIndex ] ); |
| 58 | +// returns 2 |
| 59 | +``` |
| 60 | + |
| 61 | +The function has the following parameters: |
| 62 | + |
| 63 | +- **arrays**: array-like object containing the following ndarrays: |
| 64 | + |
| 65 | + - a one-dimensional input ndarray. |
| 66 | + - a zero-dimensional ndarray containing the search element. |
| 67 | + - a zero-dimensional ndarray containing the index from which to begin searching. |
| 68 | + |
| 69 | +If the function is unable to find an element which is less than or equal to a specified search element, the function returns `-1`. |
| 70 | + |
| 71 | +```javascript |
| 72 | +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); |
| 73 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 74 | + |
| 75 | +var x = new Float64Vector( [ 3.0, 4.0, 5.0, 6.0 ] ); |
| 76 | + |
| 77 | +var searchElement = scalar2ndarray( 2.0, { |
| 78 | + 'dtype': 'float64' |
| 79 | +}); |
| 80 | + |
| 81 | +var fromIndex = scalar2ndarray( 0, { |
| 82 | + 'dtype': 'generic' |
| 83 | +}); |
| 84 | + |
| 85 | +var idx = dindexOfLessThanEqual( [ x, searchElement, fromIndex ] ); |
| 86 | +// returns -1 |
| 87 | +``` |
| 88 | + |
| 89 | +</section> |
| 90 | + |
| 91 | +<!-- /.usage --> |
| 92 | + |
| 93 | +<section class="notes"> |
| 94 | + |
| 95 | +## Notes |
| 96 | + |
| 97 | +- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element). |
| 98 | +- When comparing elements, the function uses the less-than-or-equal operator `<=`. As a consequence, comparisons involving `NaN` always evaluate to `false`, and `-0` and `+0` are considered the same. |
| 99 | + |
| 100 | +</section> |
| 101 | + |
| 102 | +<!-- /.notes --> |
| 103 | + |
| 104 | +<section class="examples"> |
| 105 | + |
| 106 | +## Examples |
| 107 | + |
| 108 | +<!-- eslint no-undef: "error" --> |
| 109 | + |
| 110 | +```javascript |
| 111 | +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); |
| 112 | +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); |
| 113 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 114 | +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); |
| 115 | +var dindexOfLessThanEqual = require( '@stdlib/blas/ext/base/ndarray/dindex-of-less-than-equal' ); |
| 116 | + |
| 117 | +var opts = { |
| 118 | + 'dtype': 'float64' |
| 119 | +}; |
| 120 | + |
| 121 | +var x = discreteUniform( [ 10 ], 0, 10, opts ); |
| 122 | +console.log( ndarray2array( x ) ); |
| 123 | + |
| 124 | +var searchElement = scalar2ndarray( 2, opts ); |
| 125 | +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); |
| 126 | + |
| 127 | +var fromIndex = scalar2ndarray( 0, { |
| 128 | + 'dtype': 'generic' |
| 129 | +}); |
| 130 | +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); |
| 131 | + |
| 132 | +var idx = dindexOfLessThanEqual( [ x, searchElement, fromIndex ] ); |
| 133 | +console.log( idx ); |
| 134 | +``` |
| 135 | + |
| 136 | +</section> |
| 137 | + |
| 138 | +<!-- /.examples --> |
| 139 | + |
| 140 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 141 | + |
| 142 | +<section class="related"> |
| 143 | + |
| 144 | +</section> |
| 145 | + |
| 146 | +<!-- /.related --> |
| 147 | + |
| 148 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 149 | + |
| 150 | +<section class="links"> |
| 151 | + |
| 152 | +</section> |
| 153 | + |
| 154 | +<!-- /.links --> |
0 commit comments