From f5f669fe49db4cb57103fb1c5f4ba2532bf9011b Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 23 Sep 2023 22:50:57 -0700 Subject: [PATCH] refactor: use base utility to construct MultiSlice from args array --- .../@stdlib/ndarray/fancy/lib/get.nd.js | 6 +- .../@stdlib/ndarray/fancy/lib/slice_start.js | 4 +- .../ndarray/fancy/lib/slice_strides.js | 4 +- .../@stdlib/ndarray/fancy/lib/view.nd.js | 2 +- .../fancy/lib/wrap_multislice_arguments.js | 62 ------------------- 5 files changed, 8 insertions(+), 70 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ndarray/fancy/lib/wrap_multislice_arguments.js diff --git a/lib/node_modules/@stdlib/ndarray/fancy/lib/get.nd.js b/lib/node_modules/@stdlib/ndarray/fancy/lib/get.nd.js index c14fb23ffc5..8b324a89852 100644 --- a/lib/node_modules/@stdlib/ndarray/fancy/lib/get.nd.js +++ b/lib/node_modules/@stdlib/ndarray/fancy/lib/get.nd.js @@ -24,10 +24,10 @@ var isFunction = require( '@stdlib/assert/is-function' ); 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 hasProperty = require( './has_property.js' ); var RE_SUBSEQ = require( './re_subseq.js' ); -var multisliceWrap = require( './wrap_multislice_arguments.js' ); var sliceView = require( './view.nd.js' ); var empty = require( './empty.js' ); @@ -104,9 +104,9 @@ function get( target, property, receiver ) { } // Case: array syntax (e.g., [ Slice(0,10,1), null, Slice(4,null,-1) ]) - // TODO: => @stdlib/ndarray/base/slice: return slice( receiver, str2multislice( multisliceWrap( prop ) ).data ); // TODO: handle `null` + // TODO: => @stdlib/ndarray/base/slice: return slice( receiver, sargs2multislice( prop ).data ); // TODO: handle `null` - return sliceView( target, '['+property+']', receiver, str2multislice( multisliceWrap( prop ) ) ); + return sliceView( target, '['+property+']', receiver, sargs2multislice( prop ) ); /** * Method wrapper. diff --git a/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_start.js b/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_start.js index 79cf3f5d75d..435ddf8273c 100644 --- a/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_start.js +++ b/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_start.js @@ -26,14 +26,14 @@ var sub2ind = require( '@stdlib/ndarray/base/sub2ind' ); // MAIN // /** -* Resolves the linear index of the first element indexed by a multi-slice. +* Resolves the linear index of the first element indexed by a normalized multi-slice. * * ## Notes * * - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`. * * @private -* @param {MultiSlice} slice - multi-slice object +* @param {MultiSlice} slice - normalized multi-slice object * @param {NonNegativeIntegerArray} shape - array shape * @param {IntegerArray} strides - array strides * @param {NonNegativeInteger} offset - index offset diff --git a/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_strides.js b/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_strides.js index b8deb28c6b6..d53e4b09aad 100644 --- a/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_strides.js +++ b/lib/node_modules/@stdlib/ndarray/fancy/lib/slice_strides.js @@ -21,10 +21,10 @@ // MAIN // /** -* Resolves slice strides. +* Resolves slice strides for a provided normalized multi-slice object. * * @private -* @param {MultiSlice} slice - multi-slice object +* @param {MultiSlice} slice - normalized multi-slice object * @param {IntegerArray} strides - array strides * @param {NonNegativeIntegerArray} sdims - indices of non-reduced dimensions * @returns {IntegerArray} slice strides diff --git a/lib/node_modules/@stdlib/ndarray/fancy/lib/view.nd.js b/lib/node_modules/@stdlib/ndarray/fancy/lib/view.nd.js index 54ee091d215..78d9de77dc4 100644 --- a/lib/node_modules/@stdlib/ndarray/fancy/lib/view.nd.js +++ b/lib/node_modules/@stdlib/ndarray/fancy/lib/view.nd.js @@ -97,7 +97,7 @@ function sliceView( target, property, receiver, slice ) { return empty( ctor, dtype, take( sh, sdims ), order ); } // Resolve the index offset of the first element: - offset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); + offset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind // Remove reduced dimensions from the slice shape: sh = take( sh, sdims ); diff --git a/lib/node_modules/@stdlib/ndarray/fancy/lib/wrap_multislice_arguments.js b/lib/node_modules/@stdlib/ndarray/fancy/lib/wrap_multislice_arguments.js deleted file mode 100644 index 9f2f3703e42..00000000000 --- a/lib/node_modules/@stdlib/ndarray/fancy/lib/wrap_multislice_arguments.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @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 replace = require( '@stdlib/string/base/replace' ); - - -// MAIN // - -/** -* Returns string-serialized array elements as arguments to the MultiSlice constructor. -* -* @private -* @param {string} str - array elements serialized as a string -* @returns {string} wrapped arguments -* -* @example -* var args = wrap( ',Slice(0,10,1)' ); -* // returns 'MultiSlice(null,Slice(0,10,1))' -* -* @example -* var args = wrap( 'Slice(0,10,1),' ); -* // returns 'MultiSlice(Slice(0,10,1),null)' -* -* @example -* var args = wrap( 'Slice(0,10,1),,,Slice(0,10,1)' ); -* // returns 'MultiSlice(Slice(0,10,1),null,null,Slice(0,10,1))' -* -* @example -* var args = wrap( ',Slice(0,10,1),null,,Slice(2,9,2),null,' ); -* // returns 'MultiSlice(null,Slice(0,10,1),null,null,Slice(2,9,2),null,null)' -*/ -function wrap( str ) { - // In order to support `x[ [...] ]` syntax, we need to touch up the serialized string due to how `undefined` is serialized... - str = replace( str, /^,/, 'null,' ); // leading comma (e.g., [ void 0, Slice(0,10,1) ] => ',Slice(0,10,1)') - str = replace( str, /,$/, ',null' ); // trailing comma (e.g., [ Slice(0,10,1), void 0 ] => 'Slice(0,10,1),') - str = replace( str, /,(?=,)/g, ',null' ); // between commas (e.g., [ Slice(0,10,1), void 0, void 0, Slice(0,10,1) ] => 'Slice(0,10,1),,,Slice(0,10,1)') - return 'MultiSlice(' + str + ')'; -} - - -// EXPORTS // - -module.exports = wrap;