All files main.js

100% Statements 647/647
100% Branches 184/184
100% Functions 3/3
100% Lines 647/647

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 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 64814x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 383x 383x 65x 65x 318x 383x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 395x 395x 395x 395x 395x 395x 395x 395x 106x 395x 289x 289x 395x 395x 136x 136x 136x 136x 259x 395x 78x 78x 24x 24x 54x 54x 78x 2x 78x 2x 2x 2x 2x 2x 2x 52x 48x 48x 54x 54x 54x 181x 395x 64x 64x 64x 64x 117x 395x 13x 13x 13x 13x 3x 3x 10x 10x 10x 2x 10x 2x 2x 2x 2x 2x 2x 8x 4x 4x 10x 10x 10x 104x 395x 29x 29x 29x 75x 395x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1405x 1x 1x 1x 1404x 1404x 1404x 1405x 69x 5x 5x 64x 69x 31x 31x 9x 9x 1335x 1335x 1335x 1401x 204x 204x 33x 1x 1x 32x 32x 171x 186x 31x 31x 13x 13x 17x 17x 140x 140x 182x 18x 17x 17x 1x 1x 1x 122x 182x 4x 4x 118x 182x 28x 28x 16x 16x 1131x 1131x 1131x 1396x 284x 284x 27x 13x 13x 27x 13x 13x 1x 1x 257x 284x 102x 3x 3x 99x 102x 30x 30x 42x 42x 155x 243x 63x 63x 243x 48x 48x 44x 243x 3x 3x 3x 41x 284x 1x 1x 40x 243x 2x 2x 38x 38x 38x 38x 847x 847x 847x 1392x 284x 284x 98x 39x 39x 85x 26x 26x 33x 85x 5x 5x 28x 85x 1x 1x 27x 27x 186x 284x 44x 44x 284x 44x 44x 98x 284x 32x 32x 3x 3x 29x 32x 24x 24x 5x 5x 5x 66x 284x 43x 43x 284x 9x 9x 14x 14x 14x 14x 563x 563x 563x 1392x 260x 260x 63x 13x 13x 63x 13x 13x 63x 15x 15x 63x 9x 9x 13x 13x 197x 260x 44x 44x 260x 44x 44x 109x 260x 27x 13x 13x 27x 13x 13x 1x 1x 1x 82x 260x 44x 44x 260x 15x 15x 260x 9x 9x 14x 14x 14x 303x 303x 303x 1392x 158x 22x 22x 158x 22x 22x 158x 26x 26x 158x 28x 28x 158x 28x 28x 32x 32x 32x 158x 3x 3x 29x 158x 24x 24x 5x 5x 5x 145x 145x 145x 1392x 33x 33x 1392x 33x 33x 1392x 13x 13x 1392x 14x 14x 1392x 14x 14x 1392x 15x 15x 1392x 9x 9x 14x 14x 14x 1405x 14x 14x 14x 14x 14x  
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 max-len */
 
'use strict';
 
// MODULES //
 
