Benchmarks for matrices¶
This file has many functions for computing timing benchmarks of various methods for random matrices with given bounds for the entries. The systems supported are Sage and Magma.
The basic command syntax is as follows:
sage: import sage.matrix.benchmark as b
sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
starting...
======================================================================
Test
======================================================================
...
======================================================================
- sage.matrix.benchmark.MatrixVector_QQ(n=1000, h=100, system='sage', times=1)¶
Compute product of square
n
matrix by random vector with num and denom bounded byh
the given number oftimes
.INPUT:
n
- matrix dimension (default:300
)h
- numerator and denominator bound (default:bnd
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of experiments (default:1
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.MatrixVector_QQ(500) sage: tm = b.MatrixVector_QQ(500, system='magma') # optional - magma
- sage.matrix.benchmark.charpoly_GF(n=100, p=16411, system='sage')¶
Given a n x n matrix over GF with random entries, compute the charpoly.
INPUT:
n
- matrix dimension (default: 100)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.charpoly_GF(100) sage: tm = b.charpoly_GF(100, system='magma') # optional - magma
- sage.matrix.benchmark.charpoly_ZZ(n=100, min=0, max=9, system='sage')¶
Characteristic polynomial over ZZ: Given a n x n matrix over ZZ with random entries between min and max, compute the charpoly.
INPUT:
n
- matrix dimension (default:100
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.charpoly_ZZ(100) sage: tm = b.charpoly_ZZ(100, system='magma') # optional - magma
- sage.matrix.benchmark.det_GF(n=400, p=16411, system='sage')¶
Dense determinant over GF(p). Given an n x n matrix A over GF with random entries compute det(A).
INPUT:
n
- matrix dimension (default: 300)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.det_GF(1000) sage: tm = b.det_GF(1000, system='magma') # optional - magma
- sage.matrix.benchmark.det_QQ(n=300, num_bound=10, den_bound=10, system='sage')¶
Dense rational determinant over QQ. Given an n x n matrix A over QQ with random entries with numerator bound and denominator bound, compute det(A).
INPUT:
n
- matrix dimension (default:200
)num_bound
- numerator bound, inclusive (default:10
)den_bound
- denominator bound, inclusive (default:10
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.det_QQ(200) sage: ts = b.det_QQ(10, num_bound=100000, den_bound=10000) sage: tm = b.det_QQ(200, system='magma') # optional - magma
- sage.matrix.benchmark.det_ZZ(n=200, min=1, max=100, system='sage')¶
Dense integer determinant over ZZ. Given an n x n matrix A over ZZ with random entries between min and max, inclusive, compute det(A).
INPUT:
n
- matrix dimension (default:200
)min
- minimal value for entries of matrix (default:1
)max
- maximal value for entries of matrix (default:100
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.det_ZZ(200) sage: tm = b.det_ZZ(200, system='magma') # optional - magma
- sage.matrix.benchmark.det_hilbert_QQ(n=80, system='sage')¶
Runs the benchmark for calculating the determinant of the hilbert matrix over rationals of dimension n.
INPUT:
n
- matrix dimension (default:300
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.det_hilbert_QQ(50) sage: tm = b.det_hilbert_QQ(50, system='magma') # optional - magma
- sage.matrix.benchmark.echelon_QQ(n=100, min=0, max=9, system='sage')¶
Given a n x (2*n) matrix over QQ with random integer entries between min and max, compute the reduced row echelon form.
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:-9
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.echelon_QQ(100) sage: tm = b.echelon_QQ(100, system='magma') # optional - magma
- sage.matrix.benchmark.hilbert_matrix(n)¶
Returns the Hilbert matrix of size n over rationals.
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: b.hilbert_matrix(3) [ 1 1/2 1/3] [1/2 1/3 1/4] [1/3 1/4 1/5]
- sage.matrix.benchmark.inverse_QQ(n=100, min=0, max=9, system='sage')¶
Given a n x n matrix over QQ with random integer entries between min and max, compute the reduced row echelon form.
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:-9
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.inverse_QQ(100) sage: tm = b.inverse_QQ(100, system='magma') # optional - magma
- sage.matrix.benchmark.invert_hilbert_QQ(n=40, system='sage')¶
Runs the benchmark for calculating the inverse of the hilbert matrix over rationals of dimension n.
INPUT:
n
- matrix dimension (default:300
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.invert_hilbert_QQ(30) sage: tm = b.invert_hilbert_QQ(30, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_add_GF(n=1000, p=16411, system='sage', times=100)¶
Given two n x n matrix over GF(p) with random entries, add them.
INPUT:
n
- matrix dimension (default: 300)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)times
- number of experiments (default:100
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_GF(500, p=19) sage: tm = b.matrix_add_GF(500, p=19, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_add_ZZ(n=200, min=- 9, max=9, system='sage', times=50)¶
Matrix addition over ZZ Given an n x n matrix A and B over ZZ with random entries between
min
andmax
, inclusive, compute A + Btimes
times.INPUT:
n
- matrix dimension (default:200
)min
- minimal value for entries of matrix (default:-9
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of experiments (default:50
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_ZZ(200) sage: tm = b.matrix_add_ZZ(200, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_add_ZZ_2(n=200, bits=16, system='sage', times=50)¶
Matrix addition over ZZ. Given an n x n matrix A and B over ZZ with random
bits
-bit entries, compute A + B.INPUT:
n
- matrix dimension (default:200
)bits
- bitsize of entriessystem
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of experiments (default:50
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_add_ZZ_2(200) sage: tm = b.matrix_add_ZZ_2(200, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_multiply_GF(n=100, p=16411, system='sage', times=3)¶
Given an n x n matrix A over GF(p) with random entries, compute A * (A+1).
INPUT:
n
- matrix dimension (default: 100)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)times
- number of experiments (default:3
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_GF(100, p=19) sage: tm = b.matrix_multiply_GF(100, p=19, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_multiply_QQ(n=100, bnd=2, system='sage', times=1)¶
Given an n x n matrix A over QQ with random entries whose numerators and denominators are bounded by bnd, compute A * (A+1).
INPUT:
n
- matrix dimension (default:300
)bnd
- numerator and denominator bound (default:bnd
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of experiments (default:1
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_QQ(100) sage: tm = b.matrix_multiply_QQ(100, system='magma') # optional - magma
- sage.matrix.benchmark.matrix_multiply_ZZ(n=300, min=- 9, max=9, system='sage', times=1)¶
Matrix multiplication over ZZ Given an n x n matrix A over ZZ with random entries between min and max, inclusive, compute A * (A+1).
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:-9
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of experiments (default:1
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.matrix_multiply_ZZ(200) sage: tm = b.matrix_multiply_ZZ(200, system='magma') # optional - magma
- sage.matrix.benchmark.nullspace_GF(n=300, p=16411, system='sage')¶
Given a n+1 x n matrix over GF(p) with random entries, compute the nullspace.
INPUT:
n
- matrix dimension (default: 300)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_GF(300) sage: tm = b.nullspace_GF(300, system='magma') # optional - magma
- sage.matrix.benchmark.nullspace_RDF(n=300, min=0, max=10, system='sage')¶
Nullspace over RDF: Given a n+1 x n matrix over RDF with random entries between min and max, compute the nullspace.
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default: \(10\))system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_RDF(100) # long time sage: tm = b.nullspace_RDF(100, system='magma') # optional - magma
- sage.matrix.benchmark.nullspace_RR(n=300, min=0, max=10, system='sage')¶
Nullspace over RR: Given a n+1 x n matrix over RR with random entries between min and max, compute the nullspace.
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:10
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_RR(100) sage: tm = b.nullspace_RR(100, system='magma') # optional - magma
- sage.matrix.benchmark.nullspace_ZZ(n=200, min=0, max=4294967296, system='sage')¶
Nullspace over ZZ: Given a n+1 x n matrix over ZZ with random entries between min and max, compute the nullspace.
INPUT:
n
- matrix dimension (default:200
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:2**32
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.nullspace_ZZ(200) sage: tm = b.nullspace_ZZ(200, system='magma') # optional - magma
- sage.matrix.benchmark.rank2_GF(n=500, p=16411, system='sage')¶
Rank over GF(p): Given a (n + 10) x n matrix over GF(p) with random entries, compute the rank.
INPUT:
n
- matrix dimension (default: 300)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.rank2_GF(500) sage: tm = b.rank2_GF(500, system='magma') # optional - magma
- sage.matrix.benchmark.rank2_ZZ(n=400, min=0, max=18446744073709551616, system='sage')¶
Rank 2 over ZZ: Given a (n + 10) x n matrix over ZZ with random entries between min and max, compute the rank.
INPUT:
n
- matrix dimension (default:400
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:2**64
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.rank2_ZZ(300) sage: tm = b.rank2_ZZ(300, system='magma') # optional - magma
- sage.matrix.benchmark.rank_GF(n=500, p=16411, system='sage')¶
Rank over GF(p): Given a n x (n+10) matrix over GF(p) with random entries, compute the rank.
INPUT:
n
- matrix dimension (default: 300)p
- prime number (default:16411
)system
- either ‘magma’ or ‘sage’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.rank_GF(1000) sage: tm = b.rank_GF(1000, system='magma') # optional - magma
- sage.matrix.benchmark.rank_ZZ(n=700, min=0, max=9, system='sage')¶
Rank over ZZ: Given a n x (n+10) matrix over ZZ with random entries between min and max, compute the rank.
INPUT:
n
- matrix dimension (default:700
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.rank_ZZ(300) sage: tm = b.rank_ZZ(300, system='magma') # optional - magma
- sage.matrix.benchmark.report(F, title, systems=['sage', 'magma'], **kwds)¶
Run benchmarks with default arguments for each function in the list F.
INPUT:
F
- a list of callables used for benchmarkingtitle
- a string describing this reportsystems
- a list of systems (supported entries are ‘sage’ and ‘magma’)**kwds
- keyword arguments passed to all functions inF
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage']) starting... ====================================================================== Test ====================================================================== ... ======================================================================
- sage.matrix.benchmark.report_GF(p=16411, **kwds)¶
Runs all the reports for finite field matrix operations, for prime p=16411.
INPUT:
p
- ignored**kwds
- passed through toreport()
Note
right now, even though p is an input, it is being ignored! If you need to check the performance for other primes, you can call individual benchmark functions.
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report_GF(systems=['sage']) starting... ====================================================================== Dense benchmarks over GF with prime 16411 ====================================================================== ... ======================================================================
- sage.matrix.benchmark.report_ZZ(**kwds)¶
Reports all the benchmarks for integer matrices and few rational matrices.
INPUT:
**kwds
- passed through toreport()
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: print("starting"); import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012) starting... ====================================================================== Dense benchmarks over ZZ ====================================================================== ... ======================================================================
- sage.matrix.benchmark.smithform_ZZ(n=128, min=0, max=9, system='sage')¶
Smith Form over ZZ: Given a n x n matrix over ZZ with random entries between min and max, compute the Smith normal form.
INPUT:
n
- matrix dimension (default:128
)min
- minimal value for entries of matrix (default:0
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.smithform_ZZ(100) sage: tm = b.smithform_ZZ(100, system='magma') # optional - magma
- sage.matrix.benchmark.vecmat_ZZ(n=300, min=- 9, max=9, system='sage', times=200)¶
Vector matrix multiplication over ZZ.
Given an n x n matrix A over ZZ with random entries between min and max, inclusive, and v the first row of A, compute the product v * A.
INPUT:
n
- matrix dimension (default:300
)min
- minimal value for entries of matrix (default:-9
)max
- maximal value for entries of matrix (default:9
)system
- either ‘sage’ or ‘magma’ (default: ‘sage’)times
- number of runs (default:200
)
EXAMPLES:
sage: import sage.matrix.benchmark as b sage: ts = b.vecmat_ZZ(300) # long time sage: tm = b.vecmat_ZZ(300, system='magma') # optional - magma