FLINT3.7.0-dev
Module · 17 functions

d_mat.h

#include <flint/d_mat.h>

This module provides dense matrices of double entries with basic operations: memory management, comparison, transposition and classical multiplication. Arithmetic uses the default rounding of the processor (round to nearest). It is a small support module; for numerical linear algebra at double or higher precision with more algorithms, use the generic matrices gr_mat_t over an nfloat or dfloat context, or arb_mat_t for rigorous results.

Types and memory management#

A matrix with r rows and c columns. The entries are stored in one array entries in row-major order, and rows is an array of r pointers to the starts of the rows. A d_mat_t is a length-one array of d_mat_struct.

void d_mat_init(d_mat_t mat, slong rows, slong cols)

Initialises mat as a rows by cols matrix with all entries zero. Throws an exception if the number of entries overflows an slong.

Frees the memory used by mat.

d_mat_entry(mat, i, j)

The entry in row ii and column jj of mat, as an lvalue of type double. The indices are not checked.

Return the number of rows and columns of mat.

Assignment#

void d_mat_set(d_mat_t mat1, const d_mat_t mat2)

Copies the entries of mat2 to mat1, which must have the same dimensions.

Swaps the entries of mat1 and mat2 one by one, rather than the structs; the row pointers of both matrices stay valid. The matrices must have the same dimensions.

Sets all entries of mat to zero.

Random generation and output#

void d_mat_randtest(d_mat_t mat, flint_rand_t state, slong minexp, slong maxexp)

Sets the entries of mat to random values from d_randtest_signed: signed numbers with exponents between minexp and maxexp, or zero.

void d_mat_print(const d_mat_t mat)

Prints mat to standard output, one bracketed row per line, with the entries in the printf format %E.

Comparison#

int d_mat_equal(const d_mat_t mat1, const d_mat_t mat2)

Returns 1 if mat1 and mat2 have the same dimensions and equal entries (as doubles), and 0 otherwise.

int d_mat_approx_equal(const d_mat_t mat1, const d_mat_t mat2, double eps)

Returns 1 if mat1 and mat2 have the same dimensions and their entries differ by at most eps in absolute value, and 0 otherwise.

int d_mat_is_square(const d_mat_t mat)

Returns 1 if mat has as many rows as columns, and 0 otherwise.

Transpose and multiplication#

Sets BB to the transpose ATA^T. Throws an exception unless the dimensions of BB are those of ATA^T. Aliasing is allowed (for square matrices, by the dimension condition).

void d_mat_mul_classical(d_mat_t C, const d_mat_t A, const d_mat_t B)

Sets C=ABC = AB using the classical algorithm in double-precision arithmetic. Throws an exception unless CC has as many rows as AA and as many columns as BB; the number of columns of AA must equal the number of rows of BB (not checked). Aliasing of CC with AA or BB is allowed.

More
Cite this page

The FLINT team, “d_mat.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/d_mat/index.html (generated 2026-11-02).