OpenBI Docs Buy

Matrices, stacks, queues and heaps

Dense matrices stored column by column, three-dimensional arrays, and the stack, double-ended queue and heap containers.

126 entries: 116 functions, 7 types and 3 macros. Part of the Open Graph reference; All functions lists every entry on one page, with a filter. The badges say how each entry is checked.

Types and macros

matrix_ttype#

Unit tests

A dense matrix of real numbers, stored column by column.

struct og_matrix_t { og_vector_t data; og_int_t nrow; og_int_t ncol; };

data is an vector_t holding nrow * ncol elements; element (i, j) is data.data[j * nrow + i] (MATRIX(m, i, j)). The same layout exists for og_matrix_int_t (og_int_t), og_matrix_bool_t (og_bool_t), og_matrix_char_t (char) and og_matrix_complex_t (og_complex_t), each with its own og_matrix_<type>_ functions. Read the fields freely, but change the shape only through the functions.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_matrix_t
In notebooks
Og.Matrix
igraph 1.0
igraph_matrix_t
See also
matrix_init, MATRIX, matrix_view

matrix_storage_ttype#

Unit tests

How a plain C array lays out a matrix: by rows or by columns.

typedef enum og_matrix_storage_t { OG_ROW_MAJOR = 0, OG_COLUMN_MAJOR = 1 } og_matrix_storage_t;

OG_ROW_MAJOR (0): element (i, j) at index i * ncol + j. OG_COLUMN_MAJOR (1): element (i, j) at index j * nrow + i, the layout matrix_t itself uses.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_matrix_storage_t
In notebooks
Og.MatrixStorage
igraph 1.0
igraph_matrix_storage_t
See also
matrix_init_array, matrix_copy_to

MATRIXmacro#

Unit tests

Unchecked access to element (i, j) of any matrix type.

#define OG_MATRIX(m, i, j) ((m).data.data[(m).nrow * (j) + (i)])

Expands to the storage element, so it can be read or assigned: MATRIX(m, i, j) = x. Takes the matrix itself, not a pointer. No range check. The short name MATRIX is defined as well unless OG_NO_SHORT_NAMES is set.

Parameters
  • m The matrix (an object, not a pointer).
  • i Row index.
  • j Column index.
Returns
The element (an lvalue).
Complexity
O(1).
Checked
Layout fixed by the header; exercised by every test of the area.
C name
OG_MATRIX
In notebooks
Og.MatrixAt
igraph 1.0
MATRIX
See also
matrix_get, matrix_set

MATRIX_INIT_FINALLYmacro#

Unit tests

Initialises a matrix and registers it on the cleanup stack in one step.

#define OG_MATRIX_INIT_FINALLY(m, nrow, ncol) do { OG_CHECK(og_matrix_init((m), (nrow), (ncol))); OG_FINALLY(og_matrix_destroy, (m)); } while (0)

Inside a function that returns error_t: if matrix_init fails the error is passed on, otherwise matrix_destroy is registered so that a later error frees the matrix. On success the caller destroys it and pops the entry with OG_FINALLY_CLEAN(1). The same helpers exist for the other types: OG_MATRIX_INT_, _BOOL_, _CHAR_, _COMPLEX_INIT_FINALLY, OG_STACK[_INT|_CHAR|_BOOL]_INIT_FINALLY, OG_DQUEUE[...]_INIT_FINALLY, OG_HEAP[_MIN][_INT|_CHAR]_INIT_FINALLY and ARRAY3[...]_INIT_FINALLY.

Parameters
  • m Pointer to the matrix.
  • nrow Number of rows.
  • ncol Number of columns.
Returns
Returns from the enclosing function with the error code when the initialisation fails.
Complexity
O(nrow * ncol).
Checked
Layout fixed by the header; exercised by every test of the area.
C name
OG_MATRIX_INIT_FINALLY
See also
matrix_init, matrix_destroy

stack_ttype#

Unit tests

A last-in, first-out stack of real numbers.

struct og_stack_t { og_real_t *data; og_int_t size; og_int_t capacity; };

data[0] is the bottom and data[size - 1] the top; capacity elements are allocated. Also og_stack_int_t, og_stack_char_t and og_stack_bool_t.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_stack_t
In notebooks
Og.Stack
igraph 1.0
igraph_stack_t
See also
stack_init, stack_push, stack_pop

dqueue_ttype#

Unit tests

A double-ended queue of real numbers in a ring buffer.

struct og_dqueue_t { og_real_t *data; og_int_t begin; og_int_t size; og_int_t capacity; };

The head is data[begin]; the k-th element is data[(begin + k) mod capacity]. Also og_dqueue_int_t, og_dqueue_char_t and og_dqueue_bool_t.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_dqueue_t
In notebooks
Og.Dqueue
igraph 1.0
igraph_dqueue_t
See also
dqueue_init, dqueue_push, dqueue_pop

heap_ttype#

Unit tests

A binary maximum heap of real numbers.

struct og_heap_t { og_real_t *data; og_int_t size; og_int_t capacity; };

data[0] is the largest element and data[(i - 1) / 2] never ranks below data[i]. Also og_heap_int_t and og_heap_char_t. NaN ranks above every number.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_heap_t
In notebooks
Og.Heap
igraph 1.0
igraph_heap_t
See also
heap_init, heap_min_t

heap_min_ttype#

Unit tests

A binary minimum heap of real numbers.

struct og_heap_min_t { og_real_t *data; og_int_t size; og_int_t capacity; };

Same layout as heap_t with the order reversed: data[0] is the smallest element. Its functions are og_heap_min_init, og_heap_min_push, og_heap_min_delete_top and so on. Also og_heap_min_int_t and og_heap_min_char_t. NaN ranks above every number, so it comes out last.

Checked
Layout fixed by the header; exercised by every test of the area.
C name
og_heap_min_t
In notebooks
Og.HeapMin
igraph 1.0
igraph_heap_min_t
See also
heap_t, heap_init

array3_ttype#

Unit tests

A dense three-dimensional array of real numbers.

struct og_array3_t { og_vector_t data; og_int_t n1; og_int_t n2; og_int_t n3; og_int_t n1n2; };

n1 x n2 x n3 elements in data; element (i, j, k) is data.data[n1n2 * k + n1 * j + i] (the first index runs fastest), read and written with ARRAY3(a, i, j, k). Also og_array3_int_t, og_array3_char_t and og_array3_bool_t. The reference lists array3 as a template type but documents no functions for it, so the small API below is Open Graph's own, shaped like the matrix one.

Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_t
In notebooks
Og.Array3
igraph 1.0
igraph_array3_t
See also
array3_init, ARRAY3

ARRAY3macro#

Unit tests

Unchecked access to element (i, j, k) of any three-dimensional array.

#define OG_ARRAY3(a, i, j, k) ((a).data.data[(a).n1n2 * (k) + (a).n1 * (j) + (i)])

Expands to the storage element, so it can be read or assigned. Takes the array itself, not a pointer. The short name ARRAY3 is defined too unless OG_NO_SHORT_NAMES is set.

Parameters
  • a The array (an object).
  • i First index.
  • j Second index.
  • k Third index.
Returns
The element (an lvalue).
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
OG_ARRAY3
In notebooks
Og.Array3At
See also
array3_t

Creating and copying

matrix_init#

Unit tests

Creates an nrow by ncol matrix with every element zero.

og_error_t og_matrix_init(og_matrix_t *m, og_int_t nrow, og_int_t ncol);

Allocates nrow * ncol elements, all zero, stored column by column: element (i, j) sits at position j * nrow + i of the storage vector data. The matrix must not be initialised yet; free it with matrix_destroy. A matrix with zero rows or zero columns is valid.

When the call fails the matrix is left as an empty 0 by 0 object, so matrix_destroy on it is harmless.

Other element types: og_matrix_int_init, og_matrix_bool_init, og_matrix_char_init and og_matrix_complex_init (same arguments with the matching container and element types).

Parameters
  • m The matrix to initialise; not initialised yet.
  • nrow Number of rows, 0 or more.
  • ncol Number of columns, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL nrow or ncol is negative, or nrow * ncol does not fit in og_int_t.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_init
In notebooks
Og.Native.og_matrix_init
igraph 1.0
igraph_matrix_init
See also
matrix_destroy, matrix_init_array, matrix_init_copy, matrix_resize, MATRIX_INIT_FINALLY
og_matrix_t m;
og_vector_t rows;
og_matrix_init(&m, 2, 3);           /* 2 x 3, all zero */
OG_MATRIX(m, 0, 2) = 5.0;            /* row 0, column 2 */
og_matrix_set(&m, 1, 0, -1.0);
og_vector_init(&rows, 0);
og_matrix_rowsum(&m, &rows);         /* rows = (5, -1) */
og_vector_destroy(&rows);
og_matrix_destroy(&m);

matrix_init_array#

Unit tests

Creates a matrix from a plain C array given row by row or column by column.

og_error_t og_matrix_init_array(
    og_matrix_t *m,
    const og_real_t *data,
    og_int_t nrow,
    og_int_t ncol,
    og_matrix_storage_t storage
);

Reads nrow * ncol elements from data. With OG_COLUMN_MAJOR the array is taken as the matrix's own column-by-column layout; with OG_ROW_MAJOR element (i, j) is read from data[i * ncol + j]. The matrix gets its own copy, so data may be freed afterwards.

If storage is neither value the matrix is left zeroed (safe to destroy) and OG_EINVAL is returned.

Other element types: og_matrix_int_init_array, og_matrix_bool_init_array, og_matrix_char_init_array and og_matrix_complex_init_array (same arguments with the matching container and element types).

Parameters
  • m The matrix to initialise; not initialised yet.
  • data The elements; at least nrow * ncol of them.
  • nrow Number of rows.
  • ncol Number of columns.
  • storage OG_ROW_MAJOR or OG_COLUMN_MAJOR: how data is laid out.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL storage is not OG_ROW_MAJOR or OG_COLUMN_MAJOR, or a dimension is negative or too large.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_init_array
In notebooks
Og.Native.og_matrix_init_array
igraph 1.0
igraph_matrix_init_array
See also
matrix_init, matrix_copy_to, matrix_view, matrix_storage_t
const og_real_t a[] = { 1, 2, 3,
                       4, 5, 6 };   /* two rows */
og_matrix_t m;
og_matrix_init_array(&m, a, 2, 3, OG_ROW_MAJOR);
/* OG_MATRIX(m, 1, 0) == 4 */
og_matrix_destroy(&m);

matrix_init_copy#

Unit tests

Creates a new matrix holding a copy of another.

og_error_t og_matrix_init_copy(og_matrix_t *to, const og_matrix_t *from);

to gets the shape and the elements of from; from is not changed. to must not be initialised yet. To copy into a matrix that already exists, use matrix_update.