var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives;
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
var isIterableLike = require( '@stdlib/assert/is-iterable-like' );
var isCollection = require( '@stdlib/assert/is-collection' );
var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' );
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
var isGenericDataType = require( '@stdlib/ndarray/base/assert/is-generic-data-type' );
var isBinaryDataType = require( '@stdlib/ndarray/base/assert/is-binary-data-type' );
var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var flatten3d = require( '@stdlib/array/base/flatten3d' );
var slice = require( '@stdlib/array/base/slice' );
var arrayShape = require( '@stdlib/array/shape' );
var typedarray = require( '@stdlib/array/typed' );
var iterator2array = require( '@stdlib/array/from-iterator' );
var buffer = require( '@stdlib/ndarray/base/buffer' );
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
var numel = require( '@stdlib/ndarray/base/numel' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var defaults = require( '@stdlib/ndarray/defaults' );
var array2buffer = require( '@stdlib/buffer/from-array' );
var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' );
var format = require( '@stdlib/string/format' );
var arraybuffer2tensor3d = require( './from_arraybuffer.js' );
 
 
// VARIABLES //
 
var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
var DEFAULT_ORDER = defaults.get( 'order' );
 
 
// FUNCTIONS //
 
/**
* Resolves the order of the output ndarray.
*
* @private
* @param {*} options - options argument
* @returns {string} order
*/
function resolveOrder( options ) {
	if ( hasOwnProp( options, 'order' ) ) {
		return options.order;
	}
	return DEFAULT_ORDER;
}
 
/**
* Returns a three-dimensional ndarray having a specified data type.
*
* @private
* @param {(NonNegativeIntegerArray|Collection|ArrayBuffer|Iterable|Options)} arg - shape, array-like object, ArrayBuffer, iterable, or options object
* @param {*} dtype - data type
* @param {(Options|null)} options - function options
* @param {boolean} [options.readonly=false] - boolean indicating whether to return a read-only ndarray
* @param {string} [options.mode='throw'] - specifies how to handle indices which exceed ndarray dimensions
* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
* @returns {(ndarray|null)} three-dimensional ndarray
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var v = tensor3dWithDType( [ 2, 2, 5 ], 'float64', {} );
* // returns <ndarray>
*
* var sh = getShape( v );
* // returns [ 2, 2, 5 ]
*
* var dt = String( getDType( v ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var v = tensor3dWithDType( [ [ [ 1, 2 ], [ 3, 4 ] ] ], 'generic', {} );
* // returns <ndarray>
*
* var sh = getShape( v );
* // returns [ 1, 2, 2 ]
*
* var dt = String( getDType( v ) );
* // returns 'generic'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
* var ArrayBuffer = require( '@stdlib/array/buffer' );
*
* var buf = new ArrayBuffer( 32 );
* var v = tensor3dWithDType( buf, 'float64', {} );
* // returns <ndarray>
*
* var sh = getShape( v );
* // returns [ 1, 1, 4 ]
*
* var dt = String( getDType( v ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var v = tensor3dWithDType( {}, 'float64', null );
* // returns <ndarray>
*
* var sh = getShape( v );
* // returns [ 0, 0, 0 ]
*
* var dt = String( getDType( v ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
* var array2iterator = require( '@stdlib/array/to-iterator' );
*
* var v = tensor3dWithDType( array2iterator( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ), 'generic', {} );
* // returns <ndarray>
*
* var sh = getShape( v );
* // returns [ 1, 2, 2 ]
*
* var dt = String( getDType( v ) );
* // returns 'generic'
*/
function tensor3dWithDType( arg, dtype, options ) {
	var opts;
	var buf;
	var ord;
	var sh;
 
	// Note: in all of the following, we delegate option validation to the ndarray constructor...
	if ( options === null ) {
		opts = {};
	} else {
		opts = options;
	}
	// Case: tensor3d( shape )
	if ( isNonNegativeIntegerArray( arg ) && arg.length === 3 ) {
		buf = buffer( dtype, numel( arg ) );
		ord = resolveOrder( opts );
		return new ndarray( dtype, buf, arg, shape2strides( arg, ord ), 0, ord, opts );
	}
	// Case: tensor3d( collection )
	if ( isCollection( arg ) ) {
		sh = arrayShape( arg );
		if ( sh.length < 3 ) {
			return null;
		}
		sh = slice( sh, 0, 3 );
		buf = flatten3d( arg, sh, false );
		if ( isBinaryDataType( dtype ) ) {
			buf = array2buffer( buf ); // note: we assume that `buf` is an array of octets
		} else if ( isComplexDataType( dtype ) ) {
			// Sniff the first value in order to determine if we've been provided a nested array containing interleaved real and imaginary components...
			if ( isNumber( buf[ 0 ] ) ) {
				// As each real and imaginary component pair corresponds to a single complex number, we need to update the ndarray shape:
				sh[ sh.length-1 ] /= 2;
			}
			buf = typedarray( buf, dtype );
		} else if ( !isGenericDataType( dtype ) ) {
			buf = typedarray( buf, dtype );
		}
		ord = resolveOrder( opts );
		return new ndarray( dtype, buf, sh, shape2strides( sh, ord ), 0, ord, opts );
	}
	// Case: tensor3d( ArrayBuffer )
	if ( isArrayBuffer( arg ) ) {
		sh = [ 1, 1, arg.byteLength/bytesPerElement( dtype ) ];
		ord = resolveOrder( opts );
		return arraybuffer2tensor3d( dtype, arg, sh, shape2strides( sh, ord ), 0, ord, opts );
	}
	// Case: tensor3d( Iterable )
	if ( isIterableLike( arg ) ) {
		buf = arg[ ITERATOR_SYMBOL ]();
		buf = iterator2array( buf );
		sh = arrayShape( buf );
		if ( sh.length < 3 ) {
			return null;
		}
		sh = slice( sh, 0, 3 );
		buf = flatten3d( buf, sh, false );
		if ( isBinaryDataType( dtype ) ) {
			buf = array2buffer( buf ); // note: we assume that `buf` is an array of octets
		} else if ( isComplexDataType( dtype ) ) {
			// Sniff the first value in order to determine if we've materialized a nested array containing interleaved real and imaginary components...
			if ( isNumber( buf[ 0 ] ) ) {
				// As each real and imaginary component pair corresponds to a single complex number, we need to update the ndarray shape:
				sh[ sh.length-1 ] /= 2;
			}
			buf = typedarray( buf, dtype );
		} else if ( !isGenericDataType( dtype ) ) {
			buf = typedarray( buf, dtype );
		}
		ord = resolveOrder( opts );
		return new ndarray( dtype, buf, sh, shape2strides( sh, ord ), 0, ord, opts );
	}
	// Case: tensor3d( options )
	if ( options === null && isPlainObject( arg ) ) {
		buf = buffer( dtype, 0 );
		return new ndarray( dtype, buf, [ 0, 0, 0 ], [ 0, 0, 0 ], 0, resolveOrder( arg ), arg );
	}
	return null;
}
 
 
// MAIN //
 
/**
* Creates a three-dimensional ndarray.
*
* ## Notes
*
* -   This API is intended to match the conventions of `@stdlib/array/typed`, which has a similar signature.
*
* @param {(NonNegativeInteger|NonNegativeIntegerArray|ArrayLikeObject<Collection>|ArrayBuffer|Iterable)} [arg0] - number of elements in the first dimension, shape, nested array, ArrayBuffer, or iterable
* @param {NonNegativeInteger} [arg1] - number of elements in the second dimension or byte offset
* @param {(NonNegativeInteger|NonNegativeIntegerArray)} [arg2] - number of elements in the last dimension, number of elements in the first dimension, or shape
* @param {NonNegativeInteger} [arg3] - number of elements in the second dimension
* @param {NonNegativeInteger} [arg4] - number of elements in the last dimension
* @param {*} [dtype='float64'] - data type
* @param {Options} [options] - function options
* @param {boolean} [options.readonly=false] - boolean indicating whether to return a read-only three-dimensional ndarray
* @param {string} [options.mode='throw'] - specifies how to handle indices which exceed ndarray dimensions
* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
* @param {string} [options.order='row-major'] - memory layout (either row-major or column-major)
* @throws {TypeError} first argument must be either a shape, array-like object, ArrayBuffer, iterable, data type, or options object
* @throws {TypeError} must provide valid options
* @returns {ndarray} three-dimensional ndarray
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var arr = tensor3d();
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 0, 0, 0 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var arr = tensor3d( 2, 2, 2 );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 2, 2, 2 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var arr = tensor3d( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ], [ 7.0, 8.0 ] ] ] );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 2, 2, 2 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
*
* var arr = tensor3d( [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ], 'float32' );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 1, 2, 2 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float32'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
* var ArrayBuffer = require( '@stdlib/array/buffer' );
*
* var buf = new ArrayBuffer( 32 );
* var arr = tensor3d( buf );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 1, 1, 4 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
* var ArrayBuffer = require( '@stdlib/array/buffer' );
*
* var buf = new ArrayBuffer( 32 );
* var arr = tensor3d( buf, 16 );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 1, 1, 2 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*
* @example
* var getDType = require( '@stdlib/ndarray/dtype' );
* var getShape = require( '@stdlib/ndarray/shape' );
* var ArrayBuffer = require( '@stdlib/array/buffer' );
*
* var buf = new ArrayBuffer( 64 );
* var arr = tensor3d( buf, 16, 2, 1, 1 );
* // returns <ndarray>
*
* var sh = getShape( arr );
* // returns [ 2, 1, 1 ]
*
* var dt = String( getDType( arr ) );
* // returns 'float64'
*/
function tensor3d() { // eslint-disable-line max-statements
	var nargs;
	var arg0;
	var arg1;
	var arg2;
	var arg3;
	var arg4;
	var arg5;
	var arg6;
	var buf;
	var ord;
	var out;
	var sh;
 
	nargs = arguments.length;
 
	// Case: tensor3d()
	if ( nargs === 0 ) {
		buf = buffer( DEFAULT_DTYPE, 0 );
		return new ndarray( DEFAULT_DTYPE, buf, [ 0, 0, 0 ], [ 0, 0, 0 ], 0, DEFAULT_ORDER );
	}
	arg0 = arguments[ 0 ];
 
	// Case: tensor3d( arg0 );
	if ( nargs === 1 ) {
		if ( isDataType( arg0 ) ) {
			return tensor3dWithDType( [ 0, 0, 0 ], arg0, null );
		}
		out = tensor3dWithDType( arg0, DEFAULT_DTYPE, null );
		if ( out === null ) {
			throw new TypeError( format( 'invalid argument. Must provide a shape, ArrayBuffer, array-like object, iterable, data type, or options object. Value: `%s`.', arg0 ) );
		}
		return out;
	}
	arg1 = arguments[ 1 ];
 
	// Case: tensor3d( arg0, arg1 )
	if ( nargs === 2 ) {
		// Case: tensor3d( dtype, options )
		if ( isDataType( arg0 ) ) {
			if ( arg1 === null ) {
				throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg1 ) );
			}
			return tensor3dWithDType( [ 0, 0, 0 ], arg0, arg1 );
		}
		// Case: tensor3d( arg0, dtype )
		if ( isDataType( arg1 ) ) {
			out = tensor3dWithDType( arg0, arg1, null );
			if ( out === null ) {
				throw new TypeError( format( 'invalid argument. First argument must be a shape, ArrayBuffer, array-like object, or iterable. Value: `%s`.', arg0 ) );
			}
			return out;
		}
		// Case: tensor3d( ArrayBuffer, byteOffset )
		// Note: unlike a matrix, a three-dimensional ndarray shape cannot be fully specified by two arguments, and thus, in contrast to `@stdlib/ndarray/matrix/ctor`, two nonnegative integers is not a supported signature.
		if ( isNonNegativeInteger( arg1 ) ) {
			if ( !isArrayBuffer( arg0 ) ) {
				throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
			}
			sh = [ 1, 1, (arg0.byteLength-arg1)/bytesPerElement( DEFAULT_DTYPE ) ];
			return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, sh, shape2strides( sh, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
		}
		// Case: tensor3d( arg0, options )
		if ( arg1 === null ) {
			throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg1 ) );
		}
		out = tensor3dWithDType( arg0, DEFAULT_DTYPE, arg1 );
		if ( out === null ) {
			throw new TypeError( format( 'invalid argument. First argument must be a shape, ArrayBuffer, array-like object, or iterable. Value: `%s`.', arg0 ) );
		}
		return out;
	}
	arg2 = arguments[ 2 ];
 
	// Case: tensor3d( arg0, arg1, arg2 )
	if ( nargs === 3 ) {
		// Case: tensor3d( K, M, N )
		if ( isNonNegativeInteger( arg0 ) ) {
			if ( !isNonNegativeInteger( arg1 ) ) {
				throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
			}
			if ( !isNonNegativeInteger( arg2 ) ) {
				throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', arg2 ) );
			}
			return tensor3dWithDType( [ arg0, arg1, arg2 ], DEFAULT_DTYPE, null );
		}
		// Case: tensor3d( arg0, dtype, options )
		if ( isDataType( arg1 ) ) {
			if ( arg2 === null ) {
				throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg2 ) );
			}
			out = tensor3dWithDType( arg0, arg1, arg2 );
			if ( out === null ) {
				throw new TypeError( format( 'invalid argument. First argument must be a shape, ArrayBuffer, array-like object, or iterable. Value: `%s`.', arg0 ) );
			}
			return out;
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, arg2 )
		if ( !isArrayBuffer( arg0 ) ) {
			throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
		}
		if ( !isNonNegativeInteger( arg1 ) ) {
			throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', arg1 ) );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, dtype )
		if ( isDataType( arg2 ) ) {
			sh = [ 1, 1, (arg0.byteLength-arg1)/bytesPerElement( arg2 ) ];
			return arraybuffer2tensor3d( arg2, arg0, sh, shape2strides( sh, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, shape )
		if ( isNonNegativeIntegerArray( arg2 ) && arg2.length === 3 ) {
			return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, arg2, shape2strides( arg2, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, options )
		if ( arg2 === null ) {
			throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg2 ) );
		}
		sh = [ 1, 1, (arg0.byteLength-arg1)/bytesPerElement( DEFAULT_DTYPE ) ];
		ord = resolveOrder( arg2 );
		return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, sh, shape2strides( sh, ord ), arg1, ord, arg2 );
	}
	arg3 = arguments[ 3 ];
 
	// Case: tensor3d( arg0, arg1, arg2, arg3 )
	if ( nargs === 4 ) {
		// Case: tensor3d( K, M, N, arg3 )
		if ( isNonNegativeInteger( arg0 ) ) {
			if ( !isNonNegativeInteger( arg1 ) ) {
				throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
			}
			if ( !isNonNegativeInteger( arg2 ) ) {
				throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', arg2 ) );
			}
			// Case: tensor3d( K, M, N, dtype )
			if ( isDataType( arg3 ) ) {
				return tensor3dWithDType( [ arg0, arg1, arg2 ], arg3, null );
			}
			// Case: tensor3d( K, M, N, options )
			if ( arg3 === null ) {
				throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg3 ) );
			}
			return tensor3dWithDType( [ arg0, arg1, arg2 ], DEFAULT_DTYPE, arg3 );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, arg2, arg3 )
		if ( !isArrayBuffer( arg0 ) ) {
			throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
		}
		if ( !isNonNegativeInteger( arg1 ) ) {
			throw new TypeError( format( 'invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.', arg1 ) );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, shape, arg3 )
		if ( isNonNegativeIntegerArray( arg2 ) && arg2.length === 3 ) {
			// Case: tensor3d( ArrayBuffer, byteOffset, shape, dtype )
			if ( isDataType( arg3 ) ) {
				return arraybuffer2tensor3d( arg3, arg0, arg2, shape2strides( arg2, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
			}
			// Case: tensor3d( ArrayBuffer, byteOffset, shape, options )
			if ( !isPlainObject( arg3 ) ) {
				throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg3 ) );
			}
			ord = resolveOrder( arg3 );
			return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, arg2, shape2strides( arg2, ord ), arg1, ord, arg3 );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, dtype, options )
		if ( !isDataType( arg2 ) ) {
			throw new TypeError( format( 'invalid argument. Third argument must be a recognized/supported data type. Value: `%s`.', arg2 ) );
		}
		if ( !isPlainObject( arg3 ) ) {
			throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg3 ) );
		}
		sh = [ 1, 1, (arg0.byteLength-arg1)/bytesPerElement( arg2 ) ];
		ord = resolveOrder( arg3 );
		return arraybuffer2tensor3d( arg2, arg0, sh, shape2strides( sh, ord ), arg1, ord, arg3 );
	}
	arg4 = arguments[ 4 ];
 
	// Case: tensor3d( arg0, arg1, arg2, arg3, arg4 )
	if ( nargs === 5 ) {
		// Case: tensor3d( K, M, N, dtype, options )
		if ( isNonNegativeInteger( arg0 ) ) {
			if ( !isNonNegativeInteger( arg1 ) ) {
				throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
			}
			if ( !isNonNegativeInteger( arg2 ) ) {
				throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', arg2 ) );
			}
			if ( !isDataType( arg3 ) ) {
				throw new TypeError( format( 'invalid argument. Fourth argument must be a recognized/supported data type. Value: `%s`.', arg3 ) );
			}
			if ( !isPlainObject( arg4 ) ) {
				throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg4 ) );
			}
			return tensor3dWithDType( [ arg0, arg1, arg2 ], arg3, arg4 );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, arg2, arg3, arg4 )
		if ( !isArrayBuffer( arg0 ) ) {
			throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
		}
		if ( !isNonNegativeInteger( arg1 ) ) {
			throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, K, M, N )
		if ( isNonNegativeInteger( arg2 ) ) {
			if ( !isNonNegativeInteger( arg3 ) ) {
				throw new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', arg3 ) );
			}
			if ( !isNonNegativeInteger( arg4 ) ) {
				throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', arg4 ) );
			}
			sh = [ arg2, arg3, arg4 ];
			return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, sh, shape2strides( sh, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, shape, dtype, options )
		if ( !isNonNegativeIntegerArray( arg2 ) || arg2.length !== 3 ) {
			throw new TypeError( format( 'invalid argument. Third argument must be a valid shape. Value: `%s`.', arg2 ) );
		}
		if ( !isDataType( arg3 ) ) {
			throw new TypeError( format( 'invalid argument. Fourth argument must be a recognized/supported data type. Value: `%s`.', arg3 ) );
		}
		if ( !isPlainObject( arg4 ) ) {
			throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg4 ) );
		}
		ord = resolveOrder( arg4 );
		return arraybuffer2tensor3d( arg3, arg0, arg2, shape2strides( arg2, ord ), arg1, ord, arg4 );
	}
	arg5 = arguments[ 5 ];
 
	// Case: tensor3d( ArrayBuffer, byteOffset, K, M, N, arg5 )
	if ( nargs === 6 ) {
		if ( !isArrayBuffer( arg0 ) ) {
			throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
		}
		if ( !isNonNegativeInteger( arg1 ) ) {
			throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
		}
		if ( !isNonNegativeInteger( arg2 ) ) {
			throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', arg2 ) );
		}
		if ( !isNonNegativeInteger( arg3 ) ) {
			throw new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', arg3 ) );
		}
		if ( !isNonNegativeInteger( arg4 ) ) {
			throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', arg4 ) );
		}
		sh = [ arg2, arg3, arg4 ];
 
		// Case: tensor3d( ArrayBuffer, byteOffset, K, M, N, dtype )
		if ( isDataType( arg5 ) ) {
			return arraybuffer2tensor3d( arg5, arg0, sh, shape2strides( sh, DEFAULT_ORDER ), arg1, DEFAULT_ORDER );
		}
		// Case: tensor3d( ArrayBuffer, byteOffset, K, M, N, options )
		if ( !isPlainObject( arg5 ) ) {
			throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg5 ) );
		}
		ord = resolveOrder( arg5 );
		return arraybuffer2tensor3d( DEFAULT_DTYPE, arg0, sh, shape2strides( sh, ord ), arg1, ord, arg5 );
	}
	arg6 = arguments[ 6 ];
 
	// Case: tensor3d( ArrayBuffer, byteOffset, K, M, N, dtype, options )
	if ( !isArrayBuffer( arg0 ) ) {
		throw new TypeError( format( 'invalid argument. First argument must be an ArrayBuffer. Value: `%s`.', arg0 ) );
	}
	if ( !isNonNegativeInteger( arg1 ) ) {
		throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', arg1 ) );
	}
	if ( !isNonNegativeInteger( arg2 ) ) {
		throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', arg2 ) );
	}
	if ( !isNonNegativeInteger( arg3 ) ) {
		throw new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', arg3 ) );
	}
	if ( !isNonNegativeInteger( arg4 ) ) {
		throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', arg4 ) );
	}
	if ( !isDataType( arg5 ) ) {
		throw new TypeError( format( 'invalid argument. Sixth argument must be a recognized/supported data type. Value: `%s`.', arg5 ) );
	}
	if ( !isPlainObject( arg6 ) ) {
		throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', arg6 ) );
	}
	sh = [ arg2, arg3, arg4 ];
	ord = resolveOrder( arg6 );
	return arraybuffer2tensor3d( arg5, arg0, sh, shape2strides( sh, ord ), arg1, ord, arg6 );
}
 
 
// EXPORTS //
 
module.exports = tensor3d;