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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 84x 84x 84x 84x 84x 1x 1x 1x 84x 9x 9x 84x 9x 9x 65x 84x 124x 124x 124x 124x 121x 124x 6x 6x 118x 118x 59x 84x 84x 48x 84x 14x 14x 45x 45x 84x 9x 9x 84x 11x 11x 25x 25x 25x 84x 21x 9x 9x 12x 12x 12x 11x 11x 12x 21x 5x 5x 5x 5x 5x 5x 5x 5x 84x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*/
/* eslint-disable no-restricted-syntax, no-invalid-this */
'use strict';
// MODULES //
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives;
var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' );
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var isFunction = require( '@stdlib/assert/is-function' );
var isComplexLike = require( '@stdlib/assert/is-complex-like' );
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var isObject = require( '@stdlib/assert/is-object' );
var isCollection = require( '@stdlib/assert/is-collection' );
var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' );
var isOutputDataTypePolicy = require( '@stdlib/ndarray/base/assert/is-output-data-type-policy' );
var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' );
var isOrder = require( '@stdlib/ndarray/base/assert/is-order' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var contains = require( '@stdlib/array/base/assert/contains' );
var filledBy = require( '@stdlib/array/base/filled-by' );
var everyBy = require( '@stdlib/array/base/every-by' );
var join = require( '@stdlib/array/base/join' );
var copy = require( '@stdlib/array/base/copy' );
var nullaryStrided = require( '@stdlib/strided/base/nullary' );
var binary = require( '@stdlib/ndarray/base/binary' );
var broadcast = require( '@stdlib/ndarray/base/maybe-broadcast-array' );
var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' );
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
var dtypes2strings = require( '@stdlib/ndarray/base/dtypes2strings' );
var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' );
var binaryOutputDataType = require( '@stdlib/ndarray/base/binary-output-dtype' );
var numel = require( '@stdlib/ndarray/base/numel' );
var buffer = require( '@stdlib/ndarray/base/buffer' );
var getShape = require( '@stdlib/ndarray/shape' );
var getDType = require( '@stdlib/ndarray/dtype' );
var getOrder = require( '@stdlib/ndarray/order' );
var ndims = require( '@stdlib/ndarray/ndims' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var defaults = require( '@stdlib/ndarray/defaults' );
var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' );
var accessorSetter = require( '@stdlib/array/base/accessor-setter' );
var setter = require( '@stdlib/array/base/setter' );
var format = require( '@stdlib/string/format' );
var validate = require( './validate.js' );
// VARIABLES //
var ORDINALS = [ 'First', 'Second', 'Third' ];
// FUNCTIONS //
/**
* Performs an initial scan of a list of parameters.
*
* @private
* @param {Array} params - list of parameters
* @returns {Array} scan results
*/
function initialScan( params ) {
var out;
var p;
var o;
var i;
out = [];
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
o = {
'scalar': true,
'value': p,
'dtype': '',
'ndims': 0,
'order': ''
};
if ( isNumber( p ) ) {
o.dtype = 'float64';
} else if ( isComplexLike( p ) ) {
if ( p.byteLength === 8 ) {
o.dtype = 'complex64';
} else {
o.dtype = 'complex128';
}
} else if ( isndarrayLike( p ) ) {
o.scalar = false;
o.dtype = resolveStr( getDType( p ) );
o.ndims = ndims( p );
o.order = getOrder( p );
} else {
o.dtype = 'generic';
}
out.push( o );
}
return out;
}
/**
* Checks whether all parameters are scalar compatible.
*
* ## Notes
*
* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.
*
* @private
* @param {Array<Object>} params - list of parameter objects
* @returns {boolean} boolean indicating whether all parameters are scalar compatible
*/
function isScalarCompatible( params ) {
var count;
var p;
var i;
count = 0;
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
if ( p.scalar || p.ndims === 0 ) {
count += 1;
}
}
return ( count === params.length );
}
/**
* Converts a list of parameters to scalar values.
*
* ## Notes
*
* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.
*
* @private
* @param {Array<Object>} params - list of parameter objects
* @returns {Array<Object>} updated list
*/
function convertToScalars( params ) {
var p;
var i;
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
if ( p.scalar === false ) {
p.scalar = true;
p.value = p.value.get();
p.ndims = 0;
p.order = '';
}
}
return params;
}
/**
* Resolves a common memory layout from a list of parameter objects.
*
* @private
* @param {Array<Object>} params - list of parameter objects
* @returns {string} memory layout
*/
function resolveOrder( params ) {
var p;
var i;
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...
if ( p.scalar === false ) {
break;
}
}
return p.order;
}
/**
* Broadcasts parameter values to an ndarray having a specified shape.
*
* ## Notes
*
* - The function **mutates** the input array.
*
* @private
* @param {NonNegativeIntegerArray} shape - array shape
* @param {Array<Object>} params - list of parameter objects
* @returns {Array<Object>} updated list
*/
function broadcastParameters( shape, params ) {
var ord;
var p;
var i;
ord = resolveOrder( params );
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
if ( p.scalar ) {
p.scalar = false;
p.value = broadcastScalar( p.value, p.dtype, shape, ord );
p.order = ord;
} else {
p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility
}
p.ndims = shape.length;
}
return params;
}
// MAIN //
/**
* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.
*
* @constructor
* @param {Function} prng - binary pseudorandom value generator
* @param {ArrayLikeObject<ArrayLikeObject>} idtypes - list containing a list of supported input data types for each PRNG parameter
* @param {ArrayLikeObject} odtypes - list of supported output data types
* @param {Object} policies - policies
* @param {string} policies.output - output data type policy
* @param {Object} [options] - function options
* @param {string} [options.order] - default memory layout
* @throws {TypeError} first argument must be a function
* @throws {TypeError} second argument must be an array containing arrays of supported data types
* @throws {TypeError} third argument must be an array of supported data types
* @throws {TypeError} fourth argument must be an object having supported policies
* @throws {TypeError} options argument must be an object
* @throws {TypeError} must provide valid options
* @returns {Random} instance
*
* @example
* var dtypes = require( '@stdlib/ndarray/dtypes' );
* var uniform = require( '@stdlib/random/base/uniform' );
*
* var idt = dtypes( 'real_and_generic' );
* var odt = dtypes( 'real_floating_point_and_generic' );
*
* var policies = {
* 'output': 'real_floating_point_and_generic'
* };
* var options = {
* 'order': 'row-major'
* };
*
* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );
*
* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );
* // returns <ndarray>
*
* @example
* var dtypes = require( '@stdlib/ndarray/dtypes' );
* var ndzeros = require( '@stdlib/ndarray/zeros' );
* var uniform = require( '@stdlib/random/base/uniform' );
*
* var idt = dtypes( 'real_and_generic' );
* var odt = dtypes( 'real_floating_point_and_generic' );
*
* var policies = {
* 'output': 'real_floating_point_and_generic'
* };
* var options = {
* 'order': 'row-major'
* };
*
* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );
*
* var out = ndzeros( [ 2, 2 ] );
* var v = rand.assign( 0.0, 1.0, out );
* // returns <ndarray>
*
* var bool = ( v === out );
* // returns true
*/
function Random( prng, idtypes, odtypes, policies, options ) {
var opts;
var dt;
var i;
if ( !( this instanceof Random ) ) {
if ( arguments.length < 5 ) {
return new Random( prng, idtypes, odtypes, policies );
}
return new Random( prng, idtypes, odtypes, policies, options );
}
if ( !isFunction( prng ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );
}
if ( !isCollection( idtypes ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );
}
idtypes = copy( idtypes );
for ( i = 0; i < idtypes.length; i++ ) {
dt = idtypes[ i ];
if (
!isCollection( dt ) ||
dt.length < 1 ||
!everyBy( dt, isDataType )
) {
throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );
}
idtypes[ i ] = dtypes2strings( dt );
}
if (
!isCollection( odtypes ) ||
odtypes.length < 1 ||
!everyBy( odtypes, isDataType )
) {
throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );
}
odtypes = dtypes2strings( odtypes );
if ( !isObject( policies ) ) {
throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );
}
if ( !isOutputDataTypePolicy( policies.output ) ) {
throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );
}
opts = {
'order': defaults.get( 'order' )
};
if ( arguments.length > 4 ) {
if ( !isPlainObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
}
if ( hasOwnProp( options, 'order' ) ) {
opts.order = options.order;
if ( !isOrder( opts.order ) ) {
throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );
}
}
}
this._prng = prng;
this._idtypes = idtypes;
this._odtypes = odtypes;
this._policies = {
'output': policies.output
};
this._opts = opts;
return this;
}
/**
* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.
*
* @name generate
* @memberof Random.prototype
* @type {Function}
* @param {NonNegativeIntegerArray} shape - output shape
* @param {(ndarrayLike|*)} param1 - first PRNG parameter
* @param {(ndarrayLike|*)} param2 - second PRNG parameter
* @param {Options} [options] - function options
* @param {*} [options.dtype] - output ndarray data type
* @param {string} [options.order] - memory layout (either row-major or column-major)
* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions
* @param {ArrayLikeObject<string>} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis
* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only
* @throws {TypeError} first argument must be a valid shape
* @throws {TypeError} must provide valid PRNG parameters
* @throws {TypeError} PRNG parameters and the desired shape must be broadcast compatible
* @throws {TypeError} options argument must be an object
* @throws {TypeError} must provide valid options
* @returns {ndarray} output ndarray
*
* @example
* var dtypes = require( '@stdlib/ndarray/dtypes' );
* var uniform = require( '@stdlib/random/base/uniform' );
*
* var idt = dtypes( 'real_and_generic' );
* var odt = dtypes( 'real_floating_point_and_generic' );
*
* var policies = {
* 'output': 'real_floating_point_and_generic'
* };
* var options = {
* 'order': 'row-major'
* };
*
* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );
*
* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );
* // returns <ndarray>
*/
setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {
var params;
var prng;
var opts;
var buf;
var err;
var len;
var ord;
var FLG;
var out;
var set;
var dt;
var st;
var p1;
var p2;
var i;
if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {
throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );
}
opts = {};
if ( arguments.length > 3 ) {
err = validate( opts, this._odtypes, options );
if ( err ) {
throw err;
}
}
params = initialScan( [ param1, param2 ] );
for ( i = 0; i < params.length; i++ ) {
dt = params[ i ].dtype;
if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {
throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) );
}
}
FLG = isScalarCompatible( params );
if ( FLG ) {
params = convertToScalars( params );
} else {
params = broadcastParameters( shape, params );
}
p1 = params[ 0 ];
p2 = params[ 1 ];
prng = this._prng;
dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len
if ( opts.order ) {
ord = opts.order;
} else if ( FLG ) {
ord = this._opts.order;
} else {
// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:
ord = p1.order;
}
// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...
len = numel( shape );
if ( len === 0 ) {
// Check for a zero-dimensional shape...
if ( shape.length === 0 ) {
// If the output array is a zero-dimensional ndarray, we generate a single random variate...
buf = buffer( dt, 1 );
if ( isAccessorArray( buf ) ) {
set = accessorSetter( dt );
} else {
set = setter( dt );
}
set( buf, 0, prng( p1.value, p2.value ) );
st = [ 0 ];
} else {
// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...
buf = buffer( dt, len );
st = shape2strides( shape, ord );
}
return new ndarray( dt, buf, shape, st, 0, ord, opts );
}
// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...
if ( FLG ) {
if ( isEqualDataType( dt, 'generic' ) ) {
buf = filledBy( len, wrapper );
} else {
buf = buffer( dt, len );
nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );
}
st = shape2strides( shape, ord );
return new ndarray( dt, buf, shape, st, 0, ord, opts );
}
// We've been provided ndarrays, so we need to perform element-wise iteration...
// Allocate a data buffer:
buf = buffer( dt, len );
// Initialize the output array:
st = shape2strides( shape, ord );
out = new ndarray( dt, buf, shape, st, 0, ord, opts );
// Fill the output array with pseudorandom values:
binary( [ p1.value, p2.value, out ], prng );
return out;
/**
* Applies parameters to a pseudorandom number generator function.
*
* @private
* @returns {(number|ComplexLike)} pseudorandom number
*/
function wrapper() {
return prng( p1.value, p2.value );
}
});
/**
* Fills an ndarray with pseudorandom values drawn from a binary PRNG.
*
* @name assign
* @memberof Random.prototype
* @type {Function}
* @param {(ndarrayLike|*)} param1 - first PRNG parameter
* @param {(ndarrayLike|*)} param2 - second PRNG parameter
* @param {ndarrayLike} out - output ndarray
* @throws {TypeError} third argument must be an ndarray
* @throws {TypeError} must provide valid PRNG parameters
* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible
* @throws {Error} cannot write to a read-only ndarray
* @returns {ndarray} output ndarray
*
* @example
* var dtypes = require( '@stdlib/ndarray/dtypes' );
* var ndzeros = require( '@stdlib/ndarray/zeros' );
* var uniform = require( '@stdlib/random/base/uniform' );
*
* var idt = dtypes( 'real_and_generic' );
* var odt = dtypes( 'real_floating_point_and_generic' );
*
* var policies = {
* 'output': 'real_floating_point_and_generic'
* };
* var options = {
* 'order': 'row-major'
* };
*
* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );
*
* var out = ndzeros( [ 2, 2 ] );
* var v = rand.assign( 0.0, 1.0, out );
* // returns <ndarray>
*
* var bool = ( v === out );
* // returns true
*/
setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {
var params;
var pdt;
var odt;
var ord;
var sh;
var p;
var i;
if ( !isndarrayLike( out ) ) {
throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );
}
if ( isReadOnly( out ) ) {
throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );
}
sh = getShape( out );
ord = getOrder( out );
odt = getDType( out );
if ( !contains( this._odtypes, resolveStr( odt ) ) ) {
throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) );
}
params = [ param1, param2 ];
for ( i = 0; i < params.length; i++ ) {
p = params[ i ];
// Check whether we've been provided a scalar PRNG parameter...
if ( isNumber( p ) ) {
// Wrap the scalar in a broadcasted ndarray:
pdt = 'float64';
p = broadcastScalar( p, pdt, sh, ord );
} else if ( isComplexLike( p ) ) {
if ( p.byteLength === 8 ) {
pdt = 'complex64';
} else {
pdt = 'complex128';
}
// Wrap the scalar in a broadcasted ndarray:
p = broadcastScalar( p, pdt, sh, ord );
} else if ( isndarrayLike( p ) ) {
// Broadcast the PRNG parameter to the desired shape:
pdt = getDType( p );
p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility
} else {
// Wrap the scalar in a broadcasted ndarray:
pdt = 'generic';
p = broadcastScalar( p, pdt, sh, ord );
}
if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {
throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) );
}
params[ i ] = p;
}
// Fill the output array with pseudorandom values:
params.push( out );
binary( params, this._prng );
return out;
});
// EXPORTS //
module.exports = Random;
|