Browse Source

initial commit to matrix repo

master
lbeckman314 2 years ago
commit
71b398e073
22 changed files with 2286 additions and 0 deletions
  1. 23
    0
      blankLines
  2. 2
    0
      example_matrices/m1
  3. 25
    0
      example_matrices/m10
  4. 25
    0
      example_matrices/m11
  5. 5
    0
      example_matrices/m12
  6. 3
    0
      example_matrices/m13
  7. 3
    0
      example_matrices/m14
  8. 10
    0
      example_matrices/m15
  9. 10
    0
      example_matrices/m16
  10. 4
    0
      example_matrices/m2
  11. 0
    0
      example_matrices/m3
  12. 5
    0
      example_matrices/m4
  13. 3
    0
      example_matrices/m5
  14. 3
    0
      example_matrices/m6
  15. 20
    0
      example_matrices/m9
  16. 53
    0
      generate
  17. 163
    0
      index.md
  18. 1
    0
      m1
  19. 563
    0
      matrix
  20. 736
    0
      p1grading_result
  21. 604
    0
      p1gradingscript
  22. 25
    0
      tags

+ 23
- 0
blankLines View File

@@ -0,0 +1,23 @@
#!/bin/bash

nonempty=0
brackets=0
empty=0
while read line
do
if [ -z "$line" ]
then
((empty++))

elif [ "$line" == "{" ] || [ "$line" == "}" ]
then
((brackets++))
elif [ -n "$line" ]
then
((nonempty++))
fi

done < $1

echo "non-blank lines: $nonempty"

+ 2
- 0
example_matrices/m1 View File

@@ -0,0 +1,2 @@
1 2 3 4
5 6 7 8

+ 25
- 0
example_matrices/m10 View File

@@ -0,0 +1,25 @@
-80 85 -94 93 28 88 47 37 9 8 51 -39 -63 56 -72 -39 80 -77 -22 70 44 -47 57 62 -77
-66 22 -30 10 -16 -26 16 -93 2 -87 32 -26 -52 99 -59 8 4 62 -66 -73 -46 -7 -88 -14 94
-41 82 45 -37 -18 -66 0 99 -28 42 -13 -22 67 52 30 87 95 -14 -7 -68 2 -12 -98 -49 79
-33 40 -76 80 97 18 -63 39 -74 99 60 -64 31 -88 32 74 97 -66 21 11 45 -5 -21 -4 -12
-78 8 5 -13 -79 -67 -23 -40 -80 13 -73 -62 -38 -13 -77 40 -61 88 81 -6 72 -71 -40 53 -26
-85 2 46 -79 -95 15 -86 35 -57 12 -94 -1 -9 -42 52 0 38 65 1 41 -52 -1 -92 -28 57
60 71 -22 -90 -3 -53 -16 -90 98 -88 53 -81 -67 -51 -24 -74 90 36 99 -57 59 -14 10 -90 -53
-23 -84 -29 2 -19 96 4 -6 -54 -73 38 -6 99 -57 63 40 -83 19 -15 80 -90 34 68 -22 -78
2 -74 -18 -45 -16 12 -99 8 98 59 72 20 -51 37 -28 56 11 79 0 94 -48 10 69 60 -22
68 -48 12 -14 51 -11 10 -97 -88 -87 9 -77 -99 79 -38 75 -48 -78 38 -51 -3 -47 66 -5 -52
-87 -93 1 93 13 77 31 79 -97 -73 -69 7 97 -24 -14 -7 -40 53 58 -14 -78 33 26 51 -48
17 -18 -90 -27 86 9 -97 51 27 -26 -81 -44 -34 -28 71 -56 -17 -88 3 89 14 59 -7 -45 -47
-5 96 -80 30 -1 43 31 -21 70 94 2 16 49 46 -67 69 0 64 -53 32 -94 96 -76 87 21
-1 72 35 67 -23 15 51 -3 -75 4 65 -44 -1 -43 66 -21 -88 -59 -29 -25 30 -57 21 -81 -76
-36 94 59 -2 86 25 -10 53 63 -24 67 49 -37 -39 -39 -14 67 -77 -76 74 46 -34 -3 85 -54
-26 -48 -34 -24 -75 67 33 6 43 -82 -25 58 82 -13 47 66 18 -39 57 -29 -8 85 15 -98 -83
-21 9 -7 86 4 72 17 -73 -64 71 -48 65 -38 -51 -2 -10 7 -69 -21 -33 -96 -26 37 25 -23
-52 -72 23 -46 7 70 12 11 -36 -38 28 71 -22 46 -40 -86 70 81 81 -34 76 -32 -90 92 77
35 -13 -63 42 63 97 -52 94 49 69 -66 25 21 42 98 93 15 -35 -13 90 -4 65 -35 34 -10
-15 -36 -49 -2 -42 -64 43 78 -31 -56 -89 -9 37 -8 -55 -4 17 74 79 55 17 46 6 85 34
49 -53 81 36 -10 -82 -48 -4 -50 11 -11 62 46 -64 74 -18 13 -76 0 87 92 -65 -37 58 50
-68 -6 62 8 93 58 80 35 55 45 21 41 0 88 -13 -47 36 45 43 -25 -40 -25 -81 -8 -40
-85 -30 -4 -17 73 -30 15 97 -64 63 81 86 3 -40 -36 7 83 43 -91 42 0 77 96 -77 10
56 46 -10 12 0 -21 2 -6 7 72 65 14 -67 2 0 53 -36 92 -52 -30 59 -86 -13 -61 -94
-74 -78 50 -78 36 81 -19 11 81 19 78 -55 -69 66 41 4 92 74 -58 -43 24 25 -74 -58 95

+ 25
- 0
example_matrices/m11 View File

