-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathtest_matrices.py
More file actions
49 lines (38 loc) · 1.33 KB
/
test_matrices.py
File metadata and controls
49 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Benchmarks for matrix generation (model -> sparse matrices)."""
from __future__ import annotations
import pytest
from benchmarks.conftest import skip_if_quick
from benchmarks.models import (
BASIC_SIZES,
EXPR_SIZES,
SPARSE_SIZES,
build_basic,
build_expression_arithmetic,
build_sparse_network,
)
def _access_matrices(m):
"""Access all matrix properties to force computation."""
matrices = m.matrices
_ = matrices.A
_ = matrices.b
_ = matrices.c
_ = matrices.lb
_ = matrices.ub
_ = matrices.sense
_ = matrices.vlabels
_ = matrices.clabels
@pytest.mark.parametrize("n", BASIC_SIZES, ids=[f"n={n}" for n in BASIC_SIZES])
def test_matrices_basic(benchmark, n, request):
skip_if_quick(request, "basic", n)
m = build_basic(n)
benchmark(_access_matrices, m)
@pytest.mark.parametrize("n", EXPR_SIZES, ids=[f"n={n}" for n in EXPR_SIZES])
def test_matrices_expression_arithmetic(benchmark, n, request):
skip_if_quick(request, "expression_arithmetic", n)
m = build_expression_arithmetic(n)
benchmark(_access_matrices, m)
@pytest.mark.parametrize("n", SPARSE_SIZES, ids=[f"n={n}" for n in SPARSE_SIZES])
def test_matrices_sparse_network(benchmark, n, request):
skip_if_quick(request, "sparse_network", n)
m = build_sparse_network(n)
benchmark(_access_matrices, m)