|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +// MODULES // |
| 22 | + |
| 23 | +// var take = require( '@stdlib/ndarray/take' ); |
| 24 | + |
| 25 | +// var mskfilter = require( '@stdlib/ndarray/mskfilter' ); |
| 26 | + |
| 27 | +// var mskreject = require( '@stdlib/ndarray/mskreject' ); |
| 28 | + |
| 29 | +var format = require( '@stdlib/string/format' ); |
| 30 | +var prop2array = require( './prop2array.js' ); |
| 31 | + |
| 32 | + |
| 33 | +// MAIN // |
| 34 | + |
| 35 | +/** |
| 36 | +* Returns the elements specified by an ndarray index. |
| 37 | +* |
| 38 | +* @private |
| 39 | +* @param {ndarrayLike} target - target object |
| 40 | +* @param {string} property - index string |
| 41 | +* @param {Object} ctx - context object |
| 42 | +* @param {Object} ctx.cache - cache for resolving ndarray index objects |
| 43 | +* @param {Function} ctx.postGetArray - function to process a retrieved ndarray |
| 44 | +* @throws {Error} invalid ndarray index |
| 45 | +* @throws {RangeError} index exceeds ndarray bounds |
| 46 | +* @returns {ndarrayLike} result |
| 47 | +*/ |
| 48 | +function getElements( target, property, ctx ) { |
| 49 | + var idx = prop2array( property, ctx.cache ); |
| 50 | + if ( idx.type === 'int' ) { |
| 51 | + // FIXME: handle the various "kinds" of index arrays (e.g., "linear" and "cartesian") |
| 52 | + |
| 53 | + // return ctx.postGetArray( take( target, idx.data ) ); |
| 54 | + return NaN; // FIXME |
| 55 | + } |
| 56 | + if ( idx.type === 'bool' ) { |
| 57 | + // return ctx.postGetArray( mskfilter( target, idx.data ) ); |
| 58 | + return NaN; // FIXME |
| 59 | + } |
| 60 | + if ( idx.type === 'mask' ) { |
| 61 | + // return ctx.postGetArray( mskreject( target, idx.data ) ); |
| 62 | + return NaN; // FIXME |
| 63 | + } |
| 64 | + throw new Error( format( 'invalid operation. Unrecognized ndarray index type. Value: `%s`.', idx.type ) ); |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +// EXPORTS // |
| 69 | + |
| 70 | +module.exports = getElements; |
0 commit comments