From d30d784191f2aa3e58ea5d45781407cf64c361be Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 30 Dec 2025 11:32:55 -0800 Subject: [PATCH] feat: add `blas/ext/base/dsortnans` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/dsortnans/README.md | 298 ++++++++++++ .../benchmark/c/unsorted-random/Makefile | 146 ++++++ .../blas/ext/base/dsortnans/binding.gyp | 148 ++++++ .../blas/ext/base/dsortnans/docs/repl.txt | 111 +++++ .../ext/base/dsortnans/docs/types/index.d.ts | 95 ++++ .../ext/base/dsortnans/docs/types/test.ts | 187 ++++++++ .../ext/base/dsortnans/examples/c/Makefile | 146 ++++++ .../ext/base/dsortnans/examples/c/example.c | 39 ++ .../blas/ext/base/dsortnans/examples/index.js | 39 ++ .../blas/ext/base/dsortnans/include.gypi | 48 ++ .../include/stdlib/blas/ext/base/dsortnans.h | 46 ++ .../blas/ext/base/dsortnans/lib/dsortnans.js | 57 +++ .../base/dsortnans/lib/dsortnans.native.js | 53 +++ .../blas/ext/base/dsortnans/lib/index.js | 68 +++ .../blas/ext/base/dsortnans/lib/main.js | 35 ++ .../blas/ext/base/dsortnans/lib/native.js | 35 ++ .../blas/ext/base/dsortnans/lib/ndarray.js | 117 +++++ .../ext/base/dsortnans/lib/ndarray.native.js | 53 +++ .../blas/ext/base/dsortnans/manifest.json | 82 ++++ .../blas/ext/base/dsortnans/package.json | 75 +++ .../blas/ext/base/dsortnans/src/Makefile | 70 +++ .../blas/ext/base/dsortnans/src/addon.c | 62 +++ .../blas/ext/base/dsortnans/src/main.c | 114 +++++ .../ext/base/dsortnans/test/test.dsortnans.js | 377 +++++++++++++++ .../dsortnans/test/test.dsortnans.native.js | 384 ++++++++++++++++ .../blas/ext/base/dsortnans/test/test.js | 82 ++++ .../ext/base/dsortnans/test/test.ndarray.js | 423 +++++++++++++++++ .../dsortnans/test/test.ndarray.native.js | 432 ++++++++++++++++++ 28 files changed, 3822 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/benchmark/c/unsorted-random/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/include/stdlib/blas/ext/base/dsortnans.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/dsortnans.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/dsortnans.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/README.md new file mode 100644 index 000000000000..c998a72e375d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/README.md @@ -0,0 +1,298 @@ + + +# dsortnans + +> Partition a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. + +
+ +## Usage + +```javascript +var dsortnans = require( '@stdlib/blas/ext/base/dsortnans' ); +``` + +#### dsortnans( N, order, x, strideX ) + +Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); + +dsortnans( x.length, 1.0, x, 1 ); +// x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **order**: NaN placement order. If `order < 0`, the function places NaNs at the **beginning** of `x`. If `order > 0`, the function places NaNs at the **end** of `x`. If `order == 0.0`, the input strided array is left **unchanged**. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to sort every other element: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, NaN, -3.0, 5.0 ] ); + +dsortnans( 2, -1.0, x, 2 ); +// x => [ NaN, -2.0, 1.0, -3.0, 5.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 1.0, NaN, -2.0, 5.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Sort every other element... +dsortnans( 2, 1.0, x1, 2 ); +// x0 => [ 1.0, 5.0, -2.0, NaN ] +``` + +#### dsortnans.ndarray( N, order, x, strideX, offsetX ) + +Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ NaN, -2.0, NaN, 3.0, -4.0 ] ); + +dsortnans.ndarray( x.length, 1.0, x, 1, 0 ); +// x => [ -4.0, -2.0, 3.0, NaN, NaN ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, NaN, -6.0 ] ); + +dsortnans.ndarray( 3, 1.0, x, 1, x.length-3 ); +// x => [ 1.0, -2.0, 3.0, -4.0, -6.0, NaN ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0` or `order == 0.0`, both functions return `x` unchanged. +- A positive order places `NaN` values at the end of the array, while a negative order places `NaN` values at the beginning. +- The algorithm has space complexity `O(1)` and worst case time complexity `O(N)`. +- The algorithm is **not stable**, meaning that the relative order of non-`NaN` elements is not guaranteed to be preserved. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsortnans = require( '@stdlib/blas/ext/base/dsortnans' ); + +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.3 ) { + x[ i ] = NaN; + } else { + x[ i ] = (randu()*20.0) - 10.0; + } +} +console.log( x ); + +dsortnans( x.length, -1.0, x, -1 ); +console.log( x ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dsortnans.h" +``` + +#### stdlib_strided_dsortnans( N, order, \*X, strideX ) + +Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. + +```c +double x[] = { 0.0/0.0, -2.0, 0.0/0.0, -4.0 }; + +stdlib_strided_dsortnans( 2, -1.0, x, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] double` NaN placement order. If `order < 0`, the function places NaNs at the **beginning** of `x`. If `order > 0`, the function places NaNs at the **end** of `x`. If `order == 0.0`, the input strided array is left **unchanged**. +- **X**: `[inout] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +stdlib_strided_dsortnans( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_dsortnans_ndarray( N, order, \*X, strideX, offsetX ) + + + +Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array using alternative indexing semantics. + +```c +double x[] = { 0.0/0.0, -2.0, 0.0/0.0, -4.0 }; + +stdlib_strided_dsortnans_ndarray( 4, 1.0, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] double` NaN placement order. If `order < 0`, the function places NaNs at the **beginning** of `x`. If `order > 0`, the function places NaNs at the **end** of `x`. If `order == 0.0`, the input strided array is left **unchanged**. +- **X**: `[inout] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +stdlib_strided_dsortnans_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dsortnans.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 0.0/0.0, -4.0, 0.0/0.0, -6.0, 7.0, 0.0/0.0 }; + + // Specify the number of elements: + int N = 8; + + // Specify a stride: + int strideX = 1; + + // Sort the array: + stdlib_strided_dsortnans( N, 1.0, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/benchmark/c/unsorted-random/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/benchmark/c/unsorted-random/Makefile new file mode 100644 index 000000000000..cce2c865d7ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/benchmark/c/unsorted-random/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/dsortnans/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/binding.gyp new file mode 100644 index 000000000000..cfd7d8b2cf7e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/binding.gyp @@ -0,0 +1,148 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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", + # 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 + }, # 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/dsortnans/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/repl.txt new file mode 100644 index 000000000000..6467db456c8b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/repl.txt @@ -0,0 +1,111 @@ + +{{alias}}( N, order, x, strideX ) + Partitions a double-precision floating-point strided array by moving all + NaNs either to the beginning or the end of the array. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0` or `order == 0`, the function returns `x` unchanged. + + A positive order places `NaN` values at the end of the array, while a + negative order places `NaN` values at the beginning. + + The algorithm has space complexity O(1) and worst case time complexity O(N). + + The algorithm is not stable, meaning that the relative order of non-`NaN` + elements is not guaranteed to be preserved. + + Parameters + ---------- + N: integer + Number of indexed elements. + + order: number + `NaN` placement order. If `order < 0`, the function places NaNs at the + beginning of `x`. + If `order > 0`, the function places NaNs at the end of `x`. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + Returns + ------- + x: Float64Array + Input array `x`. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ NaN, -2.0, NaN, 3.0, -4.0 ] ); + > {{alias}}( x.length, 1, x, 1 ) + [ -4.0, -2.0, 3.0, NaN, NaN ] + + // Using `N` and `stride` parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, -3.0, 5.0 ] ); + > {{alias}}( 2, -1, x, 2 ) + [ NaN, -2.0, 1.0, -3.0, 5.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, NaN, -2.0, 5.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 2, 1, x1, 2 ) + [ 5.0, -2.0, NaN ] + > x0 + [ 1.0, 5.0, -2.0, NaN ] + + +{{alias}}.ndarray( N, order, x, strideX, offsetX ) + Partitions a double-precision floating-point strided array by moving all + NaNs either to the beginning or the end of the array using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + order: number + `NaN` placement order. If `order < 0`, the function places NaNs at the + beginning of `x`. + If `order > 0`, the function places NaNs at the end of `x`. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + x: Float64Array + Input array `x`. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ NaN, -2.0, NaN, 3.0, -4.0 ] ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + [ -4.0, -2.0, 3.0, NaN, NaN ] + + // Using an index offset: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, NaN, -2.0, 5.0 ] ); + > {{alias}}.ndarray( 2, 1, x, 2, 1 ) + [ 1.0, 5.0, -2.0, NaN ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/index.d.ts new file mode 100644 index 000000000000..4401e86c76a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/index.d.ts @@ -0,0 +1,95 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Interface describing `dsortnans`. +*/ +interface Routine { + /** + * Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. + * + * @param N - number of indexed elements + * @param order - NaN placement order + * @param x - input array + * @param strideX - stride length + * @returns `x` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); + * + * dsortnans( x.length, 1, x, 1 ); + * // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] + */ + ( N: number, order: number, x: Float64Array, strideX: number ): Float64Array; + + /** + * Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param order - NaN placement order + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns `x` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); + * + * dsortnans.ndarray( x.length, 1, x, 1, 0 ); + * // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] + */ + ndarray( N: number, order: number, x: Float64Array, strideX: number, offsetX: number ): Float64Array; +} + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* @param N - number of indexed elements +* @param order - NaN placement order +* @param x - input array +* @param strideX - stride length +* @returns `x` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans( x.length, 1, x, 1 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans.ndarray( x.length, 1, x, 1, 0 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +*/ +declare var dsortnans: Routine; + + +// EXPORTS // + +export = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/test.ts new file mode 100644 index 000000000000..bb5fe21a3a4b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/docs/types/test.ts @@ -0,0 +1,187 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +import dsortnans = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + + dsortnans( x.length, 1, x, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans( '10', 1, x, 1 ); // $ExpectError + dsortnans( true, 1, x, 1 ); // $ExpectError + dsortnans( false, 1, x, 1 ); // $ExpectError + dsortnans( null, 1, x, 1 ); // $ExpectError + dsortnans( undefined, 1, x, 1 ); // $ExpectError + dsortnans( [], 1, x, 1 ); // $ExpectError + dsortnans( {}, 1, x, 1 ); // $ExpectError + dsortnans( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans( x.length, '10', x, 1 ); // $ExpectError + dsortnans( x.length, true, x, 1 ); // $ExpectError + dsortnans( x.length, false, x, 1 ); // $ExpectError + dsortnans( x.length, null, x, 1 ); // $ExpectError + dsortnans( x.length, undefined, x, 1 ); // $ExpectError + dsortnans( x.length, [], x, 1 ); // $ExpectError + dsortnans( x.length, {}, x, 1 ); // $ExpectError + dsortnans( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dsortnans( x.length, 1, 10, 1 ); // $ExpectError + dsortnans( x.length, 1, '10', 1 ); // $ExpectError + dsortnans( x.length, 1, true, 1 ); // $ExpectError + dsortnans( x.length, 1, false, 1 ); // $ExpectError + dsortnans( x.length, 1, null, 1 ); // $ExpectError + dsortnans( x.length, 1, undefined, 1 ); // $ExpectError + dsortnans( x.length, 1, [], 1 ); // $ExpectError + dsortnans( x.length, 1, {}, 1 ); // $ExpectError + dsortnans( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans( x.length, 1, x, '10' ); // $ExpectError + dsortnans( x.length, 1, x, true ); // $ExpectError + dsortnans( x.length, 1, x, false ); // $ExpectError + dsortnans( x.length, 1, x, null ); // $ExpectError + dsortnans( x.length, 1, x, undefined ); // $ExpectError + dsortnans( x.length, 1, x, [] ); // $ExpectError + dsortnans( x.length, 1, x, {} ); // $ExpectError + dsortnans( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dsortnans(); // $ExpectError + dsortnans( x.length ); // $ExpectError + dsortnans( x.length, 1 ); // $ExpectError + dsortnans( x.length, 1, x ); // $ExpectError + dsortnans( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( true, 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( false, 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( null, 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( [], 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, true ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, false ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, null ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dsortnans.ndarray(); // $ExpectError + dsortnans.ndarray( x.length ); // $ExpectError + dsortnans.ndarray( x.length, 1 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1 ); // $ExpectError + dsortnans.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/dsortnans/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/example.c new file mode 100644 index 000000000000..93f1b3eb2a85 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/c/example.c @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/dsortnans.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 0.0/0.0, -4.0, 0.0/0.0, -6.0, 7.0, 0.0/0.0 }; + + // Specify the number of elements: + int N = 8; + + // Specify a stride: + int strideX = 1; + + // Sort the array: + stdlib_strided_dsortnans( N, 1.0, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/index.js new file mode 100644 index 000000000000..d74a582f2787 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/examples/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dsortnans = require( './../lib' ); + +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.3 ) { + x[ i ] = NaN; + } else { + x[ i ] = (randu()*20.0) - 10.0; + } +} +console.log( x ); + +dsortnans( x.length, -1.0, x, -1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/include.gypi new file mode 100644 index 000000000000..235be47d6d3b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/include.gypi @@ -0,0 +1,48 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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": [ + " [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +*/ +function dsortnans( N, order, x, strideX ) { + return ndarray( N, order, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/dsortnans.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/dsortnans.native.js new file mode 100644 index 000000000000..2e5dc3647c0a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/dsortnans.native.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - NaN placement order +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans( x.length, 1.0, x, 1 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +*/ +function dsortnans( N, order, x, strideX ) { + addon( N, order, x, strideX ); + return x; +} + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/index.js new file mode 100644 index 000000000000..7e618c708077 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Partition a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* @module @stdlib/blas/ext/base/dsortnans +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsortnans = require( '@stdlib/blas/ext/base/dsortnans' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans( x.length, 1.0, x, 1 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsortnans = require( '@stdlib/blas/ext/base/dsortnans' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans.ndarray( x.length, 1.0, x, 1, 0 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dsortnans; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dsortnans = main; +} else { + dsortnans = tmp; +} + + +// EXPORTS // + +module.exports = dsortnans; + +// exports: { "ndarray": "dsortnans.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/main.js new file mode 100644 index 000000000000..c8456a961ef5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsortnans = require( './dsortnans.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dsortnans, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/native.js new file mode 100644 index 000000000000..3ccf08fa6348 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/native.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsortnans = require( './dsortnans.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dsortnans, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.js new file mode 100644 index 000000000000..a6a830526eef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* ## Notes +* +* - The algorithm is not stable, meaning that the relative order of non-NaN elements is not guaranteed to be preserved. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - NaN placement order +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans( x.length, 1.0, x, 1, 0 ); +* // x => [ 1.0, -2.0, -4.0, 3.0, NaN, NaN ] +*/ +function dsortnans( N, order, x, strideX, offsetX ) { + var tmp; + var ix; + var jx; + var fx; + var lx; + + if ( N <= 0 || order === 0.0 ) { + return x; + } + // For a positive stride, placing NaNs at the beginning is equivalent to providing a negative stride and placing NaNs at the end, and, for a negative stride, placing NaNs at the end is equivalent to providing a positive stride and placing NaNs at the beginning... + if ( order < 0.0 ) { + strideX *= -1; + offsetX -= ( N-1 ) * strideX; + } + fx = offsetX; // first index + lx = fx + ((N-1)*strideX); // last index + ix = fx; + jx = lx; + + if ( strideX < 0 ) { + // Traverse the strided array from right-to-left... + + // Partition array by moving NaNs to the beginning... + while ( ix >= jx ) { + if ( !isnan( x[ ix ] ) ) { + ix += strideX; + continue; + } + if ( isnan( x[ jx ] ) ) { + jx -= strideX; + continue; + } + // Swap NaN on the right with non-NaN on the left and continue partitioning... + tmp = x[ ix ]; + x[ ix ] = x[ jx ]; + x[ jx ] = tmp; + ix += strideX; + jx -= strideX; + } + return x; + } + // Traverse the strided array from left-to-right... + + // Partition array by moving NaNs to the end... + while ( ix <= jx ) { + if ( !isnan( x[ ix ] ) ) { + ix += strideX; + continue; + } + if ( isnan( x[ jx ] ) ) { + jx -= strideX; + continue; + } + // Swap NaN on the left with non-NaN on the right and continue partitioning... + tmp = x[ ix ]; + x[ ix ] = x[ jx ]; + x[ jx ] = tmp; + ix += strideX; + jx -= strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.native.js new file mode 100644 index 000000000000..04088606ce6f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/lib/ndarray.native.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - NaN placement order +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 3.0, -4.0, NaN ] ); +* +* dsortnans( x.length, 1.0, x, 1, 0 ); +*/ +function dsortnans( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX ); + return x; +} + + +// EXPORTS // + +module.exports = dsortnans; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/manifest.json new file mode 100644 index 000000000000..444b17d588b7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/manifest.json @@ -0,0 +1,82 @@ +{ + "options": { + "task": "build" + }, + "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", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-int64", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/math/base/assert/is-nan", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/package.json b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/package.json new file mode 100644 index 000000000000..52f911b179d2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/blas/ext/base/dsortnans", + "version": "0.0.0", + "description": "Partition a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "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", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "partition", + "dsortnans", + "order", + "arrange", + "permute", + "strided", + "array", + "ndarray", + "float64", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/dsortnans/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/addon.c new file mode 100644 index 000000000000..167e9810820f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/addon.c @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/dsortnans.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float64array.h" +#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, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsortnans)( N, order, X, strideX ); + return NULL; +} + +/** +* 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_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsortnans_ndarray)( N, order, X, strideX, offsetX ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/main.c new file mode 100644 index 000000000000..b884a77c9a68 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/src/main.c @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/dsortnans.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array. +* +* @param N number of indexed elements +* @param order NaN placement order +* @param X input array +* @param strideX index increment +*/ +void API_SUFFIX(stdlib_strided_dsortnans)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(stdlib_strided_dsortnans_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array using alternative indexing semantics. +* +* @param N number of indexed elements +* @param order NaN placement order +* @param X input array +* @param strideX index increment +* @param offsetX starting index +*/ +void API_SUFFIX(stdlib_strided_dsortnans_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT jx; + CBLAS_INT fx; + CBLAS_INT lx; + CBLAS_INT sx; + CBLAS_INT ox; + double tmp; + + if ( N <= 0 || order == 0.0 ) { + return; + } + // For a positive stride, placing NaNs at the beginning is equivalent to providing a negative stride and placing NaNs at the end, and, for a negative stride, placing NaNs at the end is equivalent to providing a positive stride and placing NaNs at the beginning... + if ( order < 0.0 ) { + sx = -strideX; + ox = offsetX - ( (N-1) * sx ); + } else { + sx = strideX; + ox = offsetX; + } + fx = ox; + lx = fx + ( (N-1) * sx ); + ix = fx; + jx = lx; + + if ( sx < 0 ) { + // Traverse the strided array from right-to-left... + + // Partition array by moving NaNs to the beginning... + while ( ix >= jx ) { + if ( !stdlib_base_is_nan( X[ ix ] ) ) { + ix += sx; + continue; + } + if ( stdlib_base_is_nan( X[ jx ] ) ) { + jx -= sx; + continue; + } + // Swap NaN on the right with non-NaN on the left and continue partitioning... + tmp = X[ ix ]; + X[ ix ] = X[ jx ]; + X[ jx ] = tmp; + ix += sx; + jx -= sx; + } + return; + } + // Traverse the strided array from left-to-right... + + // Partition array by moving NaNs to the end... + while ( ix <= jx ) { + if ( !stdlib_base_is_nan( X[ ix ] ) ) { + ix += sx; + continue; + } + if ( stdlib_base_is_nan( X[ jx ] ) ) { + jx -= sx; + continue; + } + // Swap NaN on the left with non-NaN on the right and continue partitioning... + tmp = X[ ix ]; + X[ ix ] = X[ jx ]; + X[ jx ] = tmp; + ix += sx; + jx -= sx; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.js new file mode 100644 index 000000000000..187649f8d17f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.js @@ -0,0 +1,377 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var dsortnans = require( './../lib/dsortnans.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsortnans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( dsortnans.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function partitions NaNs to the end (positive order)', function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (negative order)', function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (positive order; special cases)', function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function sorts a strided array (negative order; special cases)', function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, NaN, 4.0, NaN ] ); + out = dsortnans( x.length, 1.0, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, NaN, -1.0 ] ); + expected = new Float64Array( [ 3.0, NaN, -1.0 ] ); + + dsortnans( 0, 1.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + dsortnans( -4, 1.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `order` equals `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + expected = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + + dsortnans( x.length, 0.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 2.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + NaN, // 0 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + NaN, // 2 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 2.0, // 2 + -3.0, + 6.0, // 1 + 7.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (positive order)', function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + -6.0, // 1 + 5.0, + NaN // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + dsortnans( 3, 1.0, x1, 2 ); + t.strictEqual( isSameFloat64Array( x0, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (negative order)', function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + -6.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -2.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + NaN, // 0 + 3.0, + -6.0, // 1 + 5.0, + -2.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + dsortnans( 3, -1.0, x1, 2 ); + t.strictEqual( isSameFloat64Array( x0, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.native.js new file mode 100644 index 000000000000..0b3889ea7784 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.dsortnans.native.js @@ -0,0 +1,384 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dsortnans = tryRequire( resolve( __dirname, './../lib/dsortnans.native.js' ) ); +var opts = { + 'skip': ( dsortnans instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsortnans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( dsortnans.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function partitions NaNs to the end (positive order)', opts, function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (negative order)', opts, function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (positive order; special cases)', opts, function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function sorts a strided array (negative order; special cases)', opts, function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, NaN, 4.0, NaN ] ); + out = dsortnans( x.length, 1.0, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, NaN, -1.0 ] ); + expected = new Float64Array( [ 3.0, NaN, -1.0 ] ); + + dsortnans( 0, 1.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + dsortnans( -4, 1.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `order` equals `0`, the function returns `x` unchanged', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + expected = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + + dsortnans( x.length, 0.0, x, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 2.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + NaN, // 0 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + NaN, // 2 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 2.0, // 2 + -3.0, + 6.0, // 1 + 7.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (positive order)', opts, function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 2 + ]); + expected = new Float64Array([ + -2.0, + 3.0, // 0 + -6.0, + 5.0, // 1 + NaN // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + dsortnans( 3, 1.0, x1, 2 ); + t.strictEqual( isSameFloat64Array( x1, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets (negative order)', opts, function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + -6.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -2.0 // 2 + ]); + expected = new Float64Array([ + NaN, // 0 + 3.0, + -6.0, // 1 + 5.0, + -2.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + dsortnans( 3, -1.0, x1, 2 ); + t.strictEqual( isSameFloat64Array( x1, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.js new file mode 100644 index 000000000000..6f6e74cbba75 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dsortnans = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsortnans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dsortnans.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dsortnans = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dsortnans, mock, 'returns native implementation' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dsortnans; + var main; + + main = require( './../lib/dsortnans.js' ); + + dsortnans = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dsortnans, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.js new file mode 100644 index 000000000000..679f02a494df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.js @@ -0,0 +1,423 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var dsortnans = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsortnans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( dsortnans.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function partitions NaNs to the end (positive order)', function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (negative order)', function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (positive order; special cases)', function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function sorts a strided array (negative order; special cases)', function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, NaN, 4.0, NaN ] ); + out = dsortnans( x.length, 1.0, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, NaN, -1.0 ] ); + expected = new Float64Array( [ 3.0, NaN, -1.0 ] ); + + dsortnans( 0, 1.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + dsortnans( -4, 1.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `order` equals `0`, the function returns `x` unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + expected = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + + dsortnans( x.length, 0.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 2.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + NaN, // 0 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + NaN, // 2 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 2.0, // 2 + -3.0, + 6.0, // 1 + 7.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + -6.0, // 1 + 5.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -6.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -2.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + NaN, // 0 + 3.0, + -6.0, // 1 + 5.0, + -2.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (positive order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -4.0, // 2 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 0 + ]); + expected = new Float64Array([ + 1.0, + NaN, // 2 + 3.0, + -4.0, // 1 + 5.0, + -6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (negative order)', function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -2.0, // 2 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 0 + ]); + expected = new Float64Array([ + 1.0, + -2.0, // 2 + 3.0, + -6.0, // 1 + 5.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.native.js new file mode 100644 index 000000000000..042d0ef0674d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortnans/test/test.ndarray.native.js @@ -0,0 +1,432 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dsortnans = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dsortnans instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dsortnans, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( dsortnans.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function partitions NaNs to the end (positive order)', opts, function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (negative order)', opts, function test( t ) { + var seenNaN; + var x; + var v; + var i; + + seenNaN = false; + x = new Float64Array( 1e2 ); + for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = (randu()*20.0) - 10.0; + } + x[ i ] = v; + } + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function partitions NaNs to the beginning (positive order; special cases)', opts, function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, 1.0, x, 1, 0 ); + for ( i = 0; i < x.length; i++ ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function sorts a strided array (negative order; special cases)', opts, function test( t ) { + var seenNaN; + var x; + var i; + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + + seenNaN = false; + x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] ); + + dsortnans( x.length, -1.0, x, 1, 0 ); + for ( i = x.length; i > 0; i-- ) { + if ( isnan( x[ i ] ) ) { + seenNaN = true; + } else { + t.strictEqual( seenNaN, false, 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, NaN, 4.0, NaN ] ); + out = dsortnans( x.length, 1.0, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, NaN, -1.0 ] ); + expected = new Float64Array( [ 3.0, NaN, -1.0 ] ); + + dsortnans( 0, 1.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + dsortnans( -4, 1.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `order` equals `0`, the function returns `x` unchanged', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + expected = new Float64Array( [ 3.0, -4.0, NaN, 15.0, NaN, 3.0 ] ); + + dsortnans( x.length, 0.0, x, 1, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 2.0, // 0 + -3.0, + 6.0, // 1 + 7.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + NaN, // 0 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2, 0 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + NaN, // 2 + -3.0, + 2.0, // 1 + 7.0, + 6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 2.0, // 2 + -3.0, + NaN, // 1 + 7.0, + 6.0 // 0 + ]); + expected = new Float64Array([ + 2.0, // 2 + -3.0, + 6.0, // 1 + 7.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + -2.0, // 0 + 3.0, + -6.0, // 1 + 5.0, + NaN // 2 + ]); + + dsortnans( 3, 1.0, x, 2, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an offset (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -6.0, // 0 + 3.0, + NaN, // 1 + 5.0, + -2.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + NaN, // 0 + 3.0, + -6.0, // 1 + 5.0, + -2.0 // 2 + ]); + + dsortnans( 3, -1.0, x, 2, 1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (positive order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -4.0, // 2 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 0 + ]); + expected = new Float64Array([ + 1.0, + NaN, // 2 + 3.0, + -4.0, // 1 + 5.0, + -6.0 // 0 + ]); + + dsortnans( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (negative order)', opts, function test( t ) { + var expected; + var x; + + x = new Float64Array([ + 1.0, + -2.0, // 2 + 3.0, + NaN, // 1 + 5.0, + -6.0 // 0 + ]); + expected = new Float64Array([ + 1.0, + -2.0, // 2 + 3.0, + -6.0, // 1 + 5.0, + NaN // 0 + ]); + + dsortnans( 3, -1.0, x, -2, x.length-1 ); + t.strictEqual( isSameFloat64Array( x, expected ), true, 'returns expected value' ); + t.end(); +});