/* * @license Apache-2.0 * * Copyright (c) 2021 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. */ // TypeScript Version: 4.1 /// import { Collection } from '@stdlib/types/array'; import { ndarray, DataType, Mode, Order, Shape, Strides } from '@stdlib/types/ndarray'; import { Buffer } from 'buffer'; /** * Interface defining function options. */ interface Options { /** * Specifies how to handle a linear index which exceeds array dimensions (default: 'throw'). */ mode?: Mode; /** * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). */ submode?: Array; /** * Boolean indicating whether an array should be read-only (default: false). */ readonly?: boolean; } /** * Interface defining a FancyArray constructor which is both "newable" and "callable". */ interface Constructor { /** * Fancy array constructor. * * @param dtype - data type * @param buffer - data buffer * @param shape - array shape * @param strides - array strides * @param offset - index offset * @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) * @param options - function options * @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') * @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) * @param options.readonly - specifies whether an array should be read-only (default: false) * @throws `buffer` argument `get` and `set` properties must be functions * @throws `shape` argument must be an array-like object containing nonnegative integers * @throws `shape` argument length must equal the number of dimensions * @throws `strides` argument must be an array-like object containing integers * @throws `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`) * @throws for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0` * @throws `offset` argument must be a nonnegative integer * @throws `buffer` argument must be compatible with specified meta data * @throws must provide valid options * @throws too many dimensions * @returns an ndarray * * @example * 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 out = new FancyArray( 'generic', buffer, shape, strides, offset, 'row-major' ); */ new ( dtype: DataType, buffer: Collection | Buffer, shape: Shape, strides: Strides, offset: number, order: Order, options?: Options ): ndarray; /** * Fancy array constructor. * * @param dtype - data type * @param buffer - data buffer * @param shape - array shape * @param strides - array strides * @param offset - index offset * @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) * @param options - function options * @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') * @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) * @param options.readonly - specifies whether an array should be read-only (default: false) * @throws `buffer` argument `get` and `set` properties must be functions * @throws `shape` argument must be an array-like object containing nonnegative integers * @throws `shape` argument length must equal the number of dimensions * @throws `strides` argument must be an array-like object containing integers * @throws `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`) * @throws for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0` * @throws `offset` argument must be a nonnegative integer * @throws `buffer` argument must be compatible with specified meta data * @throws must provide valid options * @throws too many dimensions * @returns an ndarray * * @example * 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 out = FancyArray( 'generic', buffer, shape, strides, offset, 'row-major' ); */ ( dtype: DataType, buffer: Collection | Buffer, shape: Shape, strides: Strides, offset: number, order: Order, options?: Options ): ndarray; } /** * Fancy array constructor. * * @param dtype - data type * @param buffer - data buffer * @param shape - array shape * @param strides - array strides * @param offset - index offset * @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) * @param options - function options * @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') * @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) * @param options.readonly - specifies whether an array should be read-only (default: false) * @throws `buffer` argument `get` and `set` properties must be functions * @throws `shape` argument must be an array-like object containing nonnegative integers * @throws `shape` argument length must equal the number of dimensions * @throws `strides` argument must be an array-like object containing integers * @throws `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`) * @throws for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0` * @throws `offset` argument must be a nonnegative integer * @throws `buffer` argument must be compatible with specified meta data * @throws must provide valid options * @throws too many dimensions * @returns an ndarray * * @example * 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 out = new FancyArray( 'generic', buffer, shape, strides, offset, 'row-major' ); */ declare var ctor: Constructor; // EXPORTS // export = ctor;