Other element types: og_matrix_int_init_copy, og_matrix_bool_init_copy, og_matrix_char_init_copy and og_matrix_complex_init_copy (same arguments with the matching container and element types).

Parameters
  • to The new matrix; not initialised yet.
  • from The matrix to copy.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_init_copy
In notebooks
Og.Native.og_matrix_init_copy
igraph 1.0
igraph_matrix_init_copy
See also
matrix_update, matrix_init, matrix_swap

matrix_destroy#

Unit tests

Frees the storage of a matrix.

void og_matrix_destroy(og_matrix_t *m);

Releases the elements and sets the shape to 0 by 0. Destroying a matrix twice, destroying one whose initialisation failed, and passing NULL are all harmless. Never destroy a view made with matrix_view or matrix_view_from_vector: it does not own its memory.

Other element types: og_matrix_int_destroy, og_matrix_bool_destroy, og_matrix_char_destroy and og_matrix_complex_destroy (same arguments with the matching container and element types).

Parameters
  • m The matrix, or NULL.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_destroy
In notebooks
Og.Native.og_matrix_destroy
igraph 1.0
igraph_matrix_destroy
See also
matrix_init, MATRIX_INIT_FINALLY

matrix_view#

Unit tests

Wraps an existing column-major C array as a matrix, without copying.

og_matrix_t og_matrix_view(
    const og_real_t *data,
    og_int_t nrow,
    og_int_t ncol
);

Returns, by value, a matrix whose storage is data (nrow * ncol elements, column by column). Nothing is allocated, so the call cannot fail. The view borrows the memory: the array must outlive the view, and the view must never be destroyed, resized or passed to a function that changes its size. Use it as a read-only matrix argument.

Other element types: og_matrix_int_view, og_matrix_bool_view, og_matrix_char_view and og_matrix_complex_view (same arguments with the matching container and element types).

Parameters
  • data Column-major elements, at least nrow * ncol of them.
  • nrow Number of rows.
  • ncol Number of columns.
Returns
The view (an matrix_t value).
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_view
In notebooks
Og.Native.og_matrix_view
igraph 1.0
igraph_matrix_view
See also
matrix_view_from_vector, matrix_init_array

matrix_view_from_vector#

Unit tests

Wraps the elements of a vector as a matrix with a given number of rows, without copying.

og_matrix_t og_matrix_view_from_vector(const og_vector_t *v, og_int_t nrow);

The number of columns is size(v) / nrow, rounded down: elements at the end that do not fill a whole column are left out. With nrow 0 the view is 0 by 0. The same rules as for matrix_view apply: never destroy or resize the view, and do not resize or destroy the vector while the view is in use.

Other element types: og_matrix_int_view_from_vector, og_matrix_bool_view_from_vector, og_matrix_char_view_from_vector and og_matrix_complex_view_from_vector (same arguments with the matching container and element types).

Parameters
  • v The vector whose elements are viewed.
  • nrow Number of rows of the view.
Returns
The view (an matrix_t value).
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_view_from_vector
In notebooks
Og.Native.og_matrix_view_from_vector
igraph 1.0
igraph_matrix_view_from_vector
See also
matrix_view, matrix_get_col

matrix_copy_to#

Unit tests

Copies the elements of a matrix into a plain C array, row by row or column by column.

void og_matrix_copy_to(
    const og_matrix_t *m,
    og_real_t *to,
    og_matrix_storage_t storage
);

to must have room for nrow * ncol elements. With OG_ROW_MAJOR element (i, j) goes to to[i * ncol + j]; any other value of storage copies the column-major storage as it is.

Other element types: og_matrix_int_copy_to, og_matrix_bool_copy_to, og_matrix_char_copy_to and og_matrix_complex_copy_to (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • to Destination array, at least nrow * ncol elements.
  • storage OG_ROW_MAJOR or OG_COLUMN_MAJOR: the layout wanted in to.
Returns
Nothing.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_copy_to
In notebooks
Og.Native.og_matrix_copy_to
igraph 1.0
igraph_matrix_copy_to
See also
matrix_init_array, matrix_storage_t

matrix_update#

Unit tests

Makes an existing matrix an exact copy of another.

og_error_t og_matrix_update(og_matrix_t *to, const og_matrix_t *from);

to must be initialised. It takes the shape of from and receives its elements; its storage is reused when it is large enough. Calling it with to == from does nothing. On failure to is unchanged.

Other element types: og_matrix_int_update, og_matrix_bool_update, og_matrix_char_update and og_matrix_complex_update (same arguments with the matching container and element types).

Parameters
  • to The destination matrix (initialised).
  • from The matrix to copy.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol) of from.
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_update
In notebooks
Og.Native.og_matrix_update
igraph 1.0
igraph_matrix_update
See also
matrix_init_copy, matrix_swap

matrix_swap#

Unit tests

Exchanges the contents of two matrices.

void og_matrix_swap(og_matrix_t *m1, og_matrix_t *m2);

The two objects trade their storage and shapes; no element is copied and nothing is allocated, so the cost does not depend on the sizes.

Other element types: og_matrix_int_swap, og_matrix_bool_swap, og_matrix_char_swap and og_matrix_complex_swap (same arguments with the matching container and element types).

Parameters
  • m1 First matrix.
  • m2 Second matrix.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_swap
In notebooks
Og.Native.og_matrix_swap
igraph 1.0
igraph_matrix_swap
See also
matrix_update

Elements, rows and columns

matrix_null#

Unit tests

Sets every element to zero.

void og_matrix_null(og_matrix_t *m);

Zero means 0 for numbers, false for bool and 0 + 0i for complex matrices. The shape does not change.

