From 2184f1a2828b03283f53046fa1c28a52370f67ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:44:35 +0000 Subject: [PATCH] Update artifacts --- ndarray/base/coverage.ndjson | 1 + ndarray/base/index.html | 10 +- ndarray/base/index.js.html | 35 +- ndarray/base/slice-assign/coverage.ndjson | 1 + ndarray/base/slice-assign/index.html | 131 +++++ ndarray/base/slice-assign/index.js.html | 322 ++++++++++++ ndarray/base/slice-assign/main.js.html | 502 ++++++++++++++++++ ndarray/base/slice/coverage.ndjson | 1 + ndarray/base/slice/empty.js.html | 20 +- ndarray/base/slice/index.html | 33 +- ndarray/base/slice/index.js.html | 6 +- ndarray/base/slice/main.js.html | 150 +++--- ndarray/base/slice/slice_start.js.html | 26 +- ndarray/base/slice/slice_strides.js.html | 2 +- ndarray/fancy/coverage.ndjson | 1 + ndarray/fancy/error_constructor.js.html | 84 +-- ndarray/fancy/error_message.js.html | 80 +-- ndarray/fancy/get.js.html | 271 ++++++++++ ndarray/fancy/get_slice.js.html | 265 ++++++++++ ndarray/fancy/get_value.js.html | 280 ++++++++++ ndarray/fancy/has_property.js.html | 106 ++-- ndarray/fancy/index.html | 178 +++++-- ndarray/fancy/index.js.html | 92 ++-- ndarray/fancy/main.js.html | 307 ++++++----- ndarray/fancy/prop2slice.0d.js.html | 433 ++++++++++++++++ ndarray/fancy/prop2slice.1d.js.html | 445 ++++++++++++++++ ndarray/fancy/prop2slice.nd.js.html | 382 ++++++++++++++ ndarray/fancy/re_integer.js.html | 96 ++-- ndarray/fancy/re_subseq.js.html | 96 ++-- ndarray/fancy/set.js.html | 280 ++++++++++ ndarray/fancy/set_slice.js.html | 598 ++++++++++++++++++++++ ndarray/fancy/set_value.js.html | 208 ++++++++ ndarray/slice/coverage.ndjson | 1 + ndarray/slice/index.html | 2 +- ndarray/slice/index.js.html | 2 +- ndarray/slice/main.js.html | 4 +- 36 files changed, 4872 insertions(+), 579 deletions(-) create mode 100644 ndarray/base/slice-assign/coverage.ndjson create mode 100644 ndarray/base/slice-assign/index.html create mode 100644 ndarray/base/slice-assign/index.js.html create mode 100644 ndarray/base/slice-assign/main.js.html create mode 100644 ndarray/fancy/get.js.html create mode 100644 ndarray/fancy/get_slice.js.html create mode 100644 ndarray/fancy/get_value.js.html create mode 100644 ndarray/fancy/prop2slice.0d.js.html create mode 100644 ndarray/fancy/prop2slice.1d.js.html create mode 100644 ndarray/fancy/prop2slice.nd.js.html create mode 100644 ndarray/fancy/set.js.html create mode 100644 ndarray/fancy/set_slice.js.html create mode 100644 ndarray/fancy/set_value.js.html diff --git a/ndarray/base/coverage.ndjson b/ndarray/base/coverage.ndjson index 901a0ac5e..55a7806bf 100644 --- a/ndarray/base/coverage.ndjson +++ b/ndarray/base/coverage.ndjson @@ -1 +1,2 @@ [631,631,100,1,1,100,0,0,100,631,631,100,"fcbe4c18fd4ebfad0466b56b4c19abda6cdb4c2b","2023-09-26 14:05:25 -0700"] +[640,640,100,1,1,100,0,0,100,640,640,100,"96076ff03dd2a72f44e9b0d623ce2dfc88dd2b11","2023-09-29 19:38:19 -0700"] diff --git a/ndarray/base/index.html b/ndarray/base/index.html index 01cd1743d..78a45316b 100644 --- a/ndarray/base/index.html +++ b/ndarray/base/index.html @@ -25,7 +25,7 @@

All files ndarray/base/lib

100% Statements - 631/631 + 640/640
@@ -46,7 +46,7 @@

All files ndarray/base/lib

100% Lines - 631/631 + 640/640
@@ -84,13 +84,13 @@

All files ndarray/base/lib

100% - 631/631 + 640/640 100% 1/1 100% 0/0 100% - 631/631 + 640/640 @@ -101,7 +101,7 @@

