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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | 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 20x 20x 20x 20x 20x 20x 20x 20x 78x 16x 16x 78x 78x 78x 20x 20x 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 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 44x 9x 9x 44x 44x 44x 11x 11x 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 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 78x 16x 16x 78x 78x 78x 20x 20x 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 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 39x 8x 8x 39x 39x 39x 10x 10x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 61x 61x 61x 61x 61x 20x 61x 41x 41x 10x 41x 10x 31x 10x 16x 11x 11x 41x 41x 20x 20x 61x 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 isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' );
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
// FUNCTIONS //
/**
* Cumulatively tests whether every element in an indexed array is falsy.
*
* @private
* @param {Collection} x - input array
* @param {Collection} y - output array
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array
*
* @example
* var x = [ false, false, false, true, false ];
* var y = [ false, null, false, null, false, null, false, null, false, null ];
*
* var out = indexed( x, y, 2, 0 );
* // returns [ true, null, true, null, true, null, false, null, false, null ]
*/
function indexed( x, y, stride, offset ) {
var flg;
var io;
var i;
flg = true;
io = offset;
for ( i = 0; i < x.length; i++ ) {
if ( flg === true && x[ i ] ) {
flg = false;
}
y[ io ] = flg;
io += stride;
}
return y;
}
/**
* Cumulatively tests whether every element in a provided accessor array is falsy.
*
* @private
* @param {Object} x - input array object
* @param {Object} y - output array object
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = toAccessorArray( [ false, false, false, true, false ] );
* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] );
*
* var arr = accessors( arraylike2object( x ), arraylike2object( y ), 2, 0 );
*
* var v = y.get( 0 );
* // returns true
*
* v = y.get( 2 );
* // returns true
*
* v = y.get( 4 );
* // returns true
*
* v = y.get( 6 );
* // returns false
*
* v = y.get( 8 );
* // returns false
*/
function accessors( x, y, stride, offset ) {
var xdata;
var ydata;
var xget;
var yset;
var flg;
var io;
var i;
xdata = x.data;
ydata = y.data;
xget = x.accessors[ 0 ];
yset = y.accessors[ 1 ];
flg = true;
io = offset;
for ( i = 0; i < xdata.length; i++ ) {
if ( flg === true && xget( xdata, i ) ) {
flg = false;
}
yset( ydata, io, flg );
io += stride;
}
return ydata;
}
/**
* Cumulatively tests whether every element in a provided complex number array is falsy.
*
* @private
* @param {Collection} x - array containing interleaved real and imaginary components
* @param {Object} y - output array object
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] );
* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, true, null ] );
*
* var arr = complex( x, arraylike2object( y ), 2, 0 );
*
* var v = y.get( 0 );
* // returns true
*
* v = y.get( 2 );
* // returns true
*
* v = y.get( 4 );
* // returns true
*
* v = y.get( 6 );
* // returns false
*
* v = y.get( 8 );
* // returns false
*/
function complex( x, y, stride, offset ) {
var ydata;
var yset;
var flg;
var io;
var i;
yset = y.accessors[ 1 ];
ydata = y.data;
flg = true;
io = offset;
for ( i = 0; i < x.length; i += 2 ) {
if ( flg === true && ( x[ i ] || x[ i+1 ] ) ) {
flg = false;
}
yset( ydata, io, flg );
io += stride;
}
return ydata;
}
/**
* Cumulatively tests whether every element in a provided boolean array is falsy.
*
* @private
* @param {Collection} x - input array
* @param {Object} y - output array object
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array
*
* @example
* var Uint8Array = require( '@stdlib/array/uint8' );
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = new Uint8Array( [ 0, 0, 0, 1, 0 ] );
* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, true, null ] );
*
* var arr = boolean( x, arraylike2object( y ), 2, 0 );
*
* var v = y.get( 0 );
* // returns true
*
* v = y.get( 2 );
* // returns true
*
* v = y.get( 4 );
* // returns true
*
* v = y.get( 6 );
* // returns false
*
* v = y.get( 8 );
* // returns false
*/
function boolean( x, y, stride, offset ) {
var ydata;
var yset;
var flg;
var io;
var i;
yset = y.accessors[ 1 ];
ydata = y.data;
flg = true;
io = offset;
for ( i = 0; i < x.length; i++ ) {
if ( flg === true && x[ i ] ) {
flg = false;
}
yset( ydata, io, flg );
io += stride;
}
return ydata;
}
// MAIN //
/**
* Cumulatively tests whether every element in an array is falsy and assigns results to a provided output array.
*
* @param {Collection} x - input array
* @param {Collection} y - output array
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array offset
* @returns {Collection} output array
*
* @example
* var x = [ false, false, false, true, false ];
* var y = [ false, null, false, null, false, null, false, null, false, null ];
*
* var out = assign( x, y, 2, 0 );
* // returns [ true, null, true, null, true, null, false, null, false, null ]
*
* var bool = ( y === out );
* // returns true
*/
function assign( x, y, stride, offset ) {
var xo = arraylike2object( x );
var yo = arraylike2object( y );
if (
xo.accessorProtocol ||
yo.accessorProtocol
) {
// If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components, where we consider a complex number to be truthy if at least one component is non-zero...
if ( isComplex128Array( x ) ) {
complex( reinterpret128( x, 0 ), yo, stride, offset );
} else if ( isComplex64Array( x ) ) {
complex( reinterpret64( x, 0 ), yo, stride, offset );
} else if ( isBooleanArray( x ) ) {
boolean( reinterpretBoolean( x, 0 ), yo, stride, offset );
} else {
accessors( xo, yo, stride, offset );
}
return y;
}
indexed( x, y, stride, offset );
return y;
}
// EXPORTS //
module.exports = assign;
|