@@ -0,0 +1,25 @@
-46 19 8 23 22 -11 34 10 -36 -90 58 -23 -73 -73 -92 40 78 -43 -59 34 0 -83 72 0 -23
89 -13 42 -49 52 15 37 68 -90 85 -29 37 53 67 92 -61 -69 16 -91 81 -96 -48 30 63 -4
60 70 92 -43 91 -21 85 -38 -13 16 73 50 55 -21 79 56 -39 -15 94 -32 -57 -3 -19 0 97
87 86 -58 -11 -47 -50 -36 -67 -47 -83 -79 -44 -63 75 -80 -67 -27 22 4 -50 30 -69 39 -12 6
51 -94 26 3 -36 -50 -65 -66 36 -11 62 -39 5 4 65 85 -9 -42 82 41 -19 -43 -86 -71 16
86 -30 -46 59 56 81 -95 -97 -42 71 28 52 -15 -36 3 -81 -33 -5 -75 -73 -3 -17 -83 70 -71
-37 66 4 50 61 -92 86 -20 85 -74 -1 -41 39 73 -49 34 -41 29 -65 47 44 -48 -4 98 66
-73 -34 32 17 3 80 -45 -20 65 59 -14 -15 -60 62 5 -56 -51 70 -98 5 55 67 -67 -95 -51
13 54 15 -72 -67 48 98 45 17 48 45 37 99 87 -96 -75 36 -82 65 -72 88 83 -29 -14 -62
-43 -18 -77 73 -59 -42 4 -45 68 -15 15 71 -20 7 -80 21 -32 63 -11 73 34 3 63 68 60
-75 65 88 90 -28 -68 -14 57 -11 12 -97 3 83 76 -53 -42 -35 24 -35 -89 -96 58 -3 70 52
-71 18 -37 12 -72 14 93 32 63 47 64 -14 15 62 55 69 -75 -83 1 39 85 80 25 -98 -19
-9 -71 -87 35 -47 -11 -48 -8 -80 -68 -53 59 -38 -64 6 5 14 60 -70 -18 28 44 -2 1 -71
3 89 0 17 -16 -24 30 58 -67 -29 8 -5 30 -75 31 -62 7 -81 89 66 92 71 -34 20 41
-34 -11 -70 0 73 80 43 29 -67 -9 6 -94 -19 -46 44 -45 69 51 -78 -66 71 48 60 -51 -27
21 -90 -37 -35 21 -25 29 96 26 -90 -46 45 89 69 -20 99 98 -91 -40 -54 45 -42 51 -39 -71
-32 3 10 40 63 42 -3 -55 -53 -8 -98 -48 -43 -50 34 95 -98 95 83 55 -75 -61 -91 28 43
-88 66 9 -83 84 4 -47 -48 42 -11 -9 -85 0 -68 -45 -69 -52 68 94 34 4 94 -42 73 -50
26 -56 75 -14 -4 -92 72 -8 75 -79 49 47 -55 79 57 -53 8 98 85 12 -47 -54 -61 -24 55
72 31 18 -57 -85 -76 -65 46 14 -64 -61 81 92 89 -76 -96 29 -57 98 -21 -75 -66 14 19 -7
39 -24 -64 -85 80 -75 -48 57 -5 -52 -60 -73 27 -56 -90 -43 41 -55 -26 -47 -31 96 20 76 -4
17 -20 -98 28 87 70 54 -45 -61 90 2 48 0 97 53 -48 67 86 16 50 97 69 -8 48 -11
70 -26 -63 55 62 -70 -41 -28 -46 -93 -54 -69 90 -52 11 98 28 64 -31 76 -59 -67 44 -77 -85
-65 54 57 90 0 6 -70 77 -90 31 -3 87 -24 28 -84 23 0 36 71 -76 -84 12 95 49 -95
77 32 -46 -1 -28 81 15 -58 30 92 -36 -29 7 57 58 -70 60 11 11 63 -72 -3 -29 23 76

+ 5
- 0
example_matrices/m12 View File

@@ -0,0 +1,5 @@
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

+ 3
- 0
example_matrices/m13 View File

@@ -0,0 +1,3 @@
1 2 3
4 5 6
7 8 9

+ 3
- 0
example_matrices/m14 View File

@@ -0,0 +1,3 @@
0 0 0
0 0 0
0 0 0

+ 10
- 0
example_matrices/m15 View File

@@ -0,0 +1,10 @@
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

+ 10
- 0
example_matrices/m16 View File

@@ -0,0 +1,10 @@
24 -83 55 -74 75 -23 72 -10 -42 67 93 -18 2 86 -66
26 -66 -65 -9 -85 60 -88 -30 56 -30 -17 -30 49 0 27
-65 -36 99 45 58 48 22 36 -17 -48 64 12 71 -83 34
69 -34 -39 77 39 -40 -55 48 41 -39 -84 62 4 46 75
-67 28 12 23 -33 9 -93 -77 94 -34 4 58 -8 -85 -72
40 -39 -79 -50 31 -4 2 -71 -92 41 -30 44 -9 32 6
15 73 -29 5 -68 79 95 0 86 0 -37 10 72 14 73
47 -80 47 -60 79 -64 -19 93 -51 94 -72 32 -58 32 -43
-48 -20 95 -39 -49 -53 82 13 -19 80 7 -89 -24 52 13
-20 -23 38 -89 74 -61 -96 -86 -28 74 -95 67 56 0 58

+ 4
- 0
example_matrices/m2 View File

@@ -0,0 +1,4 @@
1 5
2 6
3 7
4 8

+ 0
- 0
example_matrices/m3 View File


+ 5
- 0
example_matrices/m4 View File

@@ -0,0 +1,5 @@
1 2
-3 4
3 6
8
9 10

+ 3
- 0
example_matrices/m5 View File

@@ -0,0 +1,3 @@
1 2 3
4 5 6
7 8 9

+ 3
- 0
example_matrices/m6 View File

@@ -0,0 +1,3 @@
1 2
2 3
3 4

+ 20
- 0
example_matrices/m9 View File

@@ -0,0 +1,20 @@
-93 -92 29 -45 -55 -87 -36 39 -88 71 7 -69 52 45 -22
50 -27 85 11 -76 -3 23 68 58 -5 34 7 -29 -49 41
-61 2 -44 -62 47 -77 33 6 -7 55 -45 99 2 20 89
52 -97 57 -39 -76 62 24 69 -74 89 -76 1 -46 -27 -9
55 77 42 10 -98 -22 15 -48 26 33 -7 29 -34 78 -19
23 25 -40 16 -63 -12 42 45 -22 20 44 -23 78 -50 17
-67 14 -9 -58 38 -78 2 99 -87 -92 -34 -29 -7 -31 11
65 -32 27 91 -46 -13 -71 37 24 -5 34 -92 6 15 -15
-49 23 -52 -9 59 -57 -78 -10 17 -27 44 -34 -62 22 -94
-45 -45 88 -12 -64 1 -60 -35 11 1 -10 52 5 52 -17
-91 61 90 22 82 -9 82 85 10 56 18 4 -18 -92 -46
31 98 47 -12 -60 20 54 -8 92 24 -71 -23 24 91 37
-12 98 -13 66 72 -14 88 51 75 5 40 -91 91 -94 26
0 60 -41 6 28 -54 97 56 40 -17 94 -92 -23 -3 -91
10 -26 78 -22 -55 73 -82 -49 -26 -63 -80 8 97 87 -27
80 17 90 22 6 45 23 91 16 -93 -38 -64 -75 35 61
21 -24 -38 92 -43 98 -14 35 39 -65 -20 65 65 19 -81
79 -32 62 -93 89 19 -83 -47 45 20 93 49 43 73 80
24 81 19 -15 48 -46 -23 -63 65 2 75 -16 1 -98 14
-40 -68 -89 -10 90 29 3 -15 58 86 -85 36 -55 31 -79