All files ndarray/base/lib

+ + + + + + \ No newline at end of file diff --git a/ndarray/base/slice-assign/index.js.html b/ndarray/base/slice-assign/index.js.html new file mode 100644 index 000000000..446fb740e --- /dev/null +++ b/ndarray/base/slice-assign/index.js.html @@ -0,0 +1,322 @@ + + + + + + Code coverage report for ndarray/base/slice-assign/lib/index.js + + + + + + + + + +
+
+

All files / ndarray/base/slice-assign/lib index.js

+
+ +
+ 100% + Statements + 79/79 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 79/79 +
+ + +
+

+ 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 +801x +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) 2023 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';
+ 
+/**
+* Assign element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.
+*
+* @module @stdlib/ndarray/base/slice-assign
+*
+* @example
+* var Slice = require( '@stdlib/slice/ctor' );
+* var MultiSlice = require( '@stdlib/slice/multi' );
+* var ndarray = require( '@stdlib/ndarray/ctor' );
+* var ndzeros = require( '@stdlib/ndarray/zeros' );
+* var ndarray2array = require( '@stdlib/ndarray/to-array' );
+* var sliceAssign = require( '@stdlib/ndarray/base/slice-assign' );
+*
+* // Define an input array:
+* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
+* var shape = [ 3, 2 ];
+* var strides = [ 2, 1 ];
+* var offset = 0;
+*
+* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
+* // returns <ndarray>
+*
+* var sh = x.shape;
+* // returns [ 3, 2 ]
+*
+* var arr = ndarray2array( x );
+* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
+*
+* // Define an output array:
+* var y = ndzeros( [ 2, 3, 2 ], {
+*     'dtype': x.dtype
+* });
+*
+* // Create a slice:
+* var s0 = null;
+* var s1 = new Slice( null, null, -1 );
+* var s2 = new Slice( null, null, -1 );
+* var s = new MultiSlice( s0, s1, s2 );
+* // returns <MultiSlice>
+*
+* // Perform assignment:
+* var out = sliceAssign( x, y, s, false );
+* // returns <ndarray>
+*
+* var bool = ( out === y );
+* // returns true
+*
+* arr = ndarray2array( y );
+* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]
+*/
+ 
+// MODULES //
+ 
+var main = require( './main.js' );
+ 
+ 
+// EXPORTS //
+ 
+module.exports = main;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/base/slice-assign/main.js.html b/ndarray/base/slice-assign/main.js.html new file mode 100644 index 000000000..0112b3460 --- /dev/null +++ b/ndarray/base/slice-assign/main.js.html @@ -0,0 +1,502 @@ + + + + + + Code coverage report for ndarray/base/slice-assign/lib/main.js + + + + + + + + + +
+
+

All files / ndarray/base/slice-assign/lib main.js

+
+ +
+ 100% + Statements + 139/139 +
+ + +
+ 100% + Branches + 11/11 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 139/139 +
+ + +
+

