unary_ops.h

Basic unary operations on the Matrix type.

Author

Brian Jackson (bjack205@gmail.com)

Date

2022-01-30

Copyright

Copyright (c) 2022

Functions

enum slap_ErrorCode slap_SetConst(Matrix mat, sfloat val)

Sets all of the elements in a matrix to a single value.

Header File: "slap/unary_ops.h"

Parameters:
  • matMatrix to be modified

  • val – Value to which each element will be set

Returns:

0 if successful

enum slap_ErrorCode slap_ScaleByConst(Matrix mat, sfloat alpha)

Scale a matrix by a constant factor.

Header File: "slap/unary_ops.h"

Parameters:
  • mat – Fully initialized matrix of non-zero size. Values will be modified.

  • alpha – scalar by which to multiply the matrix

enum slap_ErrorCode slap_SetIdentity(Matrix mat, sfloat val)

Set the diagonal elements of the matrix to val, and the rest to zeros.

Header File: "slap/unary_ops.h"

Parameters:
  • mat – Square matrix

  • val – Value for the diagonal elements

enum slap_ErrorCode slap_SetDiagonal(Matrix mat, const sfloat *diag, int len)

Set the first n elements of a matrix diagonal from an array.

If len is greater than the minimum dimension, only the minimum dimension will be set. Doesn’t touch any of the off-diagonal elements.

Header File: "slap/unary_ops.h"

Parameters:
  • matMatrix (nrows >= ncols)

  • diag – Array of length nrows.

enum slap_ErrorCode slap_AddIdentity(Matrix mat, sfloat alpha)

Add a multiple of the identity to the matrix.

Header File: "slap/unary_ops.h"

Parameters:
  • mat – A valid matrix

  • alpha – The value to add to the diagonal elements

enum slap_ErrorCode slap_SetRange(Matrix mat, sfloat start, sfloat stop)

Sets the matrix to a equally-spaced range.

Fills the matrix in column-major order.

Example

 {c'}
#include "slap/new_matrix.h"
Matrix A = slap_NewMatrix(3, 3);
slap_SetRange(A, 1, 9);
slap_FreeMatrix(A);
Creates a matrix with the following elements:
A = [
  1 4 7
  2 5 8
  3 6 9
]

Header File: "slap/unary_ops.h"

Parameters:
  • mat – A valid, non-empty matrix

  • start – Value of the first element

  • stop – Value of the last element