+ 53
- 0
generate View File

@@ -0,0 +1,53 @@
#!/bin/bash
function generate(){
# NAME
# generate - generate a matrix of a specified size
# SYNOPSIS
# generate ROWS COLS RANGE
# DESCRIPTION
# Outputs a matrix with ROWS and COLS as dimensions. If RANGE is an integer, the entries
# of the matrix will be random integers in (-RANGE,+RANGE). If RANGE is a string starting
# with 'Z' or 'z', the matrix will be populated with zeroes. If RANGE is a string starting
# with 'O' or 'o', the matrix will be populated with ones. If RANGE is a string starting
# with 'D' or 'd', the matrix will be a diagonal matrix with ones along the diagonal entries.
# AUTHOR
# Written by Ryan Gambord (gambordr@oregonstate.edu)

[ $# -ne 3 ] && echo "invalid number of arguments" >&2 # This is equivalent to using an if statement.
# The right side of the && operator will not
# be evaluated unless the left side is true.
for arg in $1 $2
do
[[ $arg =~ [^0-9]+ ]] && echo "argument '$arg' is not an integer" >&2
done

y=0
while [ $y -lt $1 ]
do
x=0
((y++))
while [ $x -lt $2 ]
do
((x++))
case $3 in
[oO]*) echo -n 1;;
[zZ]*) echo -n 0;;
[dD]*) [ $x -eq $y ] && echo -n 1 || echo -n 0;;
*) if [[ "$3" =~ [^0-9]+ ]]
then
echo "invalid RANGE" >&2
exit 1
else
echo -n $(( (RANDOM - 32767 / 2) % $3 ))
fi;;
esac
if [ $x -ne $2 ]
then
echo -ne "\t"
else
echo
fi
done
done
}
generate $1 $2 $3

+ 163
- 0
index.md View File

@@ -0,0 +1,163 @@
---
layout: my-default
title: code
---

<div class="container">


<div class="fixed" id="featured" style="border: solid 1px #d5d5d5; width: 100%; margin: 0%">
<a href="https://www.github.com/lbeckman314/matrix"><img class="center" src="/assets/png/matrix.png"></a>
<div class="border-code"></div>
<p class="center">
<a id="title" href="https://www.github.com/lbeckman314/matrix">matrix</a></p>
<p class = "code">Multiply, add, transpose, and average matrices like it's going out of style!</p>

<ul class="code">
<li class="code"><a href="matrix.zip"><img src="/assets/svg/octicons-5.0.1/lib/svg/file-zip.svg"> zip</a></li>
<li class="code"><a href="matrix.tar.gz"><img src="/assets/svg/octicons-5.0.1/lib/svg/file-zip.svg"> tar.gz</a></li>
<li class="code"><a href="https://github.com/lbeckman314/matrix/"><img src="/assets/svg/octicons-5.0.1/lib/svg/code.svg"> github</a> / <a href="https://git.liambeckman.com/cgit/matrix.git">cgit</a></li>
<li class="code"><a href="sha256sums.txt"><img src="/assets/svg/octicons-5.0.1/lib/svg/file-text.svg"> sha256sums</a></li>
</ul>

</div>


</div>


<br />
<br />

