diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md index 0daeb387947c..918d96de88d1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/README.md @@ -144,6 +144,163 @@ console.log( ndarray2array( v ) ); + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/dvander.h" +``` + +#### stdlib_blas_ext_dvander( arrays ) + +Generates a double-precision floating-point Vandermonde matrix. + +```c +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include + +// Create an input ndarray: +double dataX[] = { 1.0, 2.0, 3.0 }; +int64_t shapeX[] = { 3 }; +int64_t stridesX[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, 1, shapeX, stridesX, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Create an output ndarray: +double dataOut[ 9 ] = { 0.0 }; +int64_t shapeOut[] = { 3, 3 }; +int64_t stridesOut[] = { 3 * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + +struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, 2, shapeOut, stridesOut, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes ); + +// Create an ndarray containing the mode: +const double mdata[] = { 1.0 }; +int64_t mstrides[] = { 0 }; + +struct ndarray *mode = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)mdata, 0, NULL, mstrides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Perform computation: +const struct ndarray *arrays[] = { x, out, mode }; +stdlib_blas_ext_dvander( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( out ); +stdlib_ndarray_free( mode ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a one-dimensional input ndarray. + - `[inout] struct ndarray*` a two-dimensional output ndarray. + - `[in] struct ndarray*` a zero-dimensional ndarray specifying the mode. + +```c +void stdlib_blas_ext_dvander( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/dvander.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create an input vector: + double dataX[] = { 1.0, 2.0, 3.0 }; + int64_t shapeX[] = { 3 }; + int64_t stridesX[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR }; + + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, 1, shapeX, stridesX, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + + // Create an output matrix: + double dataOut[ 9 ] = { 0.0 }; + int64_t shapeOut[] = { 3, 3 }; + int64_t stridesOut[] = { 3 * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, 2, shapeOut, stridesOut, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes ); + + // Create mode scalar ndarray: + const double mdata[] = { 1.0 }; + int64_t mstrides[] = { 0 }; + + struct ndarray *mode = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)mdata, 0, NULL, mstrides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + if ( x == NULL || out == NULL || mode == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + const struct ndarray *arrays[] = { x, out, mode }; + stdlib_blas_ext_dvander( arrays ); + + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < 3; j++ ) { + printf( "out[ %i, %i ] = %lf\n", i, j, dataOut[ ( i * 3 ) + j ] ); + } + } + + stdlib_ndarray_free( x ); + stdlib_ndarray_free( out ); + stdlib_ndarray_free( mode ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/benchmark.native.js new file mode 100644 index 000000000000..4f573677adf2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/benchmark.native.js @@ -0,0 +1,120 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dvander = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dvander instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mode; + var out; + var x; + + x = uniform( [ len ], -10.0, 10.0, options ); + out = zeros( [ len, len ], options ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = dvander( [ x, out, mode ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( v.get( i%len, i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..1314d91b0788 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/benchmark/c/benchmark.length.c @@ -0,0 +1,218 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/ndarray/dvander.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include +#include +#include +#include + +#define NAME "dvander" +#define ITERATIONS 1000 +#define REPEATS 3 +#define MIN 1 +#define MAX 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark( int iterations, int len ) { + enum STDLIB_NDARRAY_INDEX_MODE imode; + const struct ndarray *arrays[ 3 ]; + enum STDLIB_NDARRAY_ORDER order; + int64_t mstrides[ 1 ]; + struct ndarray *mode; + int8_t submodes[ 2 ]; + int64_t stridesX[ 1 ]; + int64_t shapeX[ 1 ]; + int64_t stridesOut[ 2 ]; + int64_t shapeOut[ 2 ]; + double mdata[ 1 ]; + int64_t nsubmodes; + struct ndarray *x; + struct ndarray *out; + int64_t offset; + double elapsed; + int64_t ndimsX; + int64_t ndimsOut; + double *dataX; + double *dataOut; + double t; + int i; + + ndimsX = 1; + shapeX[ 0 ] = len; + stridesX[ 0 ] = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; + + ndimsOut = 2; + shapeOut[ 0 ] = len; + shapeOut[ 1 ] = len; + stridesOut[ 0 ] = len * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; + stridesOut[ 1 ] = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; + + offset = 0; + order = STDLIB_NDARRAY_ROW_MAJOR; + imode = STDLIB_NDARRAY_INDEX_ERROR; + submodes[ 0 ] = imode; + submodes[ 1 ] = imode; + nsubmodes = 2; + + dataX = (double *)malloc( len * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { + dataX[ i ] = random_uniform( -10.0, 10.0 ); + } + + dataOut = (double *)malloc( len * len * sizeof( double ) ); + + // cppcheck-suppress invalidPointerCast + x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndimsX, shapeX, stridesX, offset, order, imode, 1, submodes ); + + // cppcheck-suppress invalidPointerCast + out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, ndimsOut, shapeOut, stridesOut, offset, order, imode, nsubmodes, submodes ); + + mdata[ 0 ] = 1.0; + mstrides[ 0 ] = 0; + + // cppcheck-suppress invalidPointerCast + mode = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)mdata, 0, NULL, mstrides, 0, order, imode, 1, submodes ); + + arrays[ 0 ] = x; + arrays[ 1 ] = out; + arrays[ 2 ] = mode; + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_blas_ext_dvander( arrays ); + if ( dataOut[ 0 ] != dataOut[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( dataOut[ 0 ] != dataOut[ 0 ] ) { + printf( "should not return NaN\n" ); + } + stdlib_ndarray_free( x ); + stdlib_ndarray_free( out ); + stdlib_ndarray_free( mode ); + free( dataX ); + free( dataOut ); + arrays[ 0 ] = NULL; + arrays[ 1 ] = NULL; + arrays[ 2 ] = NULL; + + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d - benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/binding.gyp @@ -0,0 +1,265 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/example.c new file mode 100644 index 000000000000..b1e67f311ced --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/examples/c/example.c @@ -0,0 +1,107 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/ndarray/dvander.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create a data buffer for the input vector: + double dataX[] = { 1.0, 2.0, 3.0 }; + + // Specify the number of array dimensions: + const int64_t ndimsX = 1; + + // Specify the array shape: + int64_t shapeX[] = { 3 }; + + // Specify the array strides: + int64_t stridesX[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; + + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 2; + + // Create an input ndarray: + // cppcheck-suppress invalidPointerCast + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndimsX, shapeX, stridesX, offset, order, imode, 1, submodes ); + + // Create a data buffer for the output matrix: + double dataOut[ 9 ] = { 0.0 }; + + // Specify the number of array dimensions for the output: + const int64_t ndimsOut = 2; + + // Specify the output array shape: + int64_t shapeOut[] = { 3, 3 }; + + // Specify the array strides: + int64_t stridesOut[] = { 3 * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Create an output ndarray: + // cppcheck-suppress invalidPointerCast + struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, ndimsOut, shapeOut, stridesOut, offset, order, imode, nsubmodes, submodes ); + + // Create a data buffer for an ndarray containing the mode: + const double mdata[] = { 1.0 }; + + // Specify the array strides for a zero-dimensional ndarray: + int64_t mstrides[] = { 0 }; + + // Create an ndarray containing the mode: + // cppcheck-suppress invalidPointerCast + struct ndarray *mode = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)mdata, 0, NULL, mstrides, 0, order, imode, 1, submodes ); + + if ( x == NULL || out == NULL || mode == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, out, mode }; + + // Perform computation: + stdlib_blas_ext_dvander( arrays ); + + // Print the result: + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < 3; j++ ) { + printf( "out[ %i, %i ] = %lf\n", i, j, dataOut[ ( i * 3 ) + j ] ); + } + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( out ); + stdlib_ndarray_free( mode ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/include.gypi @@ -0,0 +1,53 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0 ] ); +* var out = zeros( [ 3, 3 ], { +* 'dtype': 'float64' +* }); +* +* var mode = scalar2ndarray( 1, { +* 'dtype': 'float64' +* }); +* +* var v = dvander( [ x, out, mode ] ); +* // returns [ [ 1.0, 1.0, 1.0 ], [ 1.0, 2.0, 4.0 ], [ 1.0, 3.0, 9.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +function dvander( arrays ) { + var x = arrays[ 0 ]; + var out = arrays[ 1 ]; + var mode = arrays[ 2 ]; + addon( getData( x ), serialize( x ), getData( out ), serialize( out ), getData( mode ), serialize( mode ) ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = dvander; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/manifest.json new file mode 100644 index 000000000000..49006938aead --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/manifest.json @@ -0,0 +1,109 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dvander", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/base/napi/addon-arguments", + "@stdlib/napi/export", + "@stdlib/napi/argv" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dvander", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dvander", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dvander", + "@stdlib/ndarray/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json index ed25bb0b374a..130e4923eda7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/addon.c new file mode 100644 index 000000000000..b1794655fcb3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/addon.c @@ -0,0 +1,67 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/ndarray/dvander.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/base/napi/addon_arguments.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); + + // Process provided arguments: + struct ndarray *arrays[ 3 ]; + napi_value err; + napi_status status = stdlib_ndarray_napi_addon_arguments( env, argv, 6, 3, arrays, &err ); + assert( status == napi_ok ); + if ( err != NULL ) { + status = napi_throw( env, err ); + assert( status == napi_ok ); + return NULL; + } + // Create a const-qualified view of the argument pointer list: + const struct ndarray *arr[ 3 ] = { + arrays[ 0 ], + arrays[ 1 ], + arrays[ 2 ] + }; + // Perform computation: + stdlib_blas_ext_dvander( arr ); + + // Free allocated memory: + stdlib_ndarray_free( arrays[ 0 ] ); + stdlib_ndarray_free( arrays[ 1 ] ); + stdlib_ndarray_free( arrays[ 2 ] ); + arrays[ 0 ] = NULL; + arrays[ 1 ] = NULL; + arrays[ 2 ] = NULL; + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/main.c new file mode 100644 index 000000000000..f7dee472df83 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/src/main.c @@ -0,0 +1,58 @@ +/** +* @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. +*/ + +#include "stdlib/blas/ext/base/ndarray/dvander.h" +#include "stdlib/blas/ext/base/dvander.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/blas/base/shared.h" + +/** +* Generates a double-precision floating-point Vandermonde matrix. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* - a zero-dimensional ndarray specifying the mode. +* +* @param arrays list containing ndarrays +*/ +void stdlib_blas_ext_dvander( const struct ndarray *arrays[] ) { + const struct ndarray *x = arrays[ 0 ]; + const struct ndarray *out = arrays[ 1 ]; + + double mode; + stdlib_ndarray_get_float64( arrays[ 2 ], NULL, &mode ); + + const CBLAS_INT M = stdlib_ndarray_dimension( out, 0 ); + const CBLAS_INT N = stdlib_ndarray_dimension( out, 1 ); + + const CBLAS_INT strideX = stdlib_ndarray_stride_elements( x, 0 ); + const CBLAS_INT offsetX = stdlib_ndarray_offset_elements( x ); + + const CBLAS_INT strideOut1 = stdlib_ndarray_stride_elements( out, 0 ); + const CBLAS_INT strideOut2 = stdlib_ndarray_stride_elements( out, 1 ); + const CBLAS_INT offsetOut = stdlib_ndarray_offset_elements( out ); + + const double *dataX = (const double *)stdlib_ndarray_data( x ); + double *dataOut = (double *)stdlib_ndarray_data( out ); + + API_SUFFIX(stdlib_strided_dvander_ndarray)( mode, M, N, dataX, strideX, offsetX, dataOut, strideOut1, strideOut2, offsetOut ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js index 06add65eeb73..ee720f891d7b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.js @@ -21,44 +21,16 @@ // MODULES // var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var getData = require( '@stdlib/ndarray/data-buffer' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var dvander = require( './../lib' ); -// FUNCTIONS // +// VARIABLES // -/** -* Returns a one-dimensional ndarray. -* -* @private -* @param {Collection} buffer - underlying data buffer -* @param {NonNegativeInteger} N - number of elements -* @param {integer} stride - stride -* @param {NonNegativeInteger} offset - index offset -* @returns {ndarray} one-dimensional ndarray -*/ -function vector( buffer, N, stride, offset ) { - return new ndarray( 'float64', new Float64Array( buffer ), [ N ], [ stride ], offset, 'row-major' ); -} - -/** -* Returns a two-dimensional ndarray. -* -* @private -* @param {Collection} buffer - underlying data buffer -* @param {NonNegativeInteger} M - number of rows -* @param {NonNegativeInteger} N - number of columns -* @param {integer} stride0 - stride of the first dimension -* @param {integer} stride1 - stride of the second dimension -* @param {NonNegativeInteger} offset - index offset -* @returns {ndarray} two-dimensional ndarray -*/ -function matrix( buffer, M, N, stride0, stride1, offset ) { - return new ndarray( 'float64', new Float64Array( buffer ), [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); -} +var opts = { + 'skip': IS_BROWSER +}; // TESTS // @@ -69,408 +41,37 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( dvander.length, 1, 'has expected arity' ); - t.end(); -}); - -tape( 'the function generates a Vandermonde matrix (row-major, increasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function generates a Vandermonde matrix (column-major, increasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a reference to the output ndarray', function test( t ) { - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 2, 2, 2, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dvander = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire }); - v = dvander( [ x, out, mode ] ); - t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( dvander, mock, 'returns expected value' ); t.end(); -}); - -tape( 'if provided an empty input ndarray, the function returns the output ndarray unchanged', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 0, 3, 3, 1, 0 ); - expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); - x = vector( [], 0, 1, 0 ); + function tryRequire() { + return mock; + } - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); + function mock() { + // Mock... + } }); -tape( 'if not provided an output ndarray with at least one column, the function returns the output ndarray unchanged', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 2, 0, 0, 1, 0 ); - expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dvander; + var main; - x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + main = require( './../lib/main.js' ); - mode = scalar2ndarray( -1, { - 'dtype': 'float64' + dvander = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire }); - v = dvander( [ x, out, mode ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.strictEqual( dvander, main, 'returns expected value' ); t.end(); -}); - -tape( 'the function supports input ndarrays with strides', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 0.0, 3.0, 0.0 ], 2, 2, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports input ndarrays with negative strides', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 3.0, 0.0, 1.0 ], 2, -2, 2 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); -tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 0.0, 1.0, 2.0, 3.0 ], 3, 1, 1 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 2 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports output ndarrays with negative strides', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, -3, 1, 6 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 3.0, 9.0, 1.0, 2.0, 4.0, 1.0, 1.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports output ndarrays having non-unit strides (row-major)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 5, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array([ - 1.0, - 1.0, - 1.0, - 0.0, - 0.0, - 4.0, - 2.0, - 1.0, - 0.0, - 0.0 - ]); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports output ndarrays having non-unit strides (column-major)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 1, 4, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array([ - 1.0, - 4.0, - 0.0, - 0.0, - 1.0, - 2.0, - 0.0, - 0.0, - 1.0, - 1.0, - 0.0, - 0.0 - ]); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 2, 2, 1, 0 ); - - mode = scalar2ndarray( -1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports non-square matrices (M < N, row-major, increasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 2.0, 3.0 ], 2, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 4, 4, 1, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function handles zero values in the input ndarray (row-major, increasing)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 0.0, 2.0 ], 2, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function handles a single column (N=1)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 5.0, 10.0, 15.0 ], 3, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0 ], 3, 1, 1, 1, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function handles a single row (M=1)', function test( t ) { - var expected; - var mode; - var out; - var x; - var v; - - x = vector( [ 3.0 ], 1, 1, 0 ); - out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 1, 4, 4, 1, 0 ); - - mode = scalar2ndarray( 1, { - 'dtype': 'float64' - }); - v = dvander( [ x, out, mode ] ); - - expected = new Float64Array( [ 1.0, 3.0, 9.0, 27.0 ] ); - t.strictEqual( v, out, 'returns expected value' ); - t.deepEqual( getData( v ), expected, 'returns expected value' ); - t.end(); + function tryRequire() { + return new Error( 'Cannot find module' ); + } }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.main.js new file mode 100644 index 000000000000..8e018322a3ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.main.js @@ -0,0 +1,476 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var dvander = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} N - number of elements +* @param {integer} stride - stride +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, N, stride, offset ) { + return new ndarray( 'float64', new Float64Array( buffer ), [ N ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'float64', new Float64Array( buffer ), [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dvander.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output ndarray', function test( t ) { + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 2, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty input ndarray, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 0, 3, 3, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [], 0, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an output ndarray with at least one column, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 2, 0, 0, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 0.0, 3.0, 0.0 ], 2, 2, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with negative strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0, 0.0, 1.0 ], 2, -2, 2 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 1.0, 2.0, 3.0 ], 3, 1, 1 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 2 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays with negative strides', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, -3, 1, 6 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 3.0, 9.0, 1.0, 2.0, 4.0, 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays having non-unit strides (row-major)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 5, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays having non-unit strides (column-major)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 1, 4, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M < N, row-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 2.0, 3.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles zero values in the input ndarray (row-major, increasing)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single column (N=1)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 5.0, 10.0, 15.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0 ], 3, 1, 1, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single row (M=1)', function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0 ], 1, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 1, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 3.0, 9.0, 27.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.native.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.native.js new file mode 100644 index 000000000000..eecc8c53c03b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dvander/test/test.native.js @@ -0,0 +1,485 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dvander = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dvander instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} N - number of elements +* @param {integer} stride - stride +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, N, stride, offset ) { + return new ndarray( 'float64', new Float64Array( buffer ), [ N ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'float64', new Float64Array( buffer ), [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dvander, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', opts, function test( t ) { + t.strictEqual( dvander.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, increasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (row-major, decreasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, increasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 1.0, 4.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function generates a Vandermonde matrix (column-major, decreasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 1, 3, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 4.0, 9.0, 1.0, 2.0, 3.0, 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output ndarray', opts, function test( t ) { + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 2, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty input ndarray, the function returns the output ndarray unchanged', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 0, 3, 3, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [], 0, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an output ndarray with at least one column, the function returns the output ndarray unchanged', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + out = matrix( [ 3.0, 4.0, 5.0, 6.0 ], 2, 0, 0, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0 ] ); + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with strides', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 0.0, 3.0, 0.0 ], 2, 2, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with negative strides', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0, 0.0, 1.0 ], 2, -2, 2 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 9.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 1.0, 2.0, 3.0 ], 3, 1, 1 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, 3, 1, 2 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays with negative strides', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 3, -3, 1, 6 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 3.0, 9.0, 1.0, 2.0, 4.0, 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays having non-unit strides (row-major)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 5, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 0.0, + 0.0, + 4.0, + 2.0, + 1.0, + 0.0, + 0.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays having non-unit strides (column-major)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 1, 4, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array([ + 1.0, + 4.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 1.0, + 1.0, + 0.0, + 0.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M > N, row-major, decreasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 1.0, 2.0, 3.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 3, 2, 2, 1, 0 ); + + mode = scalar2ndarray( -1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 2.0, 1.0, 3.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-square matrices (M < N, row-major, increasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 2.0, 3.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 2.0, 4.0, 8.0, 1.0, 3.0, 9.0, 27.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles zero values in the input ndarray (row-major, increasing)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 0.0, 2.0 ], 2, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], 2, 3, 3, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 2.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single column (N=1)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 5.0, 10.0, 15.0 ], 3, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0 ], 3, 1, 1, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles a single row (M=1)', opts, function test( t ) { + var expected; + var mode; + var out; + var x; + var v; + + x = vector( [ 3.0 ], 1, 1, 0 ); + out = matrix( [ 0.0, 0.0, 0.0, 0.0 ], 1, 4, 4, 1, 0 ); + + mode = scalar2ndarray( 1, { + 'dtype': 'float64' + }); + v = dvander( [ x, out, mode ] ); + + expected = new Float64Array( [ 1.0, 3.0, 9.0, 27.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.deepEqual( getData( v ), expected, 'returns expected value' ); + t.end(); +});