Skip to content

Commit 2e5c2a9

Browse files
committed
updating readme section titles
1 parent 1abb5c0 commit 2e5c2a9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Not too scary, right?
110110

111111
This is a basic exponentiation algorithm that lets us find the final answer in logN time, and other than the `let`s and `mut`s, this doesn't read very differently from Python. The `mut` is just us telling Rust that the `result` and `base` objects can be changed after they're initially declared: Python lets you do that to anything at any time, but in Rust, things are immutable after their creation unless you say otherwise!
112112

113-
### Adding Step 2 of the Python function
113+
### Extract and Transform
114114

115115
We're not going to touch the Rust helper function again from this point on: we're just going to process whatever data Python gives us into a format that our Rust-only function can use without complaining.
116116

@@ -124,21 +124,21 @@ Finally, we flatten the nested vectors in to a single, 1-d vector. This is very
124124

125125
The explicit use of iterators is a language feature taken from functional programming, and it is virtually always faster, often much faster, than a regular for loop in Rust. Note also that because we used `.into_iter()` instead of `.iter()`, we consume the original nested_vecs value: from this line onwards, nested_vecs no longer exists in our program!
126126

127-
### Adding Step 3 of the Python function
127+
### Matrix from Vec
128128

129129
Okay, that was a lot to take in, but it's all smooth sailing from here.
130130

131131
Now we're just creating a 2-d array using our newly flattened vector and the shape of the input matrix. We use the Array2 object's build-in-method to do this, but we handle the error case ourselves: if the dimensions of the vector don't match what we passed in, i.e. it can't be turned into a square matrix of size nxn, we return a Python ValueError, as before.
132132

133-
### Adding Step 4 of the Python function
133+
### Call Rust Function
134134

135135
Now that we have everything in the desired types, we just call our Rust matrix exponentiation function directly: no sweat!
136136

137-
### Adding Step 5 of the Python function
137+
### Transform Result
138138

139139
Now we're taking the matrix we got out and turning it back into a nested vector: we get the rows (which are an iterable), turn them into an iterator, turn each row into a separate vector, and then collect them into a vector of vectors. Done!
140140

141-
### Adding Step 6 of the Python function
141+
### Return Output
142142

143143
Finally, we take this output and return it: we wrap it in `Ok()` to signal to the Rust compiler that this is a desired output, not an error.
144144

0 commit comments

Comments
 (0)