Python代写 | ACSE-1 2020/21 – Assessment 3

本次Python代写是基于CI用于高斯消除算法,开发和优化计算矩阵行列式的算法

ACSE-1 2020/21 – Assessment 3

Assessment
1. Currently, running flake8 from the base folder of this repository will
reveal several errors. Running pytest tests/ will also reveal that the
single test located in the file tests/test gauss.py fails – this is due
to two bugs, one bug with the matrix multiplication algorithm and one
bug due to the computation of the determinant. Further, attempting
to build the sphinx documentation located in docs will fail due to a
couple of errors.
2
(a) Make the repository PEP8 compliant (i.e. fix the flake8 errors)
(b) Add docstrings to the functions matmul and zeromat
(c) To test gauss.py, add additional tests for matmul and zeromat.
(Note that you’ll need to make these functions visible to the test
file). Your tests should make use of the parameterize decorator to
test multiple inputs. In doing this, you’ll notice that any suitable
test for the matmul function fails. Debug this function such that
your test passes.
(d) With matmul fixed you’ll notice that the gauss related test is still
broken. Fix this bug so that test gauss passes and utilising the
parameterize decorator add further (at least one) set of test inputs. Note: A properly working gauss function should be able
to correctly return non integer determinants and this functionality should be tested.
(e) Next, add an additional file in tests called
test docstrings.py that tests the docstring tests in each of the
three functions present in gauss.py.
(f) Finally for part 1, fix the bugs present in docs/conf.py. When
fixed, use sphinx to build the associated html files and compile
these into a pdf file named ACSE la.pdf which should be located
in the docs folder. This documentation should be updated to
reflect the final state of your repository.
[40 marks]
2. The next task is to add some CI in the form of Github Actions workflows. These workflows should be placed within the repository in the
.github/workflows folder.
(a) Create a workflow that checks the workflow is PEP8 compliant.
The workflow should trigger when (at the very least) a push is
made the main branch.
(b) Create a workflow that runs pytest on all test files present within
the tests/ folder. The workflow should execute the tests on the
following operating systems: (i) Ubuntu 20.04, (ii) MacOS 11.0 &
(iii) Windows Server 2019. (You may utilize the default Python3
distribution available on those operating systems).
[25 marks]
3. If we simply wish to compute the determinant of a matrix (e.g. det =
gauss(A, I)), clearly our current algorithm is not optimal, especially
when the matrix becomes large ( 10, 000 × 10, 000). Lets see how bad
it is and if we can do better.
3
2 0.001 0.001
4 0.02 0.01
.
.
.
.
.
.
.
.
.
10000 5.0 1.0
Table 1: Example formatting of the results table. The first column represents the size of the matrix along one of its axes. The second column
represents the corresponding timing in a suitable unit of the gauss algorithm and the final column that of numpy.linalg.det.
(a) Within the scripts/ folder add a file called det timings.py.
This script should, for many (≈ 10) square matrices of increasing size (2 × 2 ⇒ 10, 000 × 10, 000), compute the time taken by
the gauss algorithm to compute the determinant of these matrices. Additionally, for each of these matrices compute the time
taken by numpy.linalg.det to calculate the determinant. Timing results should be written automatically by the script to a file
named timings.txt in the results/ folder with the formatting
illustrated in Table 1.
(b) Add a new workflow that, using a single operating system of
your choice, executes the script det timings.py, commits the
new results (i.e. the new timings.txt produced) and pushes
them to your github repository.
(c) In the acse la folder add a new file det.py that contains a function (that you will write) named det. This function should be
your own algorithm to compute only the determinant of a single
square matrix that’s passed to it. How does your implementation compare to that of gauss and numpy.linalg.det? Have
your script det timings.py also compute the timing of your det
algorithm and add your results as a third column in timings.txt
[35 marks]