Skip to content

Commit fe5c711

Browse files
tianyizheng02poyea
andauthored
Rewrite parts of Vector and Matrix (#5362)
* Rewrite parts of Vector and Matrix methods * Refactor determinant method and add unit tests Refactor determinant method to create separate minor and cofactor methods. Add respective unit tests for new methods. Rename methods using snake case to follow Python naming conventions. * Reorganize Vector and Matrix methods * Update linear_algebra/README.md Co-authored-by: John Law <[email protected]> * Fix punctuation and wording * Apply suggestions from code review Co-authored-by: John Law <[email protected]> Co-authored-by: John Law <[email protected]>
1 parent 8285913 commit fe5c711

File tree

4 files changed

+295
-225
lines changed

4 files changed

+295
-225
lines changed

knapsack/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The knapsack problem has been studied for more than a century, with early works
1717
## Documentation
1818

1919
This module uses docstrings to enable the use of Python's in-built `help(...)` function.
20-
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
20+
For instance, try `help(Vector)`, `help(unit_basis_vector)`, and `help(CLASSNAME.METHODNAME)`.
2121

2222
---
2323

linear_algebra/README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,56 @@ This module contains classes and functions for doing linear algebra.
1010
-
1111
- This class represents a vector of arbitrary size and related operations.
1212

13-
**Overview about the methods:**
13+
**Overview of the methods:**
1414

15-
- constructor(components : list) : init the vector
16-
- set(components : list) : changes the vector components.
15+
- constructor(components) : init the vector
16+
- set(components) : changes the vector components.
1717
- \_\_str\_\_() : toString method
18-
- component(i : int): gets the i-th component (start by 0)
18+
- component(i): gets the i-th component (0-indexed)
1919
- \_\_len\_\_() : gets the size / length of the vector (number of components)
20-
- euclidLength() : returns the eulidean length of the vector.
20+
- euclidean_length() : returns the eulidean length of the vector
2121
- operator + : vector addition
2222
- operator - : vector subtraction
2323
- operator * : scalar multiplication and dot product
24-
- copy() : copies this vector and returns it.
25-
- changeComponent(pos,value) : changes the specified component.
24+
- copy() : copies this vector and returns it
25+
- change_component(pos,value) : changes the specified component
2626

27-
- function zeroVector(dimension)
27+
- function zero_vector(dimension)
2828
- returns a zero vector of 'dimension'
29-
- function unitBasisVector(dimension,pos)
30-
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
31-
- function axpy(scalar,vector1,vector2)
29+
- function unit_basis_vector(dimension, pos)
30+
- returns a unit basis vector with a one at index 'pos' (0-indexed)
31+
- function axpy(scalar, vector1, vector2)
3232
- computes the axpy operation
33-
- function randomVector(N,a,b)
34-
- returns a random vector of size N, with random integer components between 'a' and 'b'.
33+
- function random_vector(N, a, b)
34+
- returns a random vector of size N, with random integer components between 'a' and 'b' inclusive
3535

3636
### class Matrix
3737
-
3838
- This class represents a matrix of arbitrary size and operations on it.
3939

40-
**Overview about the methods:**
40+
**Overview of the methods:**
4141

4242
- \_\_str\_\_() : returns a string representation
4343
- operator * : implements the matrix vector multiplication
4444
implements the matrix-scalar multiplication.
45-
- changeComponent(x,y,value) : changes the specified component.
46-
- component(x,y) : returns the specified component.
45+
- change_component(x, y, value) : changes the specified component.
46+
- component(x, y) : returns the specified component.
4747
- width() : returns the width of the matrix
4848
- height() : returns the height of the matrix
49-
- determinate() : returns the determinate of the matrix if it is square
49+
- determinant() : returns the determinant of the matrix if it is square
5050
- operator + : implements the matrix-addition.
51-
- operator - _ implements the matrix-subtraction
51+
- operator - : implements the matrix-subtraction
5252

53-
- function squareZeroMatrix(N)
53+
- function square_zero_matrix(N)
5454
- returns a square zero-matrix of dimension NxN
55-
- function randomMatrix(W,H,a,b)
56-
- returns a random matrix WxH with integer components between 'a' and 'b'
55+
- function random_matrix(W, H, a, b)
56+
- returns a random matrix WxH with integer components between 'a' and 'b' inclusive
5757
---
5858

5959
## Documentation
6060

6161
This module uses docstrings to enable the use of Python's in-built `help(...)` function.
62-
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
62+
For instance, try `help(Vector)`, `help(unit_basis_vector)`, and `help(CLASSNAME.METHODNAME)`.
6363

6464
---
6565

0 commit comments

Comments
 (0)