User Generators

Matrix Depot can be extended with your own matrix generators. include_generator registers a generator and publish_user_generators updates the database afterwards. include_generator must be called at run time, so packages defining custom generators should call it from their __init__ function to avoid precompilation issues. MatrixDepotTemplate.jl is a complete example of such a package.

MatrixDepot.include_generator — Function
include_generator(FunctionName, name::AbstractString, f::Function)
include_generator(Group, group::Symbol, f::Function)

Register the matrix generator f under name, or add it to the existing group. Call publish_user_generators afterwards to update the database.

source

Example

using MatrixDepot, LinearAlgebra

"""
random symmetric matrix
=======================

*Input options:*

+ n: the dimension of the matrix
"""
randsym(n) = Symmetric(randn(n, n)) |> Matrix

"""
random orthogonal matrix
========================

*Input options:*

+ n: the dimension of the matrix
"""
randorth(n) = Matrix(qr(randn(n, n)).Q)

MatrixDepot.include_generator(MatrixDepot.FunctionName, "randsym", randsym)
MatrixDepot.include_generator(MatrixDepot.FunctionName, "randorth", randorth)
MatrixDepot.include_generator(MatrixDepot.Group, :random, randsym)
MatrixDepot.include_generator(MatrixDepot.Group, :symmetric, randsym)
MatrixDepot.include_generator(MatrixDepot.Group, :random, randorth)
MatrixDepot.publish_user_generators()

listnames(user(:))
list(2)
randorthrandsym

The new generators behave like the built-in ones:

mdinfo("randsym")

random symmetric matrix (randsym)

Input options:

  • n: the dimension of the matrix

A = matrixdepot("randorth", 4)
A' * A ≈ I
true
listnames(:random)
list(13)
erdreygolubrandcorrrandorthrandsymrosserwathen
gilbertoscillaterandorandsvdrohesssmallworld