This program uses the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) to compute the first million primes. On my laptop it takes about 30 seconds, but it may be faster or slower on yours. [See it in action!](https://asciinema.org/a/CUqAnP8NgipoPTlQo2apmAErB)

<br />

```
n: nth Prime:
5 11
10 29
100 541
1000 7919
10000 104729
100000 1299709
1000000 15485863

found in 31.0171 seconds
```

<br />
<br />

# Installation



<br />

<h2 class="code">1. Download</h2>

```shell
wget http://www.liambeckman.com/code/matrix/matrix.tar.gz
# or if you prefer curl:
# curl http://www.liambeckman.com/code/matrix/matrix.tar.gz -o matrix.tar.gz
```

<br />



<h2 class="code"><button class="accordion">Optional (but recommended): verify file integrity</button></h2>

```shell
#-------------------------------#
# RECIEVE GPG KEYS
#-------------------------------#

gpg --keyserver pgp.mit.edu --recv-keys AC1CC079

#-------------------------------#
# RECIEVE SHA256SUMS
#-------------------------------#

wget http://www.liambeckman.com/code/matrix/sha256sums.txt{,.sig}
# or if you prefer curl:
# curl http://www.liambeckman.com/code/matrix/sha256sums.txt{,.sig} -o sha256sums.txt -o sha256sums.txt.sig

#-------------------------------#
# VERIFY SHA256SUMS
#-------------------------------#

gpg --verify sha256sums.txt.sig

# gpg: Signature made Tue Oct 31 11:11:11 2017 PDT using RSA key ID AC1CC079
# gpg: Good signature from "liam beckman ("I only want to live in peace, plant potatoes, and dream!" -Tove Jansson) <lbeckman314@gmail.com>" [unknown]

#-------------------------------#
# VERIFY FILE INTEGRITY
#-------------------------------#

sha256sum -c sha256sums.txt

# matrix.tar.gz: OK
# matrix.zip: OK

#-------------------------------#
# OPTIONALLY REMOVE PUBLIC KEY
#-------------------------------#

# to remove my public key from your public key ring, simply
gpg --delete-key AC1CC079
```

<br />

<h2 class="code">2. Extract</h2>


```shell
tar -zxvf matrix.tar.gz
# or if you downloaded the zip file
# unzip matrix.zip
```

<br />

<h2 class="code">3. Compile and run</h2>


```shell
g++ matrix/src/matrix.cpp -o matrix/src/matrix
./matrix/src/matrix
```

<br />
<br />

# Uninstallation

<br />

<h2 class="code">1. Delete the directory/folder.</h2>

```shell
rm -rfI matrix
```


<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
</script>

+ 1
- 0
m1 View File

@@ -0,0 +1 @@
example_matrices/m1

+ 563
- 0
matrix View File

@@ -0,0 +1,563 @@
#!/bin/bash
# author: liam beckman
# created: 2018-04-03
# updated: 2018-04-13
# sources:
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
# p1gradingscript, Written by Ryan Gambord (gambordr@oregonstate.edu)
# https://stackoverflow.com/questions/8550385/how-to-read-1-line-from-2-files-sequentially

# control-c will terminate script execution and remove temporary files
trap "echo; echo 'SIGINT received: Deleting temp files then exiting!'; clean; exit 1" INT

# Parse any args
fancy=0
POSITIONAL=()

while [ $# -gt 0 ]
do
if [[ $1 == "--fancy" ]] || [[ $1 == "-f" ]]
then
# output fancy message
fancy=1
shift
fi

# save it in an array for later
POSITIONAL+=("$1")

# shift past argument
shift
done

# restore positional parameters
set -- "${POSITIONAL[@]}"


# valiadate user's matrices
validate()
{
# clear temporary validate file
> validate$$.temp


if [ ! -f $1 ] || [ ! -r $1 ]
then
echo "$1 is an unreadable file" >&2
exit 1
fi


read entireline < $1
x1=0
for i in $entireline
do
x1=$((x1 + 1))
done


# An empty matrix.
if [ ! -s $1 ]
then
echo "empty matrix error" >&2
exit 1
fi

# A matrix where the final entry on a row is followed by a tab character.
tail -n 1 $1 >> validate$$.temp


# trailing tabs error
trailingTab=0
trailingTab=$(grep -c $'\t'$ validate$$.temp)
#trailingTabOrSpace=$(grep -c '[[:blank:]]$' validate$$.temp)

if [ $trailingTab -gt 0 ]
then
echo "trailing tabs error at last row in $1" >&2
exit 1
fi

y=1
while read line
do
# A matrix with empty lines.
if [ -z "$line" ]
then
echo "empty line error at row $y in $1" >&2
exit 1
fi

x=0
for element in $line
do

# A matrix with any element that is not an integer.
if [ $element -eq $element ] 2>/dev/null
then
((x++))
else
echo "non-numeric element error in $1: $element" >&2
exit 1
fi

done

# A matrix with any element that is blank.
if [ $x -lt $x1 ]
then
echo "blank element at column $x, row $y in $1" >&2
exit 1
fi

((y++))
done < $1

#rm -f validate$$.temp

}


dims()
{
# clear temporary dims file
> dims$$.temp

rows=0
cols=0

# read in columns
read entireline < $1
for i in $entireline
do
cols=$((cols + 1))
done

# read in rows
rows=$(wc -l < $1)

echo -n $rows
echo -n " "
echo -n $cols
echo

echo $cols >> dims$$.temp
echo $rows >> dims$$.temp
}

transpose()
{
# clear temporary transpose file
> transpose$$.temp

# if there is a file being read in...
if [ $1 ]
then dims $1 &> /dev/null

# otherwise we're reading from stdin
else
dims stdinLeft$$.temp &> /dev/null
fi

x1="$(head -n 1 dims$$.temp)"

# convert columns to rows
for i in $(seq 1 $x1)
do
cut -f$i $1 | paste -s >> transpose$$.temp
done

# output transpose matrix to stdin
cat transpose$$.temp
}


mean()
{
# clear temporary dims file
> mean$$.temp

dims $1 &> /dev/null

x1="$(head -n 1 dims$$.temp)"

# prime the transpose$$.temp file
transpose $1 &> /dev/null

# the x-coordinate of the current column of the ouput. Used for outputting newlines.
endOfLine=0

while read line
do
sum=0
count=0
average=0

# for all elements in the matrix
for element in $line
do
# add element to the total sum
sum=$((sum + element))
((count++))
done

average=$(((sum + (count/2)*( (sum>0)*2-1 )) / count))

# increment the x-coordinate of the mean row
((endOfLine++))

# if we have not reached the end of the row...
if [ $endOfLine -lt $x1 ]
then
# just print the mean and a tab
printf "%s\t" "$average"
else
# otherwise print the mean
printf "%s" "$average"
fi

done < transpose$$.temp
echo

}


add()
{
# clear temporary add files
> addLeft$$.temp
> addRight$$.temp


dims $1 &> /dev/null

x1="$(head -n 1 dims$$.temp)"
y1="$(tail -n 1 dims$$.temp)"


dims $2 &> /dev/null

x2="$(head -n 1 dims$$.temp)"
y2="$(tail -n 1 dims$$.temp)"


if [ $x1 -ne $x2 ] || [ $y1 -ne $y2 ]
then
echo -e "\e[1;31mERROR\e[0m: matrix dimensions do not match" >&2 # Print error message if at top
echo -e "matrix one: \e[1;31m$y1 x $x1\e[0m" >&2
echo -e "matrix two: \e[1;31m$y2 x $x2\e[0m" >&2
exit 1
fi



# convert first matrix into a "X by 1" matrix in temp file
# this will make it easier to draw elements from
cat $1 | tr '\t' '\n' >> addLeft$$.temp

# convert second matrix into a "X by 1" matrix in temp file
# this will make it easier to draw elements from
cat $2 | tr '\t' '\n' >> addRight$$.temp

# the given column number of the sum matrix. Used for outputting newlines.
endOfLine=0

# read in both matrices and add elements
while read left && read right <&3
do

# calculate sum
sum=$((left + right))

# increment the x-coordinate of the sum matrix
((endOfLine++))

# if we have not reached the end of the row...
if [ $endOfLine -lt $x1 ]
then
# just print the mean and a tab
printf "%s\t" $sum
else
# otherwise print the mean
printf "%s" $sum
echo

# reset column position of product matrix
endOfLine=0
fi
done < addLeft$$.temp 3< addRight$$.temp
}


multiply()
{
# clear temporary multiply files
> multiplyLeft$$.temp
> multiplyRight$$.temp


# transpose second matrix to make it easier to read in elements
transpose $2 &> /dev/null

# get first matrix's dimensions
dims $1 &> /dev/null

x1="$(head -n 1 dims$$.temp)"
y1="$(tail -n 1 dims$$.temp)"

# get second matrix's dimensions
dims $2 &> /dev/null

x2="$(head -n 1 dims$$.temp)"
y2="$(tail -n 1 dims$$.temp)"


# error message for misproportioned matrices
if [ $x1 -ne $y2 ]
then
echo -e "\e[1;31mERROR\e[0m: matrix dimensions do not match" >&2
echo -e "matrix one: $y1 x \e[1;31m$x1\e[0m" >&2
echo -e "matrix two: \e[1;31m$y2\e[0m x $x2" >&2
exit 1
fi


# add first matrix into array
arr2=0
while read line
do
for element in $line
do
#echo "element: $element"
arr2+=($element)
#echo arr2
done
done < $1

# add second matrix into array
arr3=0
while read line
do
for element in $line
do
#echo "element: $element"
arr3+=($element)
#echo arr2
done
done < $2


# the number of processed rows in the first matrix
rowTotal=0

# the x-coordinate of the current column of the first matrix. Used for outputting newlines.
endOfLine=0

while read line
do
# the column that is currently being processed
columnIndex=0
while [ $columnIndex -lt $x2 ]
do
# the number of processed columns in the second matrix
columnTotal=0

# the row that is currently being processed
rowIndex=0

# sum of multiplications between elements.
sum=0

while [ $columnTotal -lt $x1 ]
do
# left element in multiplication
left=${arr2[$x1 * $rowTotal + $rowIndex + 1 ]}

# right element in multiplication
right=${arr3[$x2 * $columnTotal + $columnIndex + 1]}

#add to sum the product of the left and right elements
sum=$((sum + left * right))

#increment the total number of columns that have been processed
((columnTotal++))

#increment the row index of the first matrix
((rowIndex++))
done

#increment the column index of the second matrix
((columnIndex++))

# increment the x-coordinate of the product matrix
((endOfLine++))

# if we have not reached the end of the row...
if [ $endOfLine -lt $x2 ]
then
# just print the sum and a tab
printf "%s\t" $sum
else
# otherwise print the sum
printf "%s" $sum

# enter new row in product matrix
echo

# reset column position of product matrix
endOfLine=0
fi
done

#increment the total number of rows that have been processed
((rowTotal++))

done < $1


# remove temporary files
#rm -f multiplyLeft$$.temp
#rm -f multiplyRight$$.temp

runtime=$((end-start))
echo $runtime > timeMultiply.temp

}


clean()
{
# remove temporary files
rm -f addLeft$$.temp
rm -f addRight$$.temp

#rm -f dims$$.temp
rm -f dims*.temp

rm -f mean$$.temp

#rm -f multiplyLeft$$.temp
#rm -f multiplyRight$$.temp
rm -f multiplyLeft*.temp
rm -f multiplyRight*.temp

rm -f stdinLeft$$.temp
rm -f stdinRight$$.temp

#rm -f transpose$$.temp
rm -f transpose*.temp

#rm -f validate$$.temp
rm -f validate*.temp

}

fancyGoodbye()
{
echo
echo "  Don't worry, __
\"Bee\" happy! // \\
\\\_/ //
''-.._.-''-.._.. -(||)(')
'''"
}

main()
{
# inavlid number of operations provided
[ $# -gt 4 ] && echo "too many arguments specified" >&2 && exit 1


# validate input
if [ $# -eq 2 ]
then
validate $2

elif [ $# -eq 3 ]
then
validate $2
validate $3
fi

# functions that accept input from stdin
if [ $1 = "dims" ] || [ $1 = "transpose" ] || [ $1 = "mean" ]
then
# read from standard input
if [ $# -eq 1 ]
then
cat > stdinLeft$$.temp
cat > stdinRight$$.temp

# validate input
if [ -s stdinLeft$$.temp ]
then
validate stdinLeft$$.temp
fi

if [ -s stdinRight$$.temp ]
then
validate stdinRight$$.temp
fi
fi

else
# inavlid number of operations provided
[ $# -lt 2 ] && echo "too few arguments specified" >&2 && exit 1
fi


case $1 in
# call dims function
dims)
if [ $2 ];
then
dims $2
else
dims stdinLeft$$.temp
fi
;;
# call transpose function
transpose)
if [ $2 ];
then
transpose $2
else
transpose stdinLeft$$.temp
fi
;;
# call mean function
mean)
if [ $2 ];
then
mean $2
else
mean stdinLeft$$.temp
fi
;;
# call add function
add)
add $2 $3
;;
# call multiply function
multiply)
multiply $2 $3
;;
# invalid operation provided
*)
echo "unknown operation provided" >&2
;;
esac


# call fancy goodbye function
if [ $fancy -eq 1 ]
then
fancyGoodbye
fi

# call clean function and remove temporary files
clean
}

# call main function with all arguments
main $@

+ 736
- 0
p1grading_result View File

@@ -0,0 +1,736 @@
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("58 75" == "58 75") (3/3)
 Passed: Stdin: ("51 71" == "51 71") (3/3)
 Passed: Stdin: ("89 90" == "89 90") (3/3)
 Passed: File input: ("72 86" == "72 86") (3/3)
 Passed: File input: ("54 100" == "54 100") (3/3)
 Passed: File input: ("52 61" == "52 61") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("92 78" == "92 78") (3/3)
 Passed: Stdin: ("86 78" == "86 78") (3/3)
 Passed: Stdin: ("94 99" == "94 99") (3/3)
 Passed: File input: ("95 95" == "95 95") (3/3)
 Passed: File input: ("69 89" == "69 89") (3/3)
 Passed: File input: ("98 51" == "98 51") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("54 64" == "54 64") (3/3)
 Passed: Stdin: ("78 88" == "78 88") (3/3)
 Passed: Stdin: ("64 96" == "64 96") (3/3)
 Passed: File input: ("78 98" == "78 98") (3/3)
 Passed: File input: ("53 89" == "53 89") (3/3)
 Passed: File input: ("65 80" == "65 80") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("85 61" == "85 61") (3/3)
 Passed: Stdin: ("97 97" == "97 97") (3/3)
 Passed: Stdin: ("87 86" == "87 86") (3/3)
 Passed: File input: ("92 88" == "92 88") (3/3)
 Passed: File input: ("92 97" == "92 97") (3/3)
 Passed: File input: ("78 80" == "78 80") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("85 79" == "85 79") (3/3)
 Passed: Stdin: ("70 51" == "70 51") (3/3)
 Passed: Stdin: ("72 78" == "72 78") (3/3)
 Passed: File input: ("59 83" == "59 83") (3/3)
 Passed: File input: ("76 93" == "76 93") (3/3)
 Passed: File input: ("59 76" == "59 76") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("56 69" == "56 69") (3/3)
 Passed: Stdin: ("96 95" == "96 95") (3/3)
 Passed: Stdin: ("98 69" == "98 69") (3/3)
 Passed: File input: ("76 98" == "76 98") (3/3)
 Passed: File input: ("97 71" == "97 71") (3/3)
 Passed: File input: ("68 73" == "68 73") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("59 67" == "59 67") (3/3)
 Passed: Stdin: ("65 79" == "65 79") (3/3)
 Passed: Stdin: ("63 80" == "63 80") (3/3)
 Passed: File input: ("95 80" == "95 80") (3/3)
 Passed: File input: ("93 57" == "93 57") (3/3)
 Passed: File input: ("87 85" == "87 85") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("74 92" == "74 92") (3/3)
 Passed: Stdin: ("74 94" == "74 94") (3/3)
 Passed: Stdin: ("85 89" == "85 89") (3/3)
 Passed: File input: ("61 71" == "61 71") (3/3)
 Passed: File input: ("63 55" == "63 55") (3/3)
 Passed: File input: ("88 65" == "88 65") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("98 97" == "98 97") (3/3)
 Passed: Stdin: ("64 73" == "64 73") (3/3)
 Passed: Stdin: ("79 98" == "79 98") (3/3)
 Passed: File input: ("65 77" == "65 77") (3/3)
 Passed: File input: ("68 92" == "68 92") (3/3)
 Passed: File input: ("82 91" == "82 91") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("77 70" == "77 70") (3/3)
 Passed: Stdin: ("81 99" == "81 99") (3/3)
 Passed: Stdin: ("73 51" == "73 51") (3/3)
 Passed: File input: ("62 76" == "62 76") (3/3)
 Passed: File input: ("60 83" == "60 83") (3/3)
 Passed: File input: ("64 70" == "64 70") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Failed: m1 == T(T(m1)) (0/5)
 Failed: m2 == T(T(m2)) (0/5)
 Failed: m3 == T(T(m3)) (0/5)
Unit test 5: matrix mean test
# (running score = 43/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 70/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 98/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 133/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("89 79" == "89 79") (3/3)
 Passed: Stdin: ("80 60" == "80 60") (3/3)
 Passed: Stdin: ("100 93" == "100 93") (3/3)
 Passed: File input: ("76 77" == "76 77") (3/3)
 Passed: File input: ("97 70" == "97 70") (3/3)
 Passed: File input: ("63 66" == "63 66") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("53 73" == "53 73") (3/3)
 Passed: Stdin: ("92 67" == "92 67") (3/3)
 Passed: Stdin: ("79 60" == "79 60") (3/3)
 Passed: File input: ("77 57" == "77 57") (3/3)
 Passed: File input: ("84 92" == "84 92") (3/3)
 Passed: File input: ("95 88" == "95 88") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Failed: m1 == T(T(m1)) (0/5)
 Failed: m2 == T(T(m2)) (0/5)
 Failed: m3 == T(T(m3)) (0/5)
Unit test 5: matrix mean test
# (running score = 43/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 70/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Failed: Stdin: ("0 0" == "58 99") (0/3)
 Failed: Stdin: ("0 0" == "77 87") (0/3)
 Failed: Stdin: ("0 0" == "66 59") (0/3)
 Passed: File input: ("60 84" == "60 84") (3/3)
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("80 68" == "80 68") (3/3)
 Passed: Stdin: ("92 84" == "92 84") (3/3)
 Passed: Stdin: ("92 98" == "92 98") (3/3)
 Passed: File input: ("62 58" == "62 58") (3/3)
 Passed: File input: ("81 65" == "81 65") (3/3)
 Passed: File input: ("100 76" == "100 76") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("73 60" == "73 60") (3/3)
 Passed: Stdin: ("86 89" == "86 89") (3/3)
 Passed: Stdin: ("99 91" == "99 91") (3/3)
 Passed: File input: ("74 87" == "74 87") (3/3)
 Passed: File input: ("71 76" == "71 76") (3/3)
 Passed: File input: ("88 68" == "88 68") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148
┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸
┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃
┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹
Unit test 1: error messages
# (running score = 0/0)
 Passed: too many args to matrix dims (1/1)
 Passed: no args to matrix add (1/1)
 Passed: multiplying incompatible matrices (5/5)
 Passed: adding incompatible matrices (4/4)
 Passed: tranpose unreadable file (2/2)
 Passed: get dims of nonexistent file (1/1)
 Passed: matrix badcommand (1/1)
Unit test 2: matrix dims tests
# (running score = 15/15)
 Passed: Stdin: ("65 72" == "65 72") (3/3)
 Passed: Stdin: ("56 70" == "56 70") (3/3)
 Passed: Stdin: ("71 59" == "71 59") (3/3)
 Passed: File input: ("51 86" == "51 86") (3/3)
 Passed: File input: ("88 58" == "88 58") (3/3)
 Passed: File input: ("56 77" == "56 77") (3/3)
Unit test 3: matrix transpose hardcoded test
# (running score = 33/33)
 Passed: m1 == T(m2) and T(m1) == m2 (10/10)
Unit test 4: matrix transpose involution test
# (running score = 43/43)
 Passed: m1 == T(T(m1)) (5/5)
 Passed: m2 == T(T(m2)) (5/5)
 Passed: m3 == T(T(m3)) (5/5)
Unit test 5: matrix mean test
# (running score = 58/58)
 Passed: zero matrix (2/2)
 Passed: ones matrix (5/5)
 Passed: identity matrix (5/5)
 Passed: hardcoded matrix (15/15)
Unit test 6: matrix add test
# (running score = 85/85)
 Passed: 0 + 0 == 0 (2/2)
 Passed: X + 0 == X (5/5)
 Passed: 0 + X == X (5/5)
 Passed: A + B == B + A (1/1)
 Passed: m1 + m2 == m3 (hardcoded matrix) (15/15)
Unit test 7: matrix multiply test
# (running score = 113/113)
 Passed: I * M == M (5/5)
 Passed: M * I == M (5/5)
 Passed: 0 * M == 0 (5/5)
 Passed: m3 == m1 * m2 (hardcoded matrix) (20/20)
# Final grade: 148/148


+ 604
- 0
p1gradingscript View File

@@ -0,0 +1,604 @@
#!/bin/bash
exec > >(tee -a ./p1grading_result) 2>&1 # Copy all output to ./p1grading_result

# Parse any args
nocolor=1
while [ $# -gt 0 ]
do
if [[ $1 == "-nocolor" ]]
then
nocolor=0
fi
shift
done

###############################################################################
# Begin helper functions
# generate() - Generates a matrix
# perror() - prints error messages
# failed() - prints failed test message
# passed() - prints passed test message
# result() - if $? == 0, calls passed(), otherwise calls failed()
# comment() - prints comment to output
# unit() - prints unit test headers
###############################################################################

function generate(){
# NAME
# generate - generate a matrix of a specified size
# SYNOPSIS
# generate ROWS COLS RANGE
# DESCRIPTION
# Outputs a matrix with ROWS and COLS as dimensions. If RANGE is an integer, the entries
# of the matrix will be random integers in (-RANGE,+RANGE). If RANGE is a string starting
# with 'Z' or 'z', the matrix will be populated with zeroes. If RANGE is a string starting
# with 'O' or 'o', the matrix will be populated with ones. If RANGE is a string starting
# with 'D' or 'd', the matrix will be a diagonal matrix with ones along the diagonal entries.
# AUTHOR
# Written by Ryan Gambord (gambordr@oregonstate.edu)

[ $# -ne 3 ] && echo "invalid number of arguments" >&2 # This is equivalent to using an if statement.
# The right side of the && operator will not
# be evaluated unless the left side is true.
for arg in $1 $2
do
[[ $arg =~ [^0-9]+ ]] && echo "argument '$arg' is not an integer" >&2
done

y=0
while [ $y -lt $1 ]
do
x=0
((y++))
while [ $x -lt $2 ]
do
((x++))
case $3 in
[oO]*) echo -n 1;;
[zZ]*) echo -n 0;;
[dD]*) [ $x -eq $y ] && echo -n 1 || echo -n 0;;
*) if [[ "$3" =~ [^0-9]+ ]]
then
echo "invalid RANGE" >&2
exit 1
else
echo -n $(( (RANDOM-32767/2) % $3 ))
fi;;
esac
if [ $x -ne $2 ]
then
echo -ne "\t"
else
echo
fi
done
done

}

function perror(){
# NAME
# perror - print a stack trace and error message
# SYNOPSIS
# perror [STRING]
# DESCRIPTION
# Echoes the STRING(s) to standard error with a stack trace for debugging.
# The value of the status flag $? is not changed by perror.
# AUTHOR
# Written by Ryan Gambord (gambordr@oregonstate.edu)

status=$? # Capture status of previous command
echo -e "\e[36mTraceback (most recent call last):\e[0m" >&2
i=${#BASH_LINENO[@]} # Get number of items in stack trace

# This section prints a stack trace of the current execution stack
while
[ $i -gt 0 ] # Iterate to the top of the stack
do
until # Loop until we get to the bottom of caller stack (this is safer than offsetting $i)
((i--))
info=($(caller $i)) # Get caller info
do :; done # Do nothing

echo " File \"${info[2]}\", line ${info[0]}, in ${info[1]}()" >&2 # Print caller info
if [ $i -ne 0 ] # Check if we're at the top of the stack (perror call is at top)
then
echo " "$(head "${info[2]}" -n ${info[0]} | tail -n 1) >&2 # Print trace if not at top
else
echo -en "\e[31mERROR\e[0m: " >&2 # Print error message if at top
[ $# -gt 0 ] && echo "$*" >&2 || echo "(no error message specified)" >&2
fi
done
exit 1
}

function failed(){
[ $nocolor -eq 0 ] || echo -ne "\033[31m"
echo -e "\tFailed: $@"
[ $nocolor -eq 0 ] || echo -ne "\033[0m"
}

function passed(){
[ $nocolor -eq 0 ] || echo -ne "\033[32m"
echo -e "\tPassed: $@"
[ $nocolor -eq 0 ] || echo -ne "\033[0m"
}

function result(){
val=$?
pts=$2
if [ $# -lt 2 ]
then
pts=1
fi
if [ $val -eq 0 ]
then
passed "$1" "($pts/$pts)"
((score += pts))
((total += pts))
else
failed "$1" "(0/$pts)"
((total += pts))
fi
}

function comment(){
[ $nocolor -eq 0 ] || echo -ne "\033[0;96m"
echo -e "# $@"
[ $nocolor -eq 0 ] || echo -ne "\033[0m"
}
unit_count=0
function unit(){
((unit_count++))
[ $nocolor -eq 0 ] || echo -ne "\033[4m"
echo -e "Unit test $unit_count: $@"
[ $nocolor -eq 0 ] || echo -ne "\033[0m"
comment "(running score = $score/$total)"
}



###############################################################################
# End helper functions #
# Begin script #
###############################################################################

# Print banner

if [ $nocolor -eq 0 ]
then
echo -e "┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸\n┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃ \n┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹"
else
echo -e "┏┓ ┏━╸┏━╸╻┏┓╻┏┓╻╻┏┓╻┏━╸ ┏┳┓┏━┓╺┳╸┏━┓╻╻ ╻ ╺┳╸┏━╸┏━┓╺┳╸\n┣┻┓┣╸ ┃╺┓┃┃┗┫┃┗┫┃┃┗┫┃╺┓ ┃┃┃┣━┫ ┃ ┣┳┛┃┏╋┛ ┃ ┣╸ ┗━┓ ┃ \n┗━┛┗━╸┗━┛╹╹ ╹╹ ╹╹╹ ╹┗━┛ ╹ ╹╹ ╹ ╹ ╹┗╸╹╹ ╹ ╹ ┗━╸┗━┛ ╹ "
fi

# Initialize score and total variables
score=0
total=0

# Check for existence/executability of matrix file
if [ ! -r matrix ] || [ ! -x matrix ]
then
perror "matrix: permission error"
exit 0
fi

tmp1="$(mktemp --tmpdir p1grading_XXXXX)"
tmp2="$(mktemp --tmpdir p1grading_XXXXX)"
tmp3="$(mktemp --tmpdir p1grading_XXXXX)"
tmp4="$(mktemp --tmpdir p1grading_XXXXX)"

###############################################################################
# Begin unit tests #
###############################################################################

unit "error messages"

$(./matrix dims "$tmp1" "$tmp1" 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "too many args to matrix dims" 1

$(./matrix add 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "no args to matrix add" 1

generate 5 6 10 > "$tmp1"

$(./matrix multiply "$tmp1" "$tmp1" 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "multiplying incompatible matrices" 5

generate 6 5 10 > "$tmp2"
$(./matrix add "$tmp1" "$tmp2" 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "adding incompatible matrices" 4

chmod -r "$tmp1"
$(./matrix transpose "$tmp1" 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "tranpose unreadable file" 2
chmod +r "$tmp1"

$(./matrix dims $(mktemp -u) 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "get dims of nonexistent file" 1

$(./matrix badcommand 1>"$tmp2" 2>"$tmp3")
[ $? -ne 0 ] && [ -s "$tmp3" ] && [ ! -s "$tmp2" ]
result "matrix badcommand" 1

###############################################################################

unit "matrix dims tests"

for a in {0..2}
do
(( rows = RANDOM % 50 + 51 ))
(( cols = RANDOM % 50 + 51 ))
dims="$(generate $rows $cols 100 | ./matrix dims)"
[[ "$dims" == "$rows $cols" ]]
result "Stdin: (\"$dims\" == \"$rows $cols\")" 3
done

for a in {3..5}
do
(( rows = RANDOM % 50 + 51 ))
(( cols = RANDOM % 50 + 51 ))

generate $rows $cols 100 > "$tmp1"
dims="$(./matrix dims $tmp1)"
[[ "$dims" == "$rows $cols" ]]
result "File input: (\"$dims\" == \"$rows $cols\")" 3
done

###############################################################################

unit "matrix transpose hardcoded test"

m1="-93 -92 29 -45 -55 -87 -36 39 -88 71 7 -69 52 45 -22
50 -27 85 11 -76 -3 23 68 58 -5 34 7 -29 -49 41
-61 2 -44 -62 47 -77 33 6 -7 55 -45 99 2 20 89
52 -97 57 -39 -76 62 24 69 -74 89 -76 1 -46 -27 -9
55 77 42 10 -98 -22 15 -48 26 33 -7 29 -34 78 -19
23 25 -40 16 -63 -12 42 45 -22 20 44 -23 78 -50 17
-67 14 -9 -58 38 -78 2 99 -87 -92 -34 -29 -7 -31 11
65 -32 27 91 -46 -13 -71 37 24 -5 34 -92 6 15 -15
-49 23 -52 -9 59 -57 -78 -10 17 -27 44 -34 -62 22 -94
-45 -45 88 -12 -64 1 -60 -35 11 1 -10 52 5 52 -17
-91 61 90 22 82 -9 82 85 10 56 18 4 -18 -92 -46
31 98 47 -12 -60 20 54 -8 92 24 -71 -23 24 91 37
-12 98 -13 66 72 -14 88 51 75 5 40 -91 91 -94 26
0 60 -41 6 28 -54 97 56 40 -17 94 -92 -23 -3 -91
10 -26 78 -22 -55 73 -82 -49 -26 -63 -80 8 97 87 -27
80 17 90 22 6 45 23 91 16 -93 -38 -64 -75 35 61
21 -24 -38 92 -43 98 -14 35 39 -65 -20 65 65 19 -81
79 -32 62 -93 89 19 -83 -47 45 20 93 49 43 73 80
24 81 19 -15 48 -46 -23 -63 65 2 75 -16 1 -98 14
-40 -68 -89 -10 90 29 3 -15 58 86 -85 36 -55 31 -79"

m2="-93 50 -61 52 55 23 -67 65 -49 -45 -91 31 -12 0 10 80 21 79 24 -40
-92 -27 2 -97 77 25 14 -32 23 -45 61 98 98 60 -26 17 -24 -32 81 -68
29 85 -44 57 42 -40 -9 27 -52 88 90 47 -13 -41 78 90 -38 62 19 -89
-45 11 -62 -39 10 16 -58 91 -9 -12 22 -12 66 6 -22 22 92 -93 -15 -10
-55 -76 47 -76 -98 -63 38 -46 59 -64 82 -60 72 28 -55 6 -43 89 48 90
-87 -3 -77 62 -22 -12 -78 -13 -57 1 -9 20 -14 -54 73 45 98 19 -46 29
-36 23 33 24 15 42 2 -71 -78 -60 82 54 88 97 -82 23 -14 -83 -23 3
39 68 6 69 -48 45 99 37 -10 -35 85 -8 51 56 -49 91 35 -47 -63 -15
-88 58 -7 -74 26 -22 -87 24 17 11 10 92 75 40 -26 16 39 45 65 58
71 -5 55 89 33 20 -92 -5 -27 1 56 24 5 -17 -63 -93 -65 20 2 86
7 34 -45 -76 -7 44 -34 34 44 -10 18 -71 40 94 -80 -38 -20 93 75 -85
-69 7 99 1 29 -23 -29 -92 -34 52 4 -23 -91 -92 8 -64 65 49 -16 36
52 -29 2 -46 -34 78 -7 6 -62 5 -18 24 91 -23 97 -75 65 43 1 -55
45 -49 20 -27 78 -50 -31 15 22 52 -92 91 -94 -3 87 35 19 73 -98 31
-22 41 89 -9 -19 17 11 -15 -94 -17 -46 37 26 -91 -27 61 -81 80 14 -79"

echo "$m1" > "$tmp1"
echo "$m2" > "$tmp2"

[[ "$m1" == "$(./matrix transpose $tmp2)" ]] && [[ "$m2" == "$(./matrix transpose $tmp1)" ]]
result "m1 == T(m2) and T(m1) == m2" 10

###############################################################################

unit "matrix transpose involution test"

for a in {1..3}
do
(( rows = RANDOM % 50 + 51 ))
(( cols = RANDOM % 50 + 51 ))

m1="$(generate $rows $cols 100)"
echo "$m1" > "$tmp1"

[[ "$m1" == "$(./matrix transpose $tmp1 | ./matrix transpose)" ]]
result "m$a == T(T(m$a))" 5
done

###############################################################################

unit "matrix mean test"

m1="-28 91 29 -5 12 83
-94 -16 41 -28 6 86
-44 83 -9 64 92 -70
41 22 66 29 55 49
6 52 4 17 -29 52
-8 -33 96 -73 -76 92
-32 94 45 4 43 -97
-57 36 86 90 35 75
46 8 4 -83 -94 -52
0 -6 -90 48 70 11
-33 -41 -76 68 30 -19
70 96 -85 -1 -9 -62
58 63 -4 22 -69 -25
-75 -65 -78 76 39 10
-99 -69 63 53 35 67
73 51 55 -26 -14 9
-90 -19 -19 -63 -96 23
-62 89 93 98 48 -21
-56 -86 24 45 -79 -65
-79 -60 87 -74 44 20
-38 50 -50 -38 -36 30
-69 -66 -23 42 55 -5
-62 98 47 -86 23 -85
-2 -55 -79 -41 -12 -31
-84 -10 46 16 -56 -26
70 -16 -17 99 24 -41
80 47 -59 -55 80 96
-54 43 24 -82 1 -46
25 -1 92 16 44 -21
62 58 79 -97 -21 -62
-46 -23 -68 59 -72 -6
-78 59 11 52 -96 -77
5 77 64 -29 -98 69
-68 69 74 32 -71 91
38 -75 25 -61 -29 73
40 25 29 93 93 -27
-1 -16 -14 48 99 -36
81 6 35 -90 4 -57
80 84 63 -10 80 -99
96 -5 -81 11 37 -46"

m2="-10 16 13 4 2 -4"



generate 5 10 z > "$tmp1"
[[ "$(generate 1 10 z)" == "$(./matrix mean < $tmp1)" ]]
result "zero matrix" 2

generate 5 10 o > "$tmp1"
[[ "$(generate 1 10 o)" == "$(./matrix mean $tmp1)" ]]
result "ones matrix" 5

generate 5 10 d > "$tmp1"
[[ "$(generate 1 10 z)" == "$(./matrix mean $tmp1)" ]]
result "identity matrix" 5

echo "$m1" > "$tmp1"
[[ "$m2" == "$(./matrix mean $tmp1)" ]]
result "hardcoded matrix" 15

###############################################################################

unit "matrix add test"

bigz="$(generate 30 20 z)"
echo "$bigz" > "$tmp1"
[[ "$bigz" == "$(./matrix add $tmp1 $tmp1)" ]]
result "0 + 0 == 0" 2

bigr="$(generate 30 20 100)"
echo "$bigr" > "$tmp2"
[[ "$bigr" == "$(./matrix add $tmp2 $tmp1)" ]]
result "X + 0 == X" 5

[[ "$bigr" == "$(./matrix add $tmp1 $tmp2)" ]]
result "0 + X == X" 5

m1="$(generate 10 10 100)"
m2="$(generate 10 10 100)"
echo "$m1" > "$tmp1"