Other element types: og_matrix_int_null, og_matrix_bool_null, og_matrix_char_null and og_matrix_complex_null (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
Nothing.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_null
In notebooks
Og.Native.og_matrix_null
igraph 1.0
igraph_matrix_null
See also
matrix_fill, matrix_isnull

matrix_fill#

Unit tests

Sets every element to the same value.

void og_matrix_fill(og_matrix_t *m, og_real_t e);

The shape does not change.

Other element types: og_matrix_int_fill, og_matrix_bool_fill, og_matrix_char_fill and og_matrix_complex_fill (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • e The value to store everywhere.
Returns
Nothing.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_fill
In notebooks
Og.Native.og_matrix_fill
igraph 1.0
igraph_matrix_fill
See also
matrix_null, matrix_add_constant

matrix_get#

Unit tests

Returns element (row, col).

og_real_t og_matrix_get(const og_matrix_t *m, og_int_t row, og_int_t col);

There is no range check: row must be in 0 .. nrow-1 and col in 0 .. ncol-1. The macro MATRIX(m, row, col) does the same without a call and can also be assigned to.

Other element types: og_matrix_int_get, og_matrix_bool_get, og_matrix_char_get and og_matrix_complex_get (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • row Row index.
  • col Column index.
Returns
The element.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_get
In notebooks
Og.Native.og_matrix_get
igraph 1.0
igraph_matrix_get
See also
matrix_set, matrix_get_ptr, MATRIX

matrix_get_ptr#

Unit tests

Returns a pointer to element (row, col).

og_real_t *og_matrix_get_ptr(
    const og_matrix_t *m,
    og_int_t row,
    og_int_t col
);

There is no range check. The pointer stays valid until the matrix is resized, bound to, transposed into a new shape or destroyed.

Other element types: og_matrix_int_get_ptr, og_matrix_bool_get_ptr, og_matrix_char_get_ptr and og_matrix_complex_get_ptr (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • row Row index.
  • col Column index.
Returns
Pointer to the element.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_get_ptr
In notebooks
Og.Native.og_matrix_get_ptr
igraph 1.0
igraph_matrix_get_ptr
See also
matrix_get, MATRIX

matrix_set#

Unit tests

Sets element (row, col) to a value.

void og_matrix_set(
    og_matrix_t *m,
    og_int_t row,
    og_int_t col,
    og_real_t value
);

There is no range check: row must be in 0 .. nrow-1 and col in 0 .. ncol-1.

Other element types: og_matrix_int_set, og_matrix_bool_set, og_matrix_char_set and og_matrix_complex_set (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • row Row index.
  • col Column index.
  • value The new value.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_set
In notebooks
Og.Native.og_matrix_set
igraph 1.0
igraph_matrix_set
See also
matrix_get, MATRIX

matrix_get_row#

Unit tests

Copies one row of a matrix into a vector.

og_error_t og_matrix_get_row(
    const og_matrix_t *m,
    og_vector_t *res,
    og_int_t index
);

res (initialised) is resized to ncol and receives row index, column by column.

Other element types: og_matrix_int_get_row, og_matrix_bool_get_row, og_matrix_char_get_row and og_matrix_complex_get_row (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The output vector (initialised); resized.
  • index Row index, 0 .. nrow-1.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL index is out of range.
  • OG_ENOMEM Not enough memory.
Complexity
O(ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_get_row
In notebooks
Og.Native.og_matrix_get_row
igraph 1.0
igraph_matrix_get_row
See also
matrix_get_col, matrix_set_row, matrix_select_rows

matrix_get_col#

Unit tests

Copies one column of a matrix into a vector.

og_error_t og_matrix_get_col(
    const og_matrix_t *m,
    og_vector_t *res,
    og_int_t index
);

res (initialised) is resized to nrow and receives column index. Columns are contiguous in storage, so this is a single block copy.

Other element types: og_matrix_int_get_col, og_matrix_bool_get_col, og_matrix_char_get_col and og_matrix_complex_get_col (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The output vector (initialised); resized.
  • index Column index, 0 .. ncol-1.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL index is out of range.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_get_col
In notebooks
Og.Native.og_matrix_get_col
igraph 1.0
igraph_matrix_get_col
See also
matrix_get_row, matrix_set_col, matrix_select_cols

matrix_set_row#

Unit tests

Overwrites one row with the elements of a vector.

og_error_t og_matrix_set_row(
    og_matrix_t *m,
    const og_vector_t *v,
    og_int_t index
);

The vector must have exactly ncol elements; element j goes to column j of row index.

Other element types: og_matrix_int_set_row, og_matrix_bool_set_row, og_matrix_char_set_row and og_matrix_complex_set_row (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • v The new row; size(v) == ncol.
  • index Row index, 0 .. nrow-1.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL index is out of range, or size(v) differs from ncol.
Complexity
O(ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_set_row
In notebooks
Og.Native.og_matrix_set_row
igraph 1.0
igraph_matrix_set_row
See also
matrix_get_row, matrix_set_col

matrix_set_col#

Unit tests

Overwrites one column with the elements of a vector.

og_error_t og_matrix_set_col(
    og_matrix_t *m,
    const og_vector_t *v,
    og_int_t index
);

The vector must have exactly nrow elements.

Other element types: og_matrix_int_set_col, og_matrix_bool_set_col, og_matrix_char_set_col and og_matrix_complex_set_col (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • v The new column; size(v) == nrow.
  • index Column index, 0 .. ncol-1.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL index is out of range, or size(v) differs from nrow.
Complexity
O(nrow).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_set_col
In notebooks
Og.Native.og_matrix_set_col
igraph 1.0
igraph_matrix_set_col
See also
matrix_get_col, matrix_set_row

matrix_swap_rows#

Unit tests

Exchanges two rows in place.

og_error_t og_matrix_swap_rows(og_matrix_t *m, og_int_t i, og_int_t j);

Swapping a row with itself does nothing.

Other element types: og_matrix_int_swap_rows, og_matrix_bool_swap_rows, og_matrix_char_swap_rows and og_matrix_complex_swap_rows (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • i First row index.
  • j Second row index.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL i or j is out of range.
Complexity
O(ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_swap_rows
In notebooks
Og.Native.og_matrix_swap_rows
igraph 1.0
igraph_matrix_swap_rows
See also
matrix_swap_cols, matrix_select_rows

matrix_swap_cols#

Unit tests

Exchanges two columns in place.

og_error_t og_matrix_swap_cols(og_matrix_t *m, og_int_t i, og_int_t j);

Swapping a column with itself does nothing.

Other element types: og_matrix_int_swap_cols, og_matrix_bool_swap_cols, og_matrix_char_swap_cols and og_matrix_complex_swap_cols (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • i First column index.
  • j Second column index.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL i or j is out of range.
Complexity
O(nrow).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_swap_cols
In notebooks
Og.Native.og_matrix_swap_cols
igraph 1.0
igraph_matrix_swap_cols
See also
matrix_swap_rows, matrix_select_cols

matrix_select_rows#

Unit tests

Builds a matrix from chosen rows of another, in the order given.

og_error_t og_matrix_select_rows(
    const og_matrix_t *m,
    og_matrix_t *res,
    const og_vector_int_t *rows
);

Row k of res is row rows[k] of m. Indices may repeat and come in any order, so the result can have more rows than m. res must be initialised and is resized to size(rows) by ncol. res may be m itself: the selection is then built in a temporary matrix and swapped in.

Every index is checked before anything changes.

Other element types: og_matrix_int_select_rows, og_matrix_bool_select_rows, og_matrix_char_select_rows and og_matrix_complex_select_rows (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The result (initialised); resized. May be m.
  • rows Row indices into m.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL An index is outside 0 .. nrow-1.
  • OG_ENOMEM Not enough memory.
Complexity
O(size(rows) * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_select_rows
In notebooks
Og.Native.og_matrix_select_rows
igraph 1.0
igraph_matrix_select_rows
See also
matrix_select_cols, matrix_select_rows_cols, matrix_get_row

matrix_select_cols#

Unit tests

Builds a matrix from chosen columns of another, in the order given.

og_error_t og_matrix_select_cols(
    const og_matrix_t *m,
    og_matrix_t *res,
    const og_vector_int_t *cols
);

Column k of res is column cols[k] of m. Indices may repeat and come in any order. res must be initialised and is resized to nrow by size(cols); it may be m itself. Every index is checked before anything changes.

Other element types: og_matrix_int_select_cols, og_matrix_bool_select_cols, og_matrix_char_select_cols and og_matrix_complex_select_cols (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The result (initialised); resized. May be m.
  • cols Column indices into m.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL An index is outside 0 .. ncol-1.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * size(cols)).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_select_cols
In notebooks
Og.Native.og_matrix_select_cols
igraph 1.0
igraph_matrix_select_cols
See also
matrix_select_rows, matrix_select_rows_cols, matrix_get_col

matrix_select_rows_cols#

Unit tests

Builds a matrix from chosen rows and columns of another.

og_error_t og_matrix_select_rows_cols(
    const og_matrix_t *m,
    og_matrix_t *res,
    const og_vector_int_t *rows,
    const og_vector_int_t *cols
);

res(k, l) = m(rows[k], cols[l]). Indices may repeat and come in any order. res must be initialised and is resized to size(rows) by size(cols); it may be m itself. Every index is checked before anything changes.

Other element types: og_matrix_int_select_rows_cols, og_matrix_bool_select_rows_cols, og_matrix_char_select_rows_cols and og_matrix_complex_select_rows_cols (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The result (initialised); resized. May be m.
  • rows Row indices into m.
  • cols Column indices into m.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL A row or column index is out of range.
  • OG_ENOMEM Not enough memory.
Complexity
O(size(rows) * size(cols)).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_select_rows_cols
In notebooks
Og.Native.og_matrix_select_rows_cols
igraph 1.0
igraph_matrix_select_rows_cols
See also
matrix_select_rows, matrix_select_cols

matrix_transpose#

Unit tests

Transposes a matrix in place.

og_error_t og_matrix_transpose(og_matrix_t *m);

A square matrix is transposed by swapping elements across the diagonal, without allocating. A single row or column has the same storage as its transpose, so only the shape changes. Any other shape is rearranged through a temporary buffer of nrow * ncol elements; if that allocation fails the matrix is unchanged.

Other element types: og_matrix_int_transpose, og_matrix_bool_transpose, og_matrix_char_transpose and og_matrix_complex_transpose (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_transpose
In notebooks
Og.Native.og_matrix_transpose
igraph 1.0
igraph_matrix_transpose
See also
matrix_is_symmetric

matrix_rbind#

Unit tests

Appends the rows of one matrix below another.

og_error_t og_matrix_rbind(og_matrix_t *to, const og_matrix_t *from);

to grows by the rows of from; both must have the same number of columns. from may be to itself, which stacks the matrix on top of itself. Appending a matrix with no rows does nothing.

Other element types: og_matrix_int_rbind, og_matrix_bool_rbind, og_matrix_char_rbind and og_matrix_complex_rbind (same arguments with the matching container and element types).

Parameters
  • to The matrix that grows.
  • from The rows to append.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The column counts differ, or the result would be too large.
  • OG_ENOMEM Not enough memory.
Complexity
O((nrow(to) + nrow(from)) * ncol): the existing columns move inside the storage.
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_rbind
In notebooks
Og.Native.og_matrix_rbind
igraph 1.0
igraph_matrix_rbind
See also
matrix_cbind, matrix_add_rows

matrix_cbind#

Unit tests

Appends the columns of one matrix to the right of another.

og_error_t og_matrix_cbind(og_matrix_t *to, const og_matrix_t *from);

to grows by the columns of from; both must have the same number of rows. from may be to itself.

Other element types: og_matrix_int_cbind, og_matrix_bool_cbind, og_matrix_char_cbind and og_matrix_complex_cbind (same arguments with the matching container and element types).

Parameters
  • to The matrix that grows.
  • from The columns to append.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The row counts differ, or the result would be too large.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol(from)), plus a copy of to when its storage has to grow.
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_cbind
In notebooks
Og.Native.og_matrix_cbind
igraph 1.0
igraph_matrix_cbind
See also
matrix_rbind, matrix_add_cols

Arithmetic

matrix_add_constant#

Unit tests

Increases every element by the same amount.

void og_matrix_add_constant(og_matrix_t *m, og_real_t plus);

m(i, j) += plus for every element. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_add_constant and og_matrix_char_add_constant (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • plus The value to add.
Returns
Nothing.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_add_constant
In notebooks
Og.Native.og_matrix_add_constant
igraph 1.0
igraph_matrix_add_constant
See also
matrix_scale, matrix_add, matrix_fill

matrix_scale#

Unit tests

Scales every element by the same factor.

void og_matrix_scale(og_matrix_t *m, og_real_t by);

m(i, j) *= by for every element. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_scale and og_matrix_char_scale (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • by The factor.
Returns
Nothing.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_scale
In notebooks
Og.Native.og_matrix_scale
igraph 1.0
igraph_matrix_scale
See also
matrix_add_constant, matrix_mul_elements

matrix_add#

Unit tests

Adds a second matrix to the first, element by element.

og_error_t og_matrix_add(og_matrix_t *m1, const og_matrix_t *m2);

m1 += m2. Both must have the same shape; m2 is not changed. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_add and og_matrix_char_add (same arguments with the matching container and element types).

Parameters
  • m1 The matrix that receives the sum.
  • m2 The matrix to add.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The two matrices differ in shape.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_add
In notebooks
Og.Native.og_matrix_add
igraph 1.0
igraph_matrix_add
See also
matrix_sub, matrix_add_constant

matrix_sub#

Unit tests

Subtracts a second matrix from the first, element by element.

og_error_t og_matrix_sub(og_matrix_t *m1, const og_matrix_t *m2);

m1 -= m2. Both must have the same shape. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_sub and og_matrix_char_sub (same arguments with the matching container and element types).

Parameters
  • m1 The matrix that receives the difference.
  • m2 The matrix to subtract.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The two matrices differ in shape.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_sub
In notebooks
Og.Native.og_matrix_sub
igraph 1.0
igraph_matrix_sub
See also
matrix_add

matrix_mul_elements#

Unit tests

Multiplies two matrices element by element.

og_error_t og_matrix_mul_elements(og_matrix_t *m1, const og_matrix_t *m2);

m1(i, j) *= m2(i, j) for every element (the element-wise product, not the matrix product). Both must have the same shape. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_mul_elements and og_matrix_char_mul_elements (same arguments with the matching container and element types).

Parameters
  • m1 The matrix that receives the product.
  • m2 The other factor.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The two matrices differ in shape.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_mul_elements
In notebooks
Og.Native.og_matrix_mul_elements
igraph 1.0
igraph_matrix_mul_elements
See also
matrix_div_elements, matrix_scale

matrix_div_elements#

Unit tests

Divides a matrix by another, element by element.

og_error_t og_matrix_div_elements(og_matrix_t *m1, const og_matrix_t *m2);

m1(i, j) /= m2(i, j) for every element. Both must have the same shape. Real division follows IEEE 754 (x / 0 gives an infinity or NaN). For int and char matrices a zero anywhere in m2 is refused before anything is written; integer division truncates toward zero, and OG_INTEGER_MIN / -1 gives OG_INTEGER_MIN.

Other element types: og_matrix_int_div_elements and og_matrix_char_div_elements (same arguments with the matching container and element types).

Parameters
  • m1 The dividend; receives the quotient.
  • m2 The divisor.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL The shapes differ, or (int and char) m2 holds a zero.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_div_elements
In notebooks
Og.Native.og_matrix_div_elements
igraph 1.0
igraph_matrix_div_elements
See also
matrix_mul_elements

matrix_sum#

Unit tests

Returns the sum of all elements.

og_real_t og_matrix_sum(const og_matrix_t *m);

Elements are added in storage (column-major) order. An empty matrix gives 0. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_sum and og_matrix_char_sum (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The sum.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_sum
In notebooks
Og.Native.og_matrix_sum
igraph 1.0
igraph_matrix_sum
See also
matrix_prod, matrix_rowsum, matrix_colsum

matrix_prod#

Unit tests

Returns the product of all elements.

og_real_t og_matrix_prod(const og_matrix_t *m);

Elements are multiplied in storage (column-major) order. An empty matrix gives 1. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_prod and og_matrix_char_prod (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The product.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_prod
In notebooks
Og.Native.og_matrix_prod
igraph 1.0
igraph_matrix_prod
See also
matrix_sum

matrix_rowsum#

Unit tests

Computes the sum of each row.

og_error_t og_matrix_rowsum(const og_matrix_t *m, og_vector_t *res);

res (initialised) is resized to nrow; res[i] is the sum of row i. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_rowsum and og_matrix_char_rowsum (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The output vector (initialised); resized.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_rowsum
In notebooks
Og.Native.og_matrix_rowsum
igraph 1.0
igraph_matrix_rowsum
See also
matrix_colsum, matrix_sum

matrix_colsum#

Unit tests

Computes the sum of each column.

og_error_t og_matrix_colsum(const og_matrix_t *m, og_vector_t *res);

res (initialised) is resized to ncol; res[j] is the sum of column j. Defined for real, int and char matrices. Integer results that overflow wrap around (modulo 2^64 for int), the same on every platform.

Other element types: og_matrix_int_colsum and og_matrix_char_colsum (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • res The output vector (initialised); resized.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_colsum
In notebooks
Og.Native.og_matrix_colsum
igraph 1.0
igraph_matrix_colsum
See also
matrix_rowsum, matrix_sum

Complex matrices

matrix_complex_real#

Unit tests

Copies the real parts of a complex matrix into a real matrix.

og_error_t og_matrix_complex_real(
    const og_matrix_complex_t *m,
    og_matrix_t *real
);

real must be initialised; it is resized to the shape of m.

Parameters
  • m The complex matrix.
  • real Output real matrix (initialised); resized.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_real
In notebooks
Og.Native.og_matrix_complex_real
igraph 1.0
igraph_matrix_complex_real
See also
matrix_complex_imag, matrix_complex_realimag, matrix_complex_create

matrix_complex_imag#

Unit tests

Copies the imaginary parts of a complex matrix into a real matrix.

og_error_t og_matrix_complex_imag(
    const og_matrix_complex_t *m,
    og_matrix_t *imag
);

imag must be initialised; it is resized to the shape of m.

Parameters
  • m The complex matrix.
  • imag Output real matrix (initialised); resized.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_imag
In notebooks
Og.Native.og_matrix_complex_imag
igraph 1.0
igraph_matrix_complex_imag
See also
matrix_complex_real, matrix_complex_realimag

matrix_complex_realimag#

Unit tests

Copies the real and the imaginary parts of a complex matrix into two real matrices.

og_error_t og_matrix_complex_realimag(
    const og_matrix_complex_t *m,
    og_matrix_t *real,
    og_matrix_t *imag
);

Both outputs must be initialised; they are resized to the shape of m.

Parameters
  • m The complex matrix.
  • real Output for the real parts (initialised).
  • imag Output for the imaginary parts (initialised).
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_realimag
In notebooks
Og.Native.og_matrix_complex_realimag
igraph 1.0
igraph_matrix_complex_realimag
See also
matrix_complex_real, matrix_complex_imag, matrix_complex_create

matrix_complex_create#

Unit tests

Builds a complex matrix from two real matrices: real parts and imaginary parts.

og_error_t og_matrix_complex_create(
    og_matrix_complex_t *m,
    const og_matrix_t *real,
    const og_matrix_t *imag
);

m(i, j) = real(i, j) + i * imag(i, j). m must not be initialised; the two real matrices must have the same shape. On failure m is left zeroed, so destroying it is harmless.

Parameters
  • m The new complex matrix; not initialised yet.
  • real Real parts.
  • imag Imaginary parts.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL real and imag differ in shape.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_create
In notebooks
Og.Native.og_matrix_complex_create
igraph 1.0
igraph_matrix_complex_create
See also
matrix_complex_create_polar, matrix_complex_realimag

matrix_complex_create_polar#

Unit tests

Builds a complex matrix from moduli and angles in radians.

og_error_t og_matrix_complex_create_polar(
    og_matrix_complex_t *m,
    const og_matrix_t *r,
    const og_matrix_t *theta
);

m(i, j) = r(i, j) cos(theta(i, j)) + i r(i, j) sin(theta(i, j)), angles in radians. m must not be initialised; r and theta must have the same shape. On failure m is left zeroed.

Parameters
  • m The new complex matrix; not initialised yet.
  • r Moduli.
  • theta Angles in radians.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL r and theta differ in shape.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_create_polar
In notebooks
Og.Native.og_matrix_complex_create_polar
igraph 1.0
igraph_matrix_complex_create_polar
See also
matrix_complex_create

matrix_complex_all_almost_e#

Unit tests

Tells whether two complex matrices are equal within a relative tolerance.

og_bool_t og_matrix_complex_all_almost_e(
    const og_matrix_complex_t *lhs,
    const og_matrix_complex_t *rhs,
    og_real_t eps
);

Both must have the same shape (otherwise false). Each pair a, b is compared with complex_almost_equals: equal when a == b or |a - b| / (|a| + |b|) < eps, with |.| the complex modulus. Elements with an infinite part are equal only when they match exactly; NaN is never equal.

Parameters
  • lhs First matrix.
  • rhs Second matrix.
  • eps Relative tolerance.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_all_almost_e
In notebooks
Og.Native.og_matrix_complex_all_almost_e
igraph 1.0
igraph_matrix_complex_all_almost_e
See also
matrix_all_almost_e, matrix_complex_zapsmall

matrix_complex_zapsmall#

Unit tests

Sets the real or imaginary parts that are very close to zero to exactly zero.

og_error_t og_matrix_complex_zapsmall(
    og_matrix_complex_t *m,
    og_real_t tol
);

Each part is judged on its own: a part with magnitude below tol becomes 0. tol = 0 selects DBL_EPSILON^(2/3), about 3.7e-11.

Parameters
  • m The complex matrix.
  • tol Threshold, 0 or more; 0 means the default.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL tol is negative or NaN.
Complexity
O(nrow * ncol).
Checked
python-igraph has no complex matrices; unit tests, the numpy operation sequences and the row-major model checks.
C name
og_matrix_complex_zapsmall
In notebooks
Og.Native.og_matrix_complex_zapsmall
igraph 1.0
igraph_matrix_complex_zapsmall
See also
matrix_zapsmall, matrix_complex_all_almost_e

Comparing, minimum and maximum

matrix_all_e#

Unit tests

Tells whether two matrices have the same shape and equal elements.

og_bool_t og_matrix_all_e(const og_matrix_t *lhs, const og_matrix_t *rhs);

Elements are compared exactly. A NaN is never equal to anything, so a real matrix holding a NaN is not equal even to itself. Complex elements are equal when both parts are. Matrices of different shapes are not equal, even with the same number of elements.

Other element types: og_matrix_int_all_e, og_matrix_bool_all_e, og_matrix_char_all_e and og_matrix_complex_all_e (same arguments with the matching container and element types).

Parameters
  • lhs First matrix.
  • rhs Second matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_e
In notebooks
Og.Native.og_matrix_all_e
igraph 1.0
igraph_matrix_all_e
See also
matrix_all_almost_e, matrix_maxdifference

matrix_all_almost_e#

Unit tests

Tells whether two real matrices are equal within a relative tolerance.

og_bool_t og_matrix_all_almost_e(
    const og_matrix_t *lhs,
    const og_matrix_t *rhs,
    og_real_t eps
);

Both matrices must have the same shape (otherwise the result is false). Each pair of elements a, b is compared with almost_equals: they count as equal when a == b or |a - b| / (|a| + |b|) < eps. There is no absolute tolerance near zero, so 0 against any non-zero value has relative difference 1; eps = 0 asks for exact equality. NaN is never equal.

Parameters
  • lhs First matrix.
  • rhs Second matrix.
  • eps Relative tolerance, for example 1e-10.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_almost_e
In notebooks
Og.Native.og_matrix_all_almost_e
igraph 1.0
igraph_matrix_all_almost_e
See also
matrix_all_e, matrix_complex_all_almost_e, matrix_zapsmall

matrix_all_l#

Unit tests

Tells whether every element of the first matrix is smaller than the matching element of the second.

og_bool_t og_matrix_all_l(const og_matrix_t *lhs, const og_matrix_t *rhs);

Checks lhs(i, j) < rhs(i, j) everywhere. False when the shapes differ, and false whenever a NaN takes part in a comparison. Two empty matrices of the same shape give true. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_all_l, og_matrix_bool_all_l and og_matrix_char_all_l (same arguments with the matching container and element types).

Parameters
  • lhs Left matrix.
  • rhs Right matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_l
In notebooks
Og.Native.og_matrix_all_l
igraph 1.0
igraph_matrix_all_l
See also
matrix_all_le, matrix_all_g, matrix_all_ge, matrix_all_e

matrix_all_g#

Unit tests

Tells whether every element of the first matrix is larger than the matching element of the second.

og_bool_t og_matrix_all_g(const og_matrix_t *lhs, const og_matrix_t *rhs);

Checks lhs(i, j) > rhs(i, j) everywhere. False when the shapes differ, and false whenever a NaN takes part in a comparison. Two empty matrices of the same shape give true. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_all_g, og_matrix_bool_all_g and og_matrix_char_all_g (same arguments with the matching container and element types).

Parameters
  • lhs Left matrix.
  • rhs Right matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_g
In notebooks
Og.Native.og_matrix_all_g
igraph 1.0
igraph_matrix_all_g
See also
matrix_all_ge, matrix_all_l

matrix_all_le#

Unit tests

Tells whether every element of the first matrix is at most the matching element of the second.

og_bool_t og_matrix_all_le(const og_matrix_t *lhs, const og_matrix_t *rhs);

Checks lhs(i, j) <= rhs(i, j) everywhere. False when the shapes differ, and false whenever a NaN takes part in a comparison. Two empty matrices of the same shape give true. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_all_le, og_matrix_bool_all_le and og_matrix_char_all_le (same arguments with the matching container and element types).

Parameters
  • lhs Left matrix.
  • rhs Right matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_le
In notebooks
Og.Native.og_matrix_all_le
igraph 1.0
igraph_matrix_all_le
See also
matrix_all_l, matrix_all_ge

matrix_all_ge#

Unit tests

Tells whether every element of the first matrix is at least the matching element of the second.

og_bool_t og_matrix_all_ge(const og_matrix_t *lhs, const og_matrix_t *rhs);

Checks lhs(i, j) >= rhs(i, j) everywhere. False when the shapes differ, and false whenever a NaN takes part in a comparison. Two empty matrices of the same shape give true. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_all_ge, og_matrix_bool_all_ge and og_matrix_char_all_ge (same arguments with the matching container and element types).

Parameters
  • lhs Left matrix.
  • rhs Right matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_all_ge
In notebooks
Og.Native.og_matrix_all_ge
igraph 1.0
igraph_matrix_all_ge
See also
matrix_all_g, matrix_all_le

matrix_zapsmall#

Unit tests

Sets the elements that are very close to zero to exactly zero.

og_error_t og_matrix_zapsmall(og_matrix_t *m, og_real_t tol);

Every element with |x| < tol becomes 0. tol = 0 selects DBL_EPSILON^(2/3), about 3.7e-11. Useful to remove rounding noise before printing or comparing results. Real matrices only; matrix_complex_zapsmall does the same for complex ones.

Parameters
  • m The matrix.
  • tol Threshold, 0 or more; 0 means the default above.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL tol is negative or NaN.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_zapsmall
In notebooks
Og.Native.og_matrix_zapsmall
igraph 1.0
igraph_matrix_zapsmall
See also
matrix_complex_zapsmall, matrix_all_almost_e

matrix_min#

Unit tests

Returns the smallest element.

og_real_t og_matrix_min(const og_matrix_t *m);

If the matrix holds a NaN the result is NaN. For an empty matrix the result is NaN for real matrices and 0 for int, bool and char ones. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_min, og_matrix_bool_min and og_matrix_char_min (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The smallest element.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_min
In notebooks
Og.Native.og_matrix_min
igraph 1.0
igraph_matrix_min
See also
matrix_max, matrix_which_min, matrix_minmax

matrix_max#

Unit tests

Returns the largest element.

og_real_t og_matrix_max(const og_matrix_t *m);

If the matrix holds a NaN the result is NaN. For an empty matrix the result is NaN for real matrices and 0 for int, bool and char ones. Defined for real, int, bool and char matrices.

Other element types: og_matrix_int_max, og_matrix_bool_max and og_matrix_char_max (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The largest element.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_max
In notebooks
Og.Native.og_matrix_max
igraph 1.0
igraph_matrix_max
See also
matrix_min, matrix_which_max, matrix_minmax

matrix_which_min#

Unit tests

Finds the row and column of the smallest element.

void og_matrix_which_min(const og_matrix_t *m, og_int_t *i, og_int_t *j);

Among equal values the first one in column-major order wins. If the matrix holds a NaN, the position of the first NaN is returned. The matrix must not be empty: an empty one stops the program through the fatal handler (OG_ASSERT), as reading past the end would.

Other element types: og_matrix_int_which_min, og_matrix_bool_which_min and og_matrix_char_which_min (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • i Receives the row.
  • j Receives the column.
Returns
Nothing; the position goes to *i and *j.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included). The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_matrix_which_min
In notebooks
Og.Native.og_matrix_which_min
igraph 1.0
igraph_matrix_which_min
See also
matrix_which_max, matrix_which_minmax, matrix_min

matrix_which_max#

Unit tests

Finds the row and column of the largest element.

void og_matrix_which_max(const og_matrix_t *m, og_int_t *i, og_int_t *j);

Among equal values the first one in column-major order wins. If the matrix holds a NaN, the position of the first NaN is returned. The matrix must not be empty: an empty one stops the program through the fatal handler (OG_ASSERT), as reading past the end would.

Other element types: og_matrix_int_which_max, og_matrix_bool_which_max and og_matrix_char_which_max (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • i Receives the row.
  • j Receives the column.
Returns
Nothing; the position goes to *i and *j.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included). The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_matrix_which_max
In notebooks
Og.Native.og_matrix_which_max
igraph 1.0
igraph_matrix_which_max
See also
matrix_which_min, matrix_which_minmax, matrix_max

matrix_minmax#

Unit tests

Returns the smallest and the largest element in one pass.

void og_matrix_minmax(const og_matrix_t *m, og_real_t *min, og_real_t *max);

Either output pointer may be NULL. A NaN in the matrix makes both results NaN. The matrix must not be empty: an empty one stops the program through the fatal handler (OG_ASSERT), as reading past the end would.

Other element types: og_matrix_int_minmax, og_matrix_bool_minmax and og_matrix_char_minmax (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • min Receives the smallest element, or NULL.
  • max Receives the largest element, or NULL.
Returns
Nothing; the values go to *min and *max.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included). The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_matrix_minmax
In notebooks
Og.Native.og_matrix_minmax
igraph 1.0
igraph_matrix_minmax
See also
matrix_which_minmax, matrix_min, matrix_max

matrix_which_minmax#

Unit tests

Finds the positions of the smallest and the largest element in one pass.

void og_matrix_which_minmax(
    const og_matrix_t *m,
    og_int_t *imin,
    og_int_t *jmin,
    og_int_t *imax,
    og_int_t *jmax
);

Ties go to the first position in column-major order. A NaN in the matrix gives the position of the first NaN for both. All four pointers must be valid. The matrix must not be empty: an empty one stops the program through the fatal handler (OG_ASSERT), as reading past the end would.

Other element types: og_matrix_int_which_minmax, og_matrix_bool_which_minmax and og_matrix_char_which_minmax (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • imin Receives the row of the minimum.
  • jmin Receives the column of the minimum.
  • imax Receives the row of the maximum.
  • jmax Receives the column of the maximum.
Returns
Nothing; the positions go to the four outputs.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included). The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_matrix_which_minmax
In notebooks
Og.Native.og_matrix_which_minmax
igraph 1.0
igraph_matrix_which_minmax
See also
matrix_minmax, matrix_which_min, matrix_which_max

matrix_maxdifference#

Unit tests

Returns the largest absolute difference between matching elements of two matrices.

og_real_t og_matrix_maxdifference(
    const og_matrix_t *m1,
    const og_matrix_t *m2
);

Defined for real, int and char matrices; the result is always a real number. When the shapes differ, a warning is issued and elements are paired by their position in column-major storage, up to the smaller element count. A NaN difference makes the result NaN, and an empty operand gives 0.

For int matrices the difference is taken in integers whenever it fits, so it is exact up to one final rounding to a double.

Other element types: og_matrix_int_maxdifference and og_matrix_char_maxdifference (same arguments with the matching container and element types).

Parameters
  • m1 First matrix.
  • m2 Second matrix.
Returns
max |m1 - m2|.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_maxdifference
In notebooks
Og.Native.og_matrix_maxdifference
igraph 1.0
igraph_matrix_maxdifference
See also
matrix_all_almost_e, matrix_all_e

Size and properties

matrix_empty#

Unit tests

Tells whether a matrix has no elements.

og_bool_t og_matrix_empty(const og_matrix_t *m);

True when the number of rows or the number of columns is zero.

Other element types: og_matrix_int_empty, og_matrix_bool_empty, og_matrix_char_empty and og_matrix_complex_empty (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
true or false.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_empty
In notebooks
Og.Native.og_matrix_empty
igraph 1.0
igraph_matrix_empty
See also
matrix_size, matrix_isnull

matrix_isnull#

Unit tests

Tells whether every element is zero.

og_bool_t og_matrix_isnull(const og_matrix_t *m);

An empty matrix gives true. -0.0 counts as zero; NaN does not. A complex element needs both parts zero; a bool matrix needs every element false.

Other element types: og_matrix_int_isnull, og_matrix_bool_isnull, og_matrix_char_isnull and og_matrix_complex_isnull (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_isnull
In notebooks
Og.Native.og_matrix_isnull
igraph 1.0
igraph_matrix_isnull
See also
matrix_null, matrix_empty

matrix_size#

Unit tests

Returns the number of elements, nrow * ncol.

og_int_t og_matrix_size(const og_matrix_t *m);

This is the number of elements in use, not the allocated room (see matrix_capacity).

Other element types: og_matrix_int_size, og_matrix_bool_size, og_matrix_char_size and og_matrix_complex_size (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
nrow * ncol.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_size
In notebooks
Og.Native.og_matrix_size
igraph 1.0
igraph_matrix_size
See also
matrix_nrow, matrix_ncol, matrix_capacity

matrix_capacity#

Unit tests

Returns how many elements the storage has room for.

og_int_t og_matrix_capacity(const og_matrix_t *m);

Always at least matrix_size. Shrinking a matrix keeps its storage; matrix_resize_min gives the spare room back.

Other element types: og_matrix_int_capacity, og_matrix_bool_capacity, og_matrix_char_capacity and og_matrix_complex_capacity (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The allocated number of elements.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_capacity
In notebooks
Og.Native.og_matrix_capacity
igraph 1.0
igraph_matrix_capacity
See also
matrix_resize_min, matrix_size

matrix_nrow#

Unit tests

Returns the number of rows.

og_int_t og_matrix_nrow(const og_matrix_t *m);

Same as reading the field m->nrow.

Other element types: og_matrix_int_nrow, og_matrix_bool_nrow, og_matrix_char_nrow and og_matrix_complex_nrow (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The number of rows.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_nrow
In notebooks
Og.Native.og_matrix_nrow
igraph 1.0
igraph_matrix_nrow
See also
matrix_ncol, matrix_size

matrix_ncol#

Unit tests

Returns the number of columns.

og_int_t og_matrix_ncol(const og_matrix_t *m);

Same as reading the field m->ncol.

Other element types: og_matrix_int_ncol, og_matrix_bool_ncol, og_matrix_char_ncol and og_matrix_complex_ncol (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
The number of columns.
Complexity
O(1).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_ncol
In notebooks
Og.Native.og_matrix_ncol
igraph 1.0
igraph_matrix_ncol
See also
matrix_nrow, matrix_size

matrix_is_symmetric#

Unit tests

Tells whether a matrix is square and equal to its transpose.

og_bool_t og_matrix_is_symmetric(const og_matrix_t *m);

Elements are compared exactly, so a NaN off the diagonal makes the result false. A non-square matrix gives false; a 0 by 0 matrix gives true. Complex matrices are compared as they are (m(i, j) == m(j, i)), not against the conjugate transpose.

Other element types: og_matrix_int_is_symmetric, og_matrix_bool_is_symmetric, og_matrix_char_is_symmetric and og_matrix_complex_is_symmetric (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_is_symmetric
In notebooks
Og.Native.og_matrix_is_symmetric
igraph 1.0
igraph_matrix_is_symmetric
See also
matrix_transpose, sparsemat_is_symmetric

matrix_contains#

Unit tests

Tells whether a value occurs in a matrix.

og_bool_t og_matrix_contains(const og_matrix_t *m, og_real_t e);

Exact comparison; for real matrices a NaN is never found.

Other element types: og_matrix_int_contains, og_matrix_bool_contains, og_matrix_char_contains and og_matrix_complex_contains (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • e The value to look for.
Returns
true or false.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_contains
In notebooks
Og.Native.og_matrix_contains
igraph 1.0
igraph_matrix_contains
See also
matrix_search

matrix_resize#

Unit tests

Changes the shape of a matrix.

og_error_t og_matrix_resize(og_matrix_t *m, og_int_t nrow, og_int_t ncol);

The storage keeps its elements in place: an element stays at the same position of the column-major storage, so after a change in the number of rows it belongs to another (i, j). Elements beyond the old size are not set. To grow while keeping every element at its (i, j), use matrix_add_rows or matrix_add_cols.

Shrinking never reallocates. Growing past the capacity at least doubles it. On failure the matrix is unchanged.

Other element types: og_matrix_int_resize, og_matrix_bool_resize, og_matrix_char_resize and og_matrix_complex_resize (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • nrow New number of rows.
  • ncol New number of columns.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL A dimension is negative, or nrow * ncol does not fit in og_int_t.
  • OG_ENOMEM Not enough memory.
Complexity
O(1) when the capacity suffices, otherwise O(nrow * ncol) for the copy.
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_resize
In notebooks
Og.Native.og_matrix_resize
igraph 1.0
igraph_matrix_resize
See also
matrix_resize_min, matrix_add_rows, matrix_add_cols

matrix_resize_min#

Unit tests

Gives back the spare storage, so that the capacity equals the number of elements.

void og_matrix_resize_min(og_matrix_t *m);

Never fails: if the smaller block cannot be obtained, the matrix keeps its current storage, which is still valid. An empty matrix ends with capacity 0.

Other element types: og_matrix_int_resize_min, og_matrix_bool_resize_min, og_matrix_char_resize_min and og_matrix_complex_resize_min (same arguments with the matching container and element types).

Parameters
  • m The matrix.
Returns
Nothing.
Complexity
O(nrow * ncol) at most (one reallocation).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_resize_min
In notebooks
Og.Native.og_matrix_resize_min
igraph 1.0
igraph_matrix_resize_min
See also
matrix_capacity, matrix_resize

matrix_add_rows#

Unit tests

Adds rows of zeros at the bottom.

og_error_t og_matrix_add_rows(og_matrix_t *m, og_int_t n);

Existing elements keep their (i, j); the columns are moved inside the storage to make room. n = 0 does nothing.

Other element types: og_matrix_int_add_rows, og_matrix_bool_add_rows, og_matrix_char_add_rows and og_matrix_complex_add_rows (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • n Number of rows to add, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL n is negative, or the result would be too large.
  • OG_ENOMEM Not enough memory.
Complexity
O((nrow + n) * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_add_rows
In notebooks
Og.Native.og_matrix_add_rows
igraph 1.0
igraph_matrix_add_rows
See also
matrix_add_cols, matrix_rbind, matrix_remove_row

matrix_add_cols#

Unit tests

Adds columns of zeros at the right.

og_error_t og_matrix_add_cols(og_matrix_t *m, og_int_t n);

Existing elements keep their (i, j); the new columns are appended at the end of the storage.

Other element types: og_matrix_int_add_cols, og_matrix_bool_add_cols, og_matrix_char_add_cols and og_matrix_complex_add_cols (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • n Number of columns to add, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL n is negative, or the result would be too large.
  • OG_ENOMEM Not enough memory.
Complexity
O(nrow * n), plus a copy when the storage has to grow.
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_add_cols
In notebooks
Og.Native.og_matrix_add_cols
igraph 1.0
igraph_matrix_add_cols
See also
matrix_add_rows, matrix_cbind, matrix_remove_col

matrix_remove_row#

Unit tests

Deletes one row.

og_error_t og_matrix_remove_row(og_matrix_t *m, og_int_t row);

The rows below move up by one. The storage is compacted in place; its capacity does not change.

Other element types: og_matrix_int_remove_row, og_matrix_bool_remove_row, og_matrix_char_remove_row and og_matrix_complex_remove_row (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • row Index of the row to delete.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL row is out of range.
Complexity
O(nrow * ncol).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_remove_row
In notebooks
Og.Native.og_matrix_remove_row
igraph 1.0
igraph_matrix_remove_row
See also
matrix_remove_col, matrix_add_rows

matrix_remove_col#

Unit tests

Deletes one column.

og_error_t og_matrix_remove_col(og_matrix_t *m, og_int_t col);

The columns to the right move left by one. The capacity does not change.

Other element types: og_matrix_int_remove_col, og_matrix_bool_remove_col, og_matrix_char_remove_col and og_matrix_complex_remove_col (same arguments with the matching container and element types).

Parameters
  • m The matrix.
  • col Index of the column to delete.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL col is out of range.
Complexity
O(nrow * (ncol - col)).
Checked
python-igraph has no binding for C matrices, so igraph's own answers cannot be compared; checked against numpy (300 seeded cases, 290 operation sequences on every element type) and an independent row-major model (1,000 random 120-step sequences per element type, each allocation failure included).
C name
og_matrix_remove_col
In notebooks
Og.Native.og_matrix_remove_col
igraph 1.0
igraph_matrix_remove_col
See also
matrix_remove_row, matrix_add_cols

Three-dimensional arrays

array3_init#

Unit tests

Creates an n1 x n2 x n3 array with every element zero.

og_error_t og_array3_init(
    og_array3_t *a,
    og_int_t n1,
    og_int_t n2,
    og_int_t n3
);

The array must not be initialised yet; free it with array3_destroy. On failure it is left zeroed.

Other element types: og_array3_int_init, og_array3_char_init and og_array3_bool_init (same arguments with the matching container and element types).

Parameters
  • a The array to initialise.
  • n1 First dimension.
  • n2 Second dimension.
  • n3 Third dimension.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL A dimension is negative or the product does not fit in og_int_t.
  • OG_ENOMEM Not enough memory.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_init
In notebooks
Og.Native.og_array3_init
See also
array3_destroy, array3_resize

array3_destroy#

Unit tests

Frees the storage of a three-dimensional array.

void og_array3_destroy(og_array3_t *a);

Destroying twice is harmless.

Other element types: og_array3_int_destroy, og_array3_char_destroy and og_array3_bool_destroy (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
Nothing.
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_destroy
In notebooks
Og.Native.og_array3_destroy
See also
array3_init

array3_size#

Unit tests

Returns the number of elements, n1 n2 n3.

og_int_t og_array3_size(const og_array3_t *a);

Other element types: og_array3_int_size, og_array3_char_size and og_array3_bool_size (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
n1 * n2 * n3.
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_size
In notebooks
Og.Native.og_array3_size
See also
array3_n1

array3_n1#

Unit tests

Returns the first dimension of a three-dimensional array.

og_int_t og_array3_n1(const og_array3_t *a);

Other element types: og_array3_int_n1, og_array3_char_n1 and og_array3_bool_n1 (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
n1.
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_n1
In notebooks
Og.Native.og_array3_n1
See also
array3_n2, array3_n3

array3_n2#

Unit tests

Returns the second dimension of a three-dimensional array.

og_int_t og_array3_n2(const og_array3_t *a);

Other element types: og_array3_int_n2, og_array3_char_n2 and og_array3_bool_n2 (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
n2.
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_n2
In notebooks
Og.Native.og_array3_n2
See also
array3_n1, array3_n3

array3_n3#

Unit tests

Returns the third dimension of a three-dimensional array.

og_int_t og_array3_n3(const og_array3_t *a);

Other element types: og_array3_int_n3, og_array3_char_n3 and og_array3_bool_n3 (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
n3.
Complexity
O(1).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_n3
In notebooks
Og.Native.og_array3_n3
See also
array3_n1, array3_n2

array3_resize#

Unit tests

Changes the dimensions of a three-dimensional array.

og_error_t og_array3_resize(
    og_array3_t *a,
    og_int_t n1,
    og_int_t n2,
    og_int_t n3
);

The contents are unspecified afterwards; fill or null the array before reading it. On failure the array is unchanged.

Other element types: og_array3_int_resize, og_array3_char_resize and og_array3_bool_resize (same arguments with the matching container and element types).

Parameters
  • a The array.
  • n1 New first dimension.
  • n2 New second dimension.
  • n3 New third dimension.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL A dimension is negative or the product does not fit in og_int_t.
  • OG_ENOMEM Not enough memory.
Complexity
O(1) when the storage suffices, otherwise O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_resize
In notebooks
Og.Native.og_array3_resize
See also
array3_init, array3_null

array3_null#

Unit tests

Sets every element of a three-dimensional array to zero.

void og_array3_null(og_array3_t *a);

Other element types: og_array3_int_null, og_array3_char_null and og_array3_bool_null (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
Nothing.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_null
In notebooks
Og.Native.og_array3_null
See also
array3_fill

array3_fill#

Unit tests

Sets every element of a three-dimensional array to one value.

void og_array3_fill(og_array3_t *a, og_real_t e);

Other element types: og_array3_int_fill, og_array3_char_fill and og_array3_bool_fill (same arguments with the matching container and element types).

Parameters
  • a The array.
  • e The value.
Returns
Nothing.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_fill
In notebooks
Og.Native.og_array3_fill
See also
array3_null

array3_update#

Unit tests

Makes an existing three-dimensional array a copy of another.

og_error_t og_array3_update(og_array3_t *to, const og_array3_t *from);

to must be initialised; it takes the dimensions and elements of from. to == from does nothing.

Other element types: og_array3_int_update, og_array3_char_update and og_array3_bool_update (same arguments with the matching container and element types).

Parameters
  • to Destination (initialised).
  • from Source.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_update
In notebooks
Og.Native.og_array3_update
See also
array3_init

array3_sum#

Unit tests

Returns the sum of all elements of a three-dimensional array.

og_real_t og_array3_sum(const og_array3_t *a);

Added in storage order. Defined for real, int and char arrays; int sums wrap around on overflow.

Other element types: og_array3_int_sum and og_array3_char_sum (same arguments with the matching container and element types).

Parameters
  • a The array.
Returns
The sum.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_sum
In notebooks
Og.Native.og_array3_sum
See also
array3_scale

array3_scale#

Unit tests

Multiplies every element of a three-dimensional array by a constant.

void og_array3_scale(og_array3_t *a, og_real_t by);

Defined for real, int and char arrays.

Other element types: og_array3_int_scale and og_array3_char_scale (same arguments with the matching container and element types).

Parameters
  • a The array.
  • by The factor.
Returns
Nothing.
Complexity
O(n1 n2 n3).
Checked
Open Graph's own API (no reference to compare with); unit tests on every element type.
C name
og_array3_scale
In notebooks
Og.Native.og_array3_scale
See also
array3_sum

Stacks

stack_init#

Unit tests

Creates an empty stack with room for a given number of elements.

og_error_t og_stack_init(og_stack_t *s, og_int_t capacity);

A stack is an array whose last element is the top. At least one element is allocated even for capacity 0. When a push finds the stack full the capacity doubles, so capacity only avoids reallocations. Free the stack with stack_destroy.

Exists for og_real_t (stack_t), og_int_t (og_stack_int_t), char (og_stack_char_t) and og_bool_t (og_stack_bool_t); the functions carry the same suffix (og_stack_int_push, ...).

Other element types: og_stack_int_init, og_stack_char_init and og_stack_bool_init (same arguments with the matching container and element types).

Parameters
  • s The stack to initialise; not initialised yet.
  • capacity Initial room, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL capacity is negative (the stack is left empty and safe to destroy).
  • OG_ENOMEM Not enough memory.
Complexity
O(1) apart from the allocation.
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_init
In notebooks
Og.Native.og_stack_init
igraph 1.0
igraph_stack_init
See also
stack_destroy, stack_push, stack_reserve
og_stack_int_t st;
og_stack_int_init(&st, 16);
og_stack_int_push(&st, 1);
og_stack_int_push(&st, 2);
while (!og_stack_int_empty(&st)) {
    og_int_t v = og_stack_int_pop(&st);   /* 2, then 1 */
    (void) v;
}
og_stack_int_destroy(&st);

stack_destroy#

Unit tests

Frees the storage of a stack.

void og_stack_destroy(og_stack_t *s);

Destroying twice, or a stack whose initialisation failed, is harmless; NULL is ignored.

Other element types: og_stack_int_destroy, og_stack_char_destroy and og_stack_bool_destroy (same arguments with the matching container and element types).

Parameters
  • s The stack, or NULL.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_destroy
In notebooks
Og.Native.og_stack_destroy
igraph 1.0
igraph_stack_destroy
See also
stack_init

stack_reserve#

Unit tests

Makes room for at least a given number of elements.

og_error_t og_stack_reserve(og_stack_t *s, og_int_t capacity);

Nothing happens when the stack already has that much room; it never shrinks. On failure the stack is unchanged.

Other element types: og_stack_int_reserve, og_stack_char_reserve and og_stack_bool_reserve (same arguments with the matching container and element types).

Parameters
  • s The stack.
  • capacity The room wanted.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(size) when it reallocates, else O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_reserve
In notebooks
Og.Native.og_stack_reserve
igraph 1.0
igraph_stack_reserve
See also
stack_init, stack_push

stack_empty#

Unit tests

Tells whether a stack has no elements.

og_bool_t og_stack_empty(const og_stack_t *s);

Other element types: og_stack_int_empty, og_stack_char_empty and og_stack_bool_empty (same arguments with the matching container and element types).

Parameters
  • s The stack.
Returns
true or false.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_empty
In notebooks
Og.Native.og_stack_empty
igraph 1.0
igraph_stack_empty
See also
stack_size

stack_size#

Unit tests

Tells how many elements a stack holds.

og_int_t og_stack_size(const og_stack_t *s);

Other element types: og_stack_int_size, og_stack_char_size and og_stack_bool_size (same arguments with the matching container and element types).

Parameters
  • s The stack.
Returns
The number of elements.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_size
In notebooks
Og.Native.og_stack_size
igraph 1.0
igraph_stack_size
See also
stack_empty

stack_clear#

Unit tests

Empties a stack but keeps its storage.

void og_stack_clear(og_stack_t *s);

The storage is kept, so the stack can be refilled without allocating.

Other element types: og_stack_int_clear, og_stack_char_clear and og_stack_bool_clear (same arguments with the matching container and element types).

Parameters
  • s The stack.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_clear
In notebooks
Og.Native.og_stack_clear
igraph 1.0
igraph_stack_clear
See also
stack_destroy

stack_push#

Unit tests

Pushes an element; it becomes the new top of the stack.

og_error_t og_stack_push(og_stack_t *s, og_real_t elem);

When the stack is full its capacity doubles. On failure the stack is unchanged.

Other element types: og_stack_int_push, og_stack_char_push and og_stack_bool_push (same arguments with the matching container and element types).

Parameters
  • s The stack.
  • elem The element.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
Amortised O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter.
C name
og_stack_push
In notebooks
Og.Native.og_stack_push
igraph 1.0
igraph_stack_push
See also
stack_pop, stack_top

stack_pop#

Unit tests

Removes the top element of a stack and returns it.

og_real_t og_stack_pop(og_stack_t *s);

The stack must not be empty: popping an empty stack stops the program through the fatal handler (OG_ASSERT).

Other element types: og_stack_int_pop, og_stack_char_pop and og_stack_bool_pop (same arguments with the matching container and element types).

Parameters
  • s The stack.
Returns
The former top element.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_stack_pop
In notebooks
Og.Native.og_stack_pop
igraph 1.0
igraph_stack_pop
See also
stack_push, stack_top

stack_top#

Unit tests

Returns the top element of a stack without removing it.

og_real_t og_stack_top(const og_stack_t *s);

The stack must not be empty (fatal error otherwise).

Other element types: og_stack_int_top, og_stack_char_top and og_stack_bool_top (same arguments with the matching container and element types).

Parameters
  • s The stack.
Returns
The top element.
Complexity
O(1).
Checked
python-igraph has no binding for stacks; 200 seeded operation sequences replayed against a Python list on every element type, plus capacity checks with the allocation counter. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_stack_top
In notebooks
Og.Native.og_stack_top
igraph 1.0
igraph_stack_top
See also
stack_pop

Double-ended queues

dqueue_init#

Unit tests

Creates an empty double-ended queue with room for a given number of elements.

og_error_t og_dqueue_init(og_dqueue_t *q, og_int_t capacity);

The queue is a ring buffer: elements are added at the back and removed from either end. At least one element is allocated even for capacity 0; a push on a full queue doubles the capacity. Free it with dqueue_destroy.

Exists for og_real_t (dqueue_t), og_int_t (og_dqueue_int_t), char (og_dqueue_char_t) and og_bool_t (og_dqueue_bool_t), with matching function names.

Other element types: og_dqueue_int_init, og_dqueue_char_init and og_dqueue_bool_init (same arguments with the matching container and element types).

Parameters
  • q The queue to initialise; not initialised yet.
  • capacity Initial room, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL capacity is negative (the queue is left empty and safe to destroy).
  • OG_ENOMEM Not enough memory.
Complexity
O(1) apart from the allocation.
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_init
In notebooks
Og.Native.og_dqueue_init
igraph 1.0
igraph_dqueue_init
See also
dqueue_destroy, dqueue_push, dqueue_pop
/* breadth-first order from vertex 0 */
og_dqueue_int_t q;
og_dqueue_int_init(&q, 100);
og_dqueue_int_push(&q, 0);
while (!og_dqueue_int_empty(&q)) {
    og_int_t v = og_dqueue_int_pop(&q);   /* oldest first */
    /* ... og_dqueue_int_push(&q, w) for each new neighbour w ... */
    (void) v;
}
og_dqueue_int_destroy(&q);

dqueue_destroy#

Unit tests

Frees the storage of a double-ended queue.

void og_dqueue_destroy(og_dqueue_t *q);

Destroying twice, or a queue whose initialisation failed, is harmless; NULL is ignored.

Other element types: og_dqueue_int_destroy, og_dqueue_char_destroy and og_dqueue_bool_destroy (same arguments with the matching container and element types).

Parameters
  • q The queue, or NULL.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_destroy
In notebooks
Og.Native.og_dqueue_destroy
igraph 1.0
igraph_dqueue_destroy
See also
dqueue_init

dqueue_empty#

Unit tests

Tells whether a double-ended queue has no elements.

og_bool_t og_dqueue_empty(const og_dqueue_t *q);

True for an empty queue.

Other element types: og_dqueue_int_empty, og_dqueue_char_empty and og_dqueue_bool_empty (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
true or false.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_empty
In notebooks
Og.Native.og_dqueue_empty
igraph 1.0
igraph_dqueue_empty
See also
dqueue_size, dqueue_full

dqueue_full#

Unit tests

Tells whether the next push will have to grow the storage.

og_bool_t og_dqueue_full(const og_dqueue_t *q);

True when the number of elements equals the capacity. A full queue still accepts pushes; they allocate.

Other element types: og_dqueue_int_full, og_dqueue_char_full and og_dqueue_bool_full (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
true or false.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_full
In notebooks
Og.Native.og_dqueue_full
igraph 1.0
igraph_dqueue_full
See also
dqueue_push, dqueue_size

dqueue_clear#

Unit tests

Empties a double-ended queue but keeps its storage.

void og_dqueue_clear(og_dqueue_t *q);

The storage is kept.

Other element types: og_dqueue_int_clear, og_dqueue_char_clear and og_dqueue_bool_clear (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_clear
In notebooks
Og.Native.og_dqueue_clear
igraph 1.0
igraph_dqueue_clear
See also
dqueue_destroy

dqueue_size#

Unit tests

Tells how many elements a double-ended queue holds.

og_int_t og_dqueue_size(const og_dqueue_t *q);

Other element types: og_dqueue_int_size, og_dqueue_char_size and og_dqueue_bool_size (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
The number of elements.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_size
In notebooks
Og.Native.og_dqueue_size
igraph 1.0
igraph_dqueue_size
See also
dqueue_empty

dqueue_head#

Unit tests

Returns the first element (the oldest) without removing it.

og_real_t og_dqueue_head(const og_dqueue_t *q);

The queue must not be empty (fatal error otherwise).

Other element types: og_dqueue_int_head, og_dqueue_char_head and og_dqueue_bool_head (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
The head element.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_dqueue_head
In notebooks
Og.Native.og_dqueue_head
igraph 1.0
igraph_dqueue_head
See also
dqueue_back, dqueue_pop

dqueue_back#

Unit tests

Returns the last element (the newest) without removing it.

og_real_t og_dqueue_back(const og_dqueue_t *q);

The queue must not be empty (fatal error otherwise).

Other element types: og_dqueue_int_back, og_dqueue_char_back and og_dqueue_bool_back (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
The back element.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_dqueue_back
In notebooks
Og.Native.og_dqueue_back
igraph 1.0
igraph_dqueue_back
See also
dqueue_head, dqueue_pop_back

dqueue_get#

Unit tests

Returns the element at a given position counted from the head.

og_real_t og_dqueue_get(const og_dqueue_t *q, og_int_t idx);

Position 0 is the head and size - 1 the back. An index outside 0 .. size-1 stops the program through the fatal handler.

Other element types: og_dqueue_int_get, og_dqueue_char_get and og_dqueue_bool_get (same arguments with the matching container and element types).

Parameters
  • q The queue.
  • idx Position from the head.
Returns
The element.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_dqueue_get
In notebooks
Og.Native.og_dqueue_get
igraph 1.0
igraph_dqueue_get
See also
dqueue_head, dqueue_back

dqueue_pop#

Unit tests

Removes the head element (the oldest) and returns it.

og_real_t og_dqueue_pop(og_dqueue_t *q);

This is the usual queue removal (first in, first out). The queue must not be empty (fatal error otherwise).

Other element types: og_dqueue_int_pop, og_dqueue_char_pop and og_dqueue_bool_pop (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
The former head.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_dqueue_pop
In notebooks
Og.Native.og_dqueue_pop
igraph 1.0
igraph_dqueue_pop
See also
dqueue_push, dqueue_pop_back, dqueue_head

dqueue_pop_back#

Unit tests

Removes the back element (the newest) and returns it.

og_real_t og_dqueue_pop_back(og_dqueue_t *q);

Used this way the queue acts as a stack. The queue must not be empty (fatal error otherwise).

Other element types: og_dqueue_int_pop_back, og_dqueue_char_pop_back and og_dqueue_bool_pop_back (same arguments with the matching container and element types).

Parameters
  • q The queue.
Returns
The former back element.
Complexity
O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_dqueue_pop_back
In notebooks
Og.Native.og_dqueue_pop_back
igraph 1.0
igraph_dqueue_pop_back
See also
dqueue_pop, dqueue_back

dqueue_push#

Unit tests

Appends an element at the back of a double-ended queue.

og_error_t og_dqueue_push(og_dqueue_t *q, og_real_t elem);

When the queue is full its capacity doubles and the ring is laid out again. On failure the queue is unchanged.

Other element types: og_dqueue_int_push, og_dqueue_char_push and og_dqueue_bool_push (same arguments with the matching container and element types).

Parameters
  • q The queue.
  • elem The element.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
Amortised O(1).
Checked
python-igraph has no binding for queues; 200 seeded operation sequences replayed against collections.deque on every element type, ring wrap-around and capacity checks.
C name
og_dqueue_push
In notebooks
Og.Native.og_dqueue_push
igraph 1.0
igraph_dqueue_push
See also
dqueue_pop, dqueue_pop_back, dqueue_full

Heaps

heap_init#

Unit tests

Creates an empty binary heap with room for a given number of elements.

og_error_t og_heap_init(og_heap_t *h, og_int_t capacity);

A binary heap in an array (Williams 1964): data[0] is the top and no element ranks above its parent. At least one element is allocated even for capacity 0; a push on a full heap doubles the capacity. Free it with heap_destroy.

heap_t keeps the largest element on top; heap_min_t (og_heap_min_init and the other og_heap_min_ functions) keeps the smallest. Both exist for og_real_t, og_int_t (og_heap_int_t, og_heap_min_int_t) and char (og_heap_char_t, og_heap_min_char_t). In real heaps NaN ranks above every number: it comes out first from a maximum heap and last from a minimum heap.

Other element types: og_heap_min_init, og_heap_int_init, og_heap_min_int_init, og_heap_char_init and og_heap_min_char_init (same arguments with the matching container and element types).

Parameters
  • h The heap to initialise; not initialised yet.
  • capacity Initial room, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL capacity is negative (the heap is left empty and safe to destroy).
  • OG_ENOMEM Not enough memory.
Complexity
O(1) apart from the allocation.
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_init
In notebooks
Og.Native.og_heap_init
igraph 1.0
igraph_heap_init
See also
heap_init_array, heap_push, heap_delete_top, heap_destroy
og_heap_min_t h;
og_heap_min_init(&h, 8);
og_heap_min_push(&h, 3.5);
og_heap_min_push(&h, 0.5);
og_heap_min_push(&h, 2.0);
while (!og_heap_min_empty(&h)) {
    og_real_t x = og_heap_min_delete_top(&h);  /* 0.5, 2, 3.5 */
    (void) x;
}
og_heap_min_destroy(&h);

heap_init_array#

Unit tests

Creates a heap holding a copy of a C array.

og_error_t og_heap_init_array(
    og_heap_t *h,
    const og_real_t *data,
    og_int_t len
);

The elements are copied and arranged into a heap bottom-up (Floyd 1964), which takes linear time, faster than pushing them one by one. data is not changed. The capacity equals len (at least 1).

Other element types: og_heap_min_init_array, og_heap_int_init_array, og_heap_min_int_init_array, og_heap_char_init_array and og_heap_min_char_init_array (same arguments with the matching container and element types).

Parameters
  • h The heap to initialise; not initialised yet.
  • data The elements; len of them.
  • len Number of elements, 0 or more.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_EINVAL len is negative (the heap is left empty and safe to destroy).
  • OG_ENOMEM Not enough memory.
Complexity
O(len).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_init_array
In notebooks
Og.Native.og_heap_init_array
igraph 1.0
igraph_heap_init_array
See also
heap_init, heap_push

heap_destroy#

Unit tests

Frees the storage of a heap.

void og_heap_destroy(og_heap_t *h);

Destroying twice, or a heap whose initialisation failed, is harmless; NULL is ignored.

Other element types: og_heap_min_destroy, og_heap_int_destroy, og_heap_min_int_destroy, og_heap_char_destroy and og_heap_min_char_destroy (same arguments with the matching container and element types).

Parameters
  • h The heap, or NULL.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_destroy
In notebooks
Og.Native.og_heap_destroy
igraph 1.0
igraph_heap_destroy
See also
heap_init

heap_clear#

Unit tests

Empties a heap but keeps its storage.

void og_heap_clear(og_heap_t *h);

The storage is kept.

Other element types: og_heap_min_clear, og_heap_int_clear, og_heap_min_int_clear, og_heap_char_clear and og_heap_min_char_clear (same arguments with the matching container and element types).

Parameters
  • h The heap.
Returns
Nothing.
Complexity
O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_clear
In notebooks
Og.Native.og_heap_clear
igraph 1.0
igraph_heap_clear
See also
heap_destroy

heap_empty#

Unit tests

Tells whether a heap has no elements.

og_bool_t og_heap_empty(const og_heap_t *h);

Other element types: og_heap_min_empty, og_heap_int_empty, og_heap_min_int_empty, og_heap_char_empty and og_heap_min_char_empty (same arguments with the matching container and element types).

Parameters
  • h The heap.
Returns
true or false.
Complexity
O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_empty
In notebooks
Og.Native.og_heap_empty
igraph 1.0
igraph_heap_empty
See also
heap_size

heap_push#

Unit tests

Adds an element to a heap.

og_error_t og_heap_push(og_heap_t *h, og_real_t elem);

The element moves up until its parent ranks at least as high. When the heap is full its capacity doubles. On failure the heap is unchanged.

Other element types: og_heap_min_push, og_heap_int_push, og_heap_min_int_push, og_heap_char_push and og_heap_min_char_push (same arguments with the matching container and element types).

Parameters
  • h The heap.
  • elem The element.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(log n), amortised over the reallocations.
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_push
In notebooks
Og.Native.og_heap_push
igraph 1.0
igraph_heap_push
See also
heap_delete_top, heap_top

heap_top#

Unit tests

Returns the top element (the largest, or the smallest for heap_min_t) without removing it.

og_real_t og_heap_top(const og_heap_t *h);

The heap must not be empty (fatal error otherwise).

Other element types: og_heap_min_top, og_heap_int_top, og_heap_min_int_top, og_heap_char_top and og_heap_min_char_top (same arguments with the matching container and element types).

Parameters
  • h The heap.
Returns
The top element.
Complexity
O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_heap_top
In notebooks
Og.Native.og_heap_top
igraph 1.0
igraph_heap_top
See also
heap_delete_top

heap_delete_top#

Unit tests

Removes the top element of a heap and returns it.

og_real_t og_heap_delete_top(og_heap_t *h);

The last element takes the top's place and moves down until the heap order holds again. The heap must not be empty (fatal error otherwise). heap_pop is the same function under another name.

Other element types: og_heap_min_delete_top, og_heap_int_delete_top, og_heap_min_int_delete_top, og_heap_char_delete_top and og_heap_min_char_delete_top (same arguments with the matching container and element types).

Parameters
  • h The heap.
Returns
The former top element.
Complexity
O(log n).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included. The fatal stop on an empty container (or bad index) is tested on every element type.
C name
og_heap_delete_top
In notebooks
Og.Native.og_heap_delete_top
igraph 1.0
igraph_heap_delete_top
See also
heap_top, heap_push, heap_pop

heap_size#

Unit tests

Tells how many elements a heap holds.

og_int_t og_heap_size(const og_heap_t *h);

Other element types: og_heap_min_size, og_heap_int_size, og_heap_min_int_size, og_heap_char_size and og_heap_min_char_size (same arguments with the matching container and element types).

Parameters
  • h The heap.
Returns
The number of elements.
Complexity
O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_size
In notebooks
Og.Native.og_heap_size
igraph 1.0
igraph_heap_size
See also
heap_empty

heap_reserve#

Unit tests

Makes room for at least a given number of elements.

og_error_t og_heap_reserve(og_heap_t *h, og_int_t capacity);

Nothing happens when the heap already has that much room; it never shrinks. On failure the heap is unchanged.

Other element types: og_heap_min_reserve, og_heap_int_reserve, og_heap_min_int_reserve, og_heap_char_reserve and og_heap_min_char_reserve (same arguments with the matching container and element types).

Parameters
  • h The heap.
  • capacity The room wanted.
Returns
OG_SUCCESS, or an error code.
Errors
  • OG_ENOMEM Not enough memory.
Complexity
O(size) when it reallocates, else O(1).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_reserve
In notebooks
Og.Native.og_heap_reserve
igraph 1.0
igraph_heap_reserve
See also
heap_init, heap_push

heap_pop#

Unit tests

Removes the top element of a heap and returns it (another name for heap_delete_top).

og_real_t og_heap_pop(og_heap_t *h);

Identical to heap_delete_top; both names exist because the reference names the heap functions both ways. Defined for every heap type: og_heap_min_pop, og_heap_int_pop, og_heap_min_int_pop, og_heap_char_pop, og_heap_min_char_pop. The heap must not be empty (fatal error otherwise).

Parameters
  • h The heap.
Returns
The former top element.
Complexity
O(log n).
Checked
python-igraph has no binding for heaps; 240 seeded operation sequences replayed against Python's heapq on every element type, maximum and minimum heaps, NaN included.
C name
og_heap_pop
In notebooks
Og.Native.og_heap_pop
igraph 1.0
igraph_heap_pop
See also
heap_delete_top

Last updated · Open Graph 0.1.0 · OpenBI Studio 0.3.78