Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions lib/node_modules/@stdlib/lapack/base/dgttrf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,58 +341,90 @@ console.log( info );

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

Compute a tridiagonal LU factorization using partial pivoting. The functions mutate the arrays in place, with zero-based pivot indices.

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
#include "stdlib/lapack/base/dgttrf.h"
```

#### TODO
#### c_dgttrf( N, DL, D, DU, DU2, IPIV )

TODO.
Computes the factorization for a matrix of order `N`. `DL`, `D`, and `DU` contain `N-1`, `N`, and `N-1` elements, respectively. `DU2` and `IPIV` contain at least `max(N-2, 0)` and `N` elements, respectively.

```c
TODO
double DL[] = { 3.0, 1.0 };
double D[] = { 1.0, 4.0, 5.0 };
double DU[] = { 2.0, 1.0 };
double DU2[ 1 ];
LAPACK_INT IPIV[ 3 ];

LAPACK_INT info = API_SUFFIX(c_dgttrf)( 3, DL, D, DU, DU2, IPIV );
```

TODO
#### c_dgttrf_ndarray( N, DL, strideDL, offsetDL, D, strideD, offsetD, DU, strideDU, offsetDU, DU2, strideDU2, offsetDU2, IPIV, strideIPIV, offsetIPIV )

Computes the factorization using independent strides and offsets for each array. The first indexed element is at its corresponding offset, and consecutive elements are separated by the associated stride. Negative and zero strides are supported.

```c
TODO
double DL[] = { 1.0, 3.0 };
double D[] = { 5.0, 4.0, 1.0 };
double DU[] = { 1.0, 2.0 };
double DU2[ 1 ];
LAPACK_INT IPIV[ 3 ];

LAPACK_INT info = API_SUFFIX(c_dgttrf_ndarray)( 3, DL, -1, 1, D, -1, 2, DU, -1, 1, DU2, 1, 0, IPIV, 1, 0 );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

### Notes

- Both functions return `0` on successful factorization, or the zero-based index of the first exactly zero diagonal element of `U`, matching the current JavaScript interface. A zero at the first pivot also returns `0`. A negative matrix order returns `-1`.
- `LAPACK_INT` is a signed 32-bit integer by default and a signed 64-bit integer when compiled with `LAPACK_ILP64`. Compile callers and implementations with the same integer configuration. `API_SUFFIX` follows the shared BLAS API suffix configuration.
- The JavaScript native interface retains `Int32Array` pivot buffers using a separate width-correct workspace. Inputs which cannot safely use the native interface, including pivot buffers which overlap numeric buffers, retain the original JavaScript implementation.

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
#include "stdlib/lapack/base/dgttrf.h"
#include <stdio.h>

int main( void ) {
double DL[] = { 3.0, 1.0 };
double D[] = { 1.0, 4.0, 5.0 };
double DU[] = { 2.0, 1.0 };
double DU2[ 1 ];
LAPACK_INT IPIV[ 3 ];
LAPACK_INT info;
LAPACK_INT i;

info = API_SUFFIX(c_dgttrf)( 3, DL, D, DU, DU2, IPIV );
printf( "status: %" LAPACK_IFMT "\n", info );
for ( i = 0; i < 3; i++ ) {
printf( "D[%" LAPACK_IFMT "]: %g; pivot: %" LAPACK_IFMT "\n", i, D[ i ], IPIV[ i ] );
}
return info != 0;
}
```

</section>
Expand Down
146 changes: 146 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgttrf/benchmark/c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/

# VARIABLES #

ifndef VERBOSE
QUIET := @
else
QUIET :=
endif

# Determine the OS ([1][1], [2][2]).
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
else
ifneq (, $(findstring Windows_NT,$(OS)))
OS := WINNT
endif
endif
endif
endif

# Define the program used for compiling C source files:
ifdef C_COMPILER
CC := $(C_COMPILER)
else
CC := gcc
endif

# Define the command-line options when compiling C files:
CFLAGS ?= \
-std=c99 \
-O3 \
-Wall \
-pedantic

# Determine whether to generate position independent code ([1][1], [2][2]).
#
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
ifeq ($(OS), WINNT)
fPIC ?=
else
fPIC ?= -fPIC
endif

# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
INCLUDE ?=

# List of source files:
SOURCE_FILES ?=

# List of libraries (e.g., `-lopenblas -lpthread`):
LIBRARIES ?=

# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
LIBPATH ?=

# List of C targets:
c_targets := benchmark.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "stdlib/lapack/base/dgttrf.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#define NAME "dgttrf"
#define REPEATS 3
#define ITERATIONS 10000

/**
* Runs a tridiagonal factorization benchmark.
*
* @param N matrix order
* @return elapsed time in seconds
*/
static double benchmark( const LAPACK_INT N ) {
double *DL;
double *D;
double *DU;
double *DU2;
LAPACK_INT *IPIV;
LAPACK_INT info;
LAPACK_INT i;
LAPACK_INT j;
clock_t t;

DL = (double *)malloc( N*sizeof( double ) );
D = (double *)malloc( N*sizeof( double ) );
DU = (double *)malloc( N*sizeof( double ) );
DU2 = (double *)malloc( N*sizeof( double ) );
IPIV = (LAPACK_INT *)malloc( N*sizeof( LAPACK_INT ) );
if ( DL == NULL || D == NULL || DU == NULL || DU2 == NULL || IPIV == NULL ) {
free( DL ); free( D ); free( DU ); free( DU2 ); free( IPIV );
exit( 1 );
}
t = clock();
for ( i = 0; i < ITERATIONS; i++ ) {
for ( j = 0; j < N; j++ ) {
DL[ j ] = 1.0;
D[ j ] = 4.0;
DU[ j ] = 1.0;
}
info = API_SUFFIX(c_dgttrf)( N, DL, D, DU, DU2, IPIV );
if ( info != 0 || D[ N-1 ] <= 0.0 ) {
free( DL ); free( D ); free( DU ); free( DU2 ); free( IPIV );
exit( 1 );
}
}
t = clock() - t;
free( DL ); free( D ); free( DU ); free( DU2 ); free( IPIV );
return (double)t / CLOCKS_PER_SEC;
}

int main( void ) {
const LAPACK_INT orders[] = { 4, 16, 256 };
double elapsed;
int count;
int i;
int j;

printf( "TAP version 13\n" );
count = 0;
for ( i = 0; i < 3; i++ ) {
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
elapsed = benchmark( orders[ i ] );
printf( "# c::%s:N=%" LAPACK_IFMT "\n", NAME, orders[ i ] );
printf( " ---\n iterations: %d\n elapsed: %0.9f\n rate: %0.9f\n ...\n", ITERATIONS, elapsed, ITERATIONS/elapsed );
printf( "ok %d benchmark finished\n", count );
}
}
printf( "1..%d\n# total %d\n# pass %d\n# ok\n", count, count, count );
return 0;
}
Loading
Loading