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.
MatrixDepot.publish_user_generators — Function
publish_user_generators()Make the generators registered by include_generator available in the database. User generators are not written to the database cache.
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) | |
|---|---|
| randorth | randsym |
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 ≈ Itruelistnames(:random)| list(13) | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| erdrey | golub | randcorr | randorth | randsym | rosser | wathen | |||||
| gilbert | oscillate | rando | randsvd | rohess | smallworld |