+ 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 +1401x +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 +79x +79x +79x +79x +79x +79x +79x +79x +79x +79x +79x +73x +73x +2x +2x +73x +71x +71x +71x +73x +6x +6x +2x +2x +6x +4x +4x +75x +75x +75x +75x +75x +75x +75x +75x +75x +75x +75x +79x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 isSafeCast = require( '@stdlib/ndarray/base/assert/is-safe-data-type-cast' );
+var isSameKindCast = require( '@stdlib/ndarray/base/assert/is-same-kind-data-type-cast' );
+var isFloatingPointDataType = require( '@stdlib/ndarray/base/assert/is-floating-point-data-type' );
+var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
+var isRealDataType = require( '@stdlib/ndarray/base/assert/is-real-data-type' );
+var broadcast = require( '@stdlib/ndarray/base/broadcast-array' );
+var unary = require( '@stdlib/ndarray/base/unary' ); // TODO: replace with `@stdlib/ndarray/base/assign` and add native add-on support
+var identity = require( '@stdlib/utils/identity-function' ); // TODO: remove once use `@stdlib/ndarray/base/assign`
+var castReturn = require( '@stdlib/complex/base/cast-return' );
+var complexCtors = require( '@stdlib/complex/ctors' );
+var slice = require( '@stdlib/ndarray/base/slice' );
+var format = require( '@stdlib/string/format' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.
+*
+* @param {ndarray} x - input array
+* @param {ndarray} y - output array
+* @param {MultiSlice} s - multi-slice object for the output array
+* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking
+* @throws {RangeError} number of slice dimensions must match the number of array dimensions
+* @throws {RangeError} slice exceeds array bounds
+* @throws {Error} input array must be broadcast compatible with an output array view
+* @throws {TypeError} input array cannot be safely cast to the output array data type
+* @returns {ndarray} output array
+*
+* @example
+* var Slice = require( '@stdlib/slice/ctor' );
+* var MultiSlice = require( '@stdlib/slice/multi' );
+* var ndarray = require( '@stdlib/ndarray/ctor' );
+* var ndzeros = require( '@stdlib/ndarray/zeros' );
+* var ndarray2array = require( '@stdlib/ndarray/to-array' );
+*
+* // Define an input array:
+* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
+* var shape = [ 3, 2 ];
+* var strides = [ 2, 1 ];
+* var offset = 0;
+*
+* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
+* // returns <ndarray>
+*
+* var sh = x.shape;
+* // returns [ 3, 2 ]
+*
+* var arr = ndarray2array( x );
+* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
+*
+* // Define an output array:
+* var y = ndzeros( [ 2, 3, 2 ], {
+*     'dtype': x.dtype
+* });
+*
+* // Create a slice:
+* var s0 = null;
+* var s1 = new Slice( null, null, -1 );
+* var s2 = new Slice( null, null, -1 );
+* var s = new MultiSlice( s0, s1, s2 );
+* // returns <MultiSlice>
+*
+* // Perform assignment:
+* var out = sliceAssign( x, y, s, false );
+* // returns <ndarray>
+*
+* var bool = ( out === y );
+* // returns true
+*
+* arr = ndarray2array( y );
+* // returns [ [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ], [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ]
+*/
+function sliceAssign( x, y, s, strict ) {
+	var view;
+	var fcn;
+	var xdt;
+	var ydt;
+ 
+	xdt = x.dtype;
+	ydt = y.dtype;
+ 
+	// Safe casts are always allowed...
+	if ( isSafeCast( xdt, ydt ) ) {
+		// Check for real-to-complex conversion...
+		if ( isRealDataType( xdt ) && isComplexDataType( ydt ) ) {
+			// Need to cast a real number to a complex number:
+			fcn = castReturn( identity, 1, complexCtors( ydt ) );
+		} else {
+			// Should only be real->real and complex->complex:
+			fcn = identity;
+		}
+	}
+	// Allow same kind casts (i.e., downcasts) only when the output data type is floating-point...
+	else if ( isFloatingPointDataType( ydt ) && isSameKindCast( xdt, ydt ) ) {
+		// At this point, we know that the input data type and output data type are of the same "kind" (e.g., real->real and complex->complex), and, thus, we don't need to perform any special conversions:
+		fcn = identity;
+	} else {
+		throw new TypeError( format( 'invalid argument. Input array values cannot be safely cast to the output array data type. Data types: [%s, %s].', xdt, ydt ) );
+	}
+	// Resolve a mutable output array view:
+	view = slice( y, s, strict, true );
+ 
+	// Broadcast the input array:
+	x = broadcast( x, view.shape );
+ 
+	// Set elements from `x` in `y`:
+	unary( [ x, view ], fcn );
+ 
+	// Return the original output array:
+	return y;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = sliceAssign;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/base/slice/coverage.ndjson b/ndarray/base/slice/coverage.ndjson index 07b919936..f805e5e8a 100644 --- a/ndarray/base/slice/coverage.ndjson +++ b/ndarray/base/slice/coverage.ndjson @@ -5,3 +5,4 @@ [430,430,100,29,29,100,5,5,100,430,430,100,"a25cd619b407e68227846262766615d499d310c9","2023-09-27 00:50:46 -0700"] [430,430,100,29,29,100,5,5,100,430,430,100,"976d69a7c27bad4d43cfaf8bdd0d2838363a6d91","2023-09-27 01:14:43 -0700"] [430,430,100,29,29,100,5,5,100,430,430,100,"70088a43e057dc3227ecd7180491e165ffd31c51","2023-09-27 01:32:43 -0700"] +[399,399,100,27,27,100,4,4,100,399,399,100,"96076ff03dd2a72f44e9b0d623ce2dfc88dd2b11","2023-09-29 19:38:19 -0700"] diff --git a/ndarray/base/slice/empty.js.html b/ndarray/base/slice/empty.js.html index c4df80cb5..71b7d0d64 100644 --- a/ndarray/base/slice/empty.js.html +++ b/ndarray/base/slice/empty.js.html @@ -25,7 +25,7 @@

All files / ndarra
100% Statements - 56/56 + 58/58
@@ -46,7 +46,7 @@

All files / ndarra
100% Lines - 56/56 + 58/58
@@ -119,7 +119,9 @@

All files / ndarra 54 55 56 -571x +57 +58 +591x 1x 1x 1x @@ -170,6 +172,8 @@

All files / ndarra 4x 5x 5x +5x +5x 1x 1x 1x @@ -199,7 +203,6 @@

All files / ndarra   var buffer = require( '@stdlib/ndarray/base/buffer' ); var zeros = require( '@stdlib/array/base/zeros' ); -var options = require( './options.js' );     // MAIN // @@ -212,9 +215,10 @@

All files / ndarra * @param {string} dtype - array data type * @param {NonNegativeIntegerArray} shape - array shape * @param {string} order - layout order +* @param {boolean} readonly - boolean indicating whether a returned array should be read-only * @returns {ndarray} empty ndarray */ -function empty( ctor, dtype, shape, order ) { +function empty( ctor, dtype, shape, order, readonly ) { var strides; var ndims;   @@ -224,7 +228,9 @@

All files / ndarra } else { strides = zeros( ndims ); } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len + return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { + 'readonly': readonly + }); }     @@ -238,7 +244,7 @@

All files / ndarra + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/get_slice.js.html b/ndarray/fancy/get_slice.js.html new file mode 100644 index 000000000..4526ca06c --- /dev/null +++ b/ndarray/fancy/get_slice.js.html @@ -0,0 +1,265 @@ + + + + + + Code coverage report for ndarray/fancy/lib/get_slice.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib get_slice.js

+
+ +
+ 76.66% + Statements + 46/60 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 76.66% + Lines + 46/60 +
+ + +
+

+ 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 +6133x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 slice = require( '@stdlib/ndarray/base/slice' );
+var errMessage = require( './error_message.js' );
+var errConstructor = require( './error_constructor.js' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Returns an ndarray view.
+*
+* @private
+* @param {Object} target - target object
+* @param {string} property - property name
+* @param {Object} receiver - the proxy object or an object inheriting from the proxy
+* @param {Function} prop2slice - function for converting an indexing expression to a slice
+* @throws {Error} invalid slice operation
+* @throws {RangeError} number of slice dimensions must match the number of array dimensions
+* @returns {FancyArray} result
+*/
+function getSlice( target, property, receiver, prop2slice ) { // eslint-disable-line stdlib/jsdoc-require-throws-tags
+	var strict;
+	var E;
+	var s;
+
+	strict = false; // TODO: support strict mode
+	s = prop2slice( target, property, strict );
+	try {
+		return slice( receiver, s, strict, false );
+	} catch ( err ) {
+		E = errConstructor( err );
+		throw new E( errMessage( err.message ) );
+	}
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = getSlice;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/get_value.js.html b/ndarray/fancy/get_value.js.html new file mode 100644 index 000000000..82820d838 --- /dev/null +++ b/ndarray/fancy/get_value.js.html @@ -0,0 +1,280 @@ + + + + + + Code coverage report for ndarray/fancy/lib/get_value.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib get_value.js

+
+ +
+ 100% + Statements + 65/65 +
+ + +
+ 85.71% + Branches + 6/7 +
+ + +
+ 100% + Functions + 2/2 +
+ + +
+ 100% + Lines + 65/65 +
+ + +
+

+ 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 +6633x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +3983x +3983x +3983x +3899x +3899x +84x +84x +84x +84x +84x +84x +84x +84x +84x +3879x +3879x +3879x +3879x +3879x +8226x +8226x +3879x +3879x +3983x +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 isFunction = require( '@stdlib/assert/is-function' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Returns the property value associated with a specified property.
+*
+* @private
+* @param {Object} target - target object
+* @param {(string|symbol)} property - property
+* @param {Object} receiver - the proxy object or an object inheriting from the proxy
+* @returns {*} result
+*/
+function getValue( target, property, receiver ) {
+	var value = target[ property ];
+	if ( isFunction( value ) ) {
+		return wrapper;
+	}
+	return value;
+ 
+	/**
+	* Method wrapper.
+	*
+	* @private
+	* @returns {*} results
+	*/
+	function wrapper() {
+		var args;
+		var i;
+ 
+		args = [];
+		for ( i = 0; i < arguments.length; i++ ) {
+			args.push( arguments[ i ] );
+		}
+		return value.apply( ( this === receiver ) ? target : this, args ); // eslint-disable-line no-invalid-this
+	}
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = getValue;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/has_property.js.html b/ndarray/fancy/has_property.js.html index ba10cb2c1..3cda9ac71 100644 --- a/ndarray/fancy/has_property.js.html +++ b/ndarray/fancy/has_property.js.html @@ -115,58 +115,58 @@

All files / ndarray/f 50 51 52 -532x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x +5333x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x  
/**
 * @license Apache-2.0
 *
@@ -226,7 +226,7 @@ 

All files / ndarray/f + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/prop2slice.1d.js.html b/ndarray/fancy/prop2slice.1d.js.html new file mode 100644 index 000000000..ed11172f5 --- /dev/null +++ b/ndarray/fancy/prop2slice.1d.js.html @@ -0,0 +1,445 @@ + + + + + + Code coverage report for ndarray/fancy/lib/prop2slice.1d.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib prop2slice.1d.js

+
+ +
+ 41.66% + Statements + 50/120 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 41.66% + Lines + 50/120 +
+ + +
+

+ 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 +12133x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 trim = require( '@stdlib/string/base/trim' );
+var replace = require( '@stdlib/string/base/replace' );
+var MultiSlice = require( '@stdlib/slice/multi' );
+var str2multislice = require( '@stdlib/slice/base/str2multislice' );
+var seq2multislice = require( '@stdlib/slice/base/seq2multislice' );
+var str2slice = require( '@stdlib/slice/base/str2slice' );
+var format = require( '@stdlib/string/format' );
+var RE_INTEGER = require( './re_integer.js' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Converts a one-dimensional ndarray indexing expression to a slice.
+*
+* @private
+* @param {Object} target - target object
+* @param {string} property - property name
+* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking
+* @throws {Error} invalid slice operation
+* @throws {RangeError} number of slice dimensions must match the number of array dimensions
+* @returns {MultiSlice} multi-slice object
+*/
+function prop2slice( target, property, strict ) {
+	var shape;
+	var prop;
+	var ch;
+	var s;
+
+	prop = trim( property );
+
+	// Retrieve the first character in order to to detect how a slice operation was specified:
+	ch = prop[ 0 ];
+
+	// Case: slice
+	if ( ch === 'S' ) {
+		// Convert the string to a slice object:
+		s = str2slice( property );
+		if ( s === null ) {
+			throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+		}
+		// Create a multi-slice:
+		s = new MultiSlice( s );
+	}
+	// Case: multi-slice
+	else if ( ch === 'M' ) {
+		// Convert the string to a slice object:
+		s = str2multislice( prop );
+		if ( s === null ) {
+			throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+		}
+	}
+	// Case: integer
+	else if ( RE_INTEGER.test( prop ) ) {
+		// Convert the string to a numeric value:
+		s = parseInt( prop, 10 );
+
+		// Create a multi-slice:
+		s = new MultiSlice( s );
+	}
+	// Case: subsequence string
+	else if ( prop.length > 0 ) {
+		shape = target.shape;
+		s = seq2multislice( prop, shape, true );
+		if ( s.code ) {
+			if ( s.code === 'ERR_SLICE_INVALID_INCREMENT' ) {
+				throw new Error( format( 'invalid operation. A subsequence increment must be a non-zero integer. Value: `%s`.', property ) );
+			}
+			if ( s.code === 'ERR_SLICE_INVALID_ELLIPSIS' ) {
+				throw new Error( format( 'invalid operation. A subsequence may only include a single ellipsis. Value: `%s`.', property ) );
+			}
+			if ( s.code === 'ERR_SLICE_INVALID_SUBSEQUENCE' ) {
+				throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+			}
+			if ( s.code === 'ERR_SLICE_TOO_MANY_DIMENSIONS' ) {
+				throw new RangeError( format( 'invalid operation. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', target.shape.join( ',' ), replace( prop, /\.\.\.,/, '' ).split( ',' ).length ) );
+			}
+			// NOTE: the following error check must come last due to fall-through when in non-strict mode...
+			if ( s.code === 'ERR_SLICE_OUT_OF_BOUNDS' ) {
+				if ( strict ) {
+					throw new RangeError( format( 'invalid operation. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );
+				}
+				// Repeat parsing, this time allowing for out-of-bounds slices:
+				s = seq2multislice( prop, shape, false );
+			}
+		}
+	}
+	// Case: empty string
+	else {
+		throw new RangeError( format( 'invalid operation. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', target.shape.join( ',' ), 0 ) );
+	}
+	return s;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = prop2slice;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/prop2slice.nd.js.html b/ndarray/fancy/prop2slice.nd.js.html new file mode 100644 index 000000000..9f1713cf0 --- /dev/null +++ b/ndarray/fancy/prop2slice.nd.js.html @@ -0,0 +1,382 @@ + + + + + + Code coverage report for ndarray/fancy/lib/prop2slice.nd.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib prop2slice.nd.js

+
+ +
+ 48.48% + Statements + 48/99 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 48.48% + Lines + 48/99 +
+ + +
+

+ 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 +10033x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 trim = require( '@stdlib/string/base/trim' );
+var str2multislice = require( '@stdlib/slice/base/str2multislice' );
+var seq2multislice = require( '@stdlib/slice/base/seq2multislice' );
+var sargs2multislice = require( '@stdlib/slice/base/sargs2multislice' );
+var format = require( '@stdlib/string/format' );
+var RE_SUBSEQ = require( './re_subseq.js' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Converts an n-dimensional ndarray indexing expression to a slice.
+*
+* @private
+* @param {Object} target - target object
+* @param {string} property - property name
+* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking
+* @throws {Error} invalid slice operation
+* @throws {RangeError} number of slice dimensions must match the number of array dimensions
+* @returns {MultiSlice} multi-slice object
+*/
+function prop2slice( target, property, strict ) {
+	var shape;
+	var prop;
+	var ch;
+	var s;
+
+	prop = trim( property );
+
+	// Retrieve the first character in order to to detect how a slice operation was specified:
+	ch = prop[ 0 ];
+
+	// Case: multi-slice (e.g., 'MultiSlice(Slice(0,10,2),null,2,Slice(10,5,-1))')
+	if ( ch === 'M' ) {
+		s = str2multislice( prop );
+		if ( s === null ) {
+			throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+		}
+	}
+	// Case: subsequence string (e.g., '...' or ':10,1,::-1,:,-5,2::3')
+	else if ( RE_SUBSEQ.test( prop ) || prop === '...' ) {
+		shape = target.shape;
+		s = seq2multislice( prop, shape, true );
+		if ( s.code ) {
+			if ( s.code === 'ERR_SLICE_INVALID_INCREMENT' ) {
+				throw new Error( format( 'invalid operation. A subsequence increment must be a non-zero integer. Value: `%s`.', property ) );
+			}
+			if ( s.code === 'ERR_SLICE_INVALID_ELLIPSIS' ) {
+				throw new Error( format( 'invalid operation. A subsequence may only include a single ellipsis. Value: `%s`.', property ) );
+			}
+			if ( s.code === 'ERR_SLICE_INVALID_SUBSEQUENCE' ) {
+				throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+			}
+			// NOTE: the following error check must come last due to fall-through when in non-strict mode...
+			if ( s.code === 'ERR_SLICE_OUT_OF_BOUNDS' ) {
+				if ( strict ) {
+					throw new RangeError( format( 'invalid operation. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );
+				}
+				// Repeat parsing, this time allowing for out-of-bounds slices:
+				s = seq2multislice( prop, shape, false );
+			}
+		}
+	}
+	// Case: array syntax (e.g., [ Slice(0,10,1), null, Slice(4,null,-1) ]) or Slice or integer or arbitrary string (where the latter three are not valid for >2d arrays)
+	else {
+		s = sargs2multislice( prop );
+		if ( s === null ) {
+			throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
+		}
+	}
+	return s;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = prop2slice;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/re_integer.js.html b/ndarray/fancy/re_integer.js.html index e659cb2e5..7c334c5cc 100644 --- a/ndarray/fancy/re_integer.js.html +++ b/ndarray/fancy/re_integer.js.html @@ -110,53 +110,53 @@

All files / ndarray/f 45 46 47 -482x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x +4833x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x  
/**
 * @license Apache-2.0
 *
@@ -211,7 +211,7 @@ 

All files / ndarray/f + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/set_slice.js.html b/ndarray/fancy/set_slice.js.html new file mode 100644 index 000000000..48f9c0da7 --- /dev/null +++ b/ndarray/fancy/set_slice.js.html @@ -0,0 +1,598 @@ + + + + + + Code coverage report for ndarray/fancy/lib/set_slice.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib set_slice.js

+
+ +
+ 45.02% + Statements + 77/171 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/2 +
+ + +
+ 45.02% + Lines + 77/171 +
+ + +
+

+ 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 +17233x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +  +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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 sliceAssign = require( '@stdlib/ndarray/base/slice-assign' );
+var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
+var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
+var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
+var isComplexLike = require( '@stdlib/assert/is-complex-like' );
+var isComplexDataType = require( '@stdlib/ndarray/base/assert/is-complex-floating-point-data-type' );
+var isFloatingDataType = require( '@stdlib/ndarray/base/assert/is-floating-point-data-type' );
+var isUnsignedIntegerDataType = require( '@stdlib/ndarray/base/assert/is-unsigned-integer-data-type' );
+var isSignedIntegerDataType = require( '@stdlib/ndarray/base/assert/is-signed-integer-data-type' );
+var isSafeCast = require( '@stdlib/ndarray/base/assert/is-safe-data-type-cast' );
+var INT8_MAX = require( '@stdlib/constants/int8/max' );
+var INT16_MAX = require( '@stdlib/constants/int16/max' );
+var INT32_MAX = require( '@stdlib/constants/int32/max' );
+var minDataType = require( '@stdlib/ndarray/min-dtype' );
+var complexDataType = require( '@stdlib/complex/dtype' );
+var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
+var format = require( '@stdlib/string/format' );
+var errMessage = require( './error_message.js' );
+var errConstructor = require( './error_constructor.js' );
+ 
+ 
+// FUNCTIONS //
+ 
+/**
+* Returns an options object for creating an ndarray from a scalar value.
+*
+* @private
+* @param {string} dtype - output array data type
+* @returns {Object} options
+*/
+function options( dtype ) {
+	return {
+		'dtype': dtype
+	};
+}
+ 
+ 
+// MAIN //
+ 
+/**
+* Sets element values belonging to the ndarray view specified by an indexing expression.
+*
+* @private
+* @param {Object} target - target object
+* @param {string} property - indexing expression
+* @param {*} value - new value
+* @param {Object} receiver - the proxy object or an object inheriting from the proxy
+* @param {Function} prop2slice - function for converting an indexing expression to a slice
+* @throws {Error} invalid slice operation
+* @throws {RangeError} number of slice dimensions must match the number of array dimensions
+* @throws {Error} assigned value must be broadcast compatible with target array view
+* @throws {TypeError} assigned value cannot be safely cast to the target array data type
+* @throws {TypeError} target array must have a supported data type
+* @returns {boolean} boolean indicating whether assignment succeeded
+*/
+function setSlice( target, property, value, receiver, prop2slice ) { // eslint-disable-line stdlib/jsdoc-require-throws-tags
+	var strict;
+	var vdt;
+	var dt;
+	var E;
+	var s;
+
+	if ( !isndarrayLike( value ) ) {
+		dt = target.dtype;
+
+		// If the target array data type is "generic", we can just go ahead and "cast" to the target array data type...
+		if ( dt === 'generic' ) {
+			value = scalar2ndarray( value, options( dt ) );
+		}
+		// If the input value is real-valued number, we need to inspect the value to determine whether we can safely cast the value to the target array data type...
+		else if ( isNumber( value ) ) {
+			// If the target array has a floating-point data type, we can just go ahead and cast the input scalar to the target array data type...
+			if ( isFloatingDataType( dt ) ) {
+				value = scalar2ndarray( value, options( dt ) );
+			}
+			// If the target array has an unsigned integer data type, then the assigned value must be a compatible nonnegative integer value...
+			else if ( isUnsignedIntegerDataType( dt ) ) {
+				vdt = minDataType( value );
+				if ( isSafeCast( vdt, dt ) ) {
+					value = scalar2ndarray( value, options( dt ) );
+				} else {
+					throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dt ) );
+				}
+			}
+			// If the target array has a signed integer data type, then the assigned value must be a compatible integer value...
+			else if ( isSignedIntegerDataType( dt ) ) {
+				if ( !isInteger( value ) ) {
+					throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', minDataType( value ), dt ) );
+				}
+				// Manually resolve the minimum data type of the closest "kind" necessary for storing a scalar value, as `minDataType()` defaults to unsigned integer data types when a scalar value is greater than or equal to zero...
+				if ( value < 0 ) {
+					vdt = minDataType( value );
+				} else if ( value <= INT8_MAX ) { // TODO: consider moving this logic to `@stdlib/ndarray/base/min-signed-intger-dtype` where the interface can assume that `value` is integer-valued
+					vdt = 'int8';
+				} else if ( value <= INT16_MAX ) {
+					vdt = 'int16';
+				} else if ( value <= INT32_MAX ) {
+					vdt = 'int32';
+				} else {
+					vdt = 'float64';
+				}
+				if ( isSafeCast( vdt, dt ) ) {
+					value = scalar2ndarray( value, options( dt ) );
+				} else {
+					throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dt ) );
+				}
+			}
+			// If the target array has "binary" data type, then the assigned value must be a compatible nonnegative integer value...
+			else if ( dt === 'binary' ) {
+				vdt = minDataType( value );
+				if ( vdt === 'uint8' ) {
+					value = scalar2ndarray( value, options( dt ) );
+				} else {
+					throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dt ) );
+				}
+			}
+			// If we reach this point, we must be dealing with an unexpected target array data type...
+			else {
+				// Raise an exception in order to flag that, in order to perform assignment, we need to add explicit support for additional data types:
+				throw new TypeError( format( 'invalid operation. Unsupported target array data type. Data type: `%s`.', dt ) );
+			}
+		}
+		// If the target array is not "generic" and the input value is a complex number, then the target array data type must also have a complex number data type...
+		else if ( isComplexLike( value ) ) {
+			if ( !isComplexDataType( dt ) ) {
+				throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dt ) );
+			}
+			value = scalar2ndarray( value, options( dt ) );
+		}
+		// If the target array is not "generic" and the input value is neither a real- or complex-valued number, raise an exception in order to flag that, in order to perform assignment, we need to add explicit support for additional data types...
+		else {
+			throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dt ) );
+		}
+	}
+	strict = false; // TODO: support strict mode
+	s = prop2slice( target, property, strict );
+	try {
+		sliceAssign( value, receiver, s, strict );
+		return true;
+	} catch ( err ) {
+		E = errConstructor( err );
+		throw new E( errMessage( err.message ) );
+	}
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = setSlice;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/fancy/set_value.js.html b/ndarray/fancy/set_value.js.html new file mode 100644 index 000000000..2f9afeb96 --- /dev/null +++ b/ndarray/fancy/set_value.js.html @@ -0,0 +1,208 @@ + + + + + + Code coverage report for ndarray/fancy/lib/set_value.js + + + + + + + + + +
+
+

All files / ndarray/fancy/lib set_value.js

+
+ +
+ 90.24% + Statements + 37/41 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 90.24% + Lines + 37/41 +
+ + +
+

+ 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 +4233x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +33x +  +  +  +  +33x +33x +33x +33x +33x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 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';
+ 
+// MAIN //
+ 
+/**
+* Sets the value associated with a specified property.
+*
+* @private
+* @param {Object} target - target object
+* @param {string} property - property
+* @param {*} value - new value
+* @param {Object} receiver - the proxy object or an object inheriting from the proxy
+* @returns {boolean} boolean indicating whether assignment succeeded
+*/
+function setValue( target, property, value ) {
+	target[ property ] = value;
+	return true;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = setValue;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/ndarray/slice/coverage.ndjson b/ndarray/slice/coverage.ndjson index 9bdc45922..8912b48b0 100644 --- a/ndarray/slice/coverage.ndjson +++ b/ndarray/slice/coverage.ndjson @@ -2,3 +2,4 @@ [216,216,100,25,25,100,1,1,100,216,216,100,"e11b04813691e71b939decf1e053f0669ead8058","2023-09-27 17:58:49 -0700"] [216,216,100,25,25,100,1,1,100,216,216,100,"3574c0afcb1eb663462ecf5d220a4ede191b96bc","2023-09-27 18:00:14 -0700"] [216,216,100,25,25,100,1,1,100,216,216,100,"d81786be3cf34d964bfe45ba25704228af41c56a","2023-09-27 18:00:55 -0700"] +[216,216,100,25,25,100,1,1,100,216,216,100,"96076ff03dd2a72f44e9b0d623ce2dfc88dd2b11","2023-09-29 19:38:19 -0700"] diff --git a/ndarray/slice/index.html b/ndarray/slice/index.html index e4b48aa92..d1ed9c401 100644 --- a/ndarray/slice/index.html +++ b/ndarray/slice/index.html @@ -116,7 +116,7 @@

All files ndarray/slice/lib