Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/fhdsl/AI_for_software into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
jhudsl-robot committed Jul 12, 2023
2 parents d20978e + d4a078e commit 54caf12
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions docs/04-refactoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Learning Objectives

- Describe how refactoring code involves optimization for maintainability, efficiency, and reuse
- Explain why refactoring code is important for developers in the longterm
- Explain why refactoring code is important for developers in the long-term
- Recognize the benefits and limitations of using AI tools to refactor code, as well as why AI tools are uniquely poised to be beneficial
- Implement prompt strategies that can be used to assist with refactoring code for correcting syntax, for adopting more consistent styling, for making code more concise, for making code easier to maintain, and for making code more efficient

Expand Down Expand Up @@ -547,7 +547,7 @@ proc.time() - start_time

```
## user system elapsed
## 11.986 0.003 11.988
## 14.389 0.000 14.398
```

:::{.query}
Expand Down Expand Up @@ -575,7 +575,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.745 0.504 0.832
## 0.670 0.392 0.698
```

The `outer()` function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The `rowSums()` function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index `i` in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.
Expand Down Expand Up @@ -603,7 +603,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.394 0.452 0.536
## 0.283 0.344 0.394
```

One optimized way to perform the same calculation is by using the `%*%` operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.
Expand Down
8 changes: 4 additions & 4 deletions docs/no_toc/04-refactoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Learning Objectives

- Describe how refactoring code involves optimization for maintainability, efficiency, and reuse
- Explain why refactoring code is important for developers in the longterm
- Explain why refactoring code is important for developers in the long-term
- Recognize the benefits and limitations of using AI tools to refactor code, as well as why AI tools are uniquely poised to be beneficial
- Implement prompt strategies that can be used to assist with refactoring code for correcting syntax, for adopting more consistent styling, for making code more concise, for making code easier to maintain, and for making code more efficient

Expand Down Expand Up @@ -547,7 +547,7 @@ proc.time() - start_time

```
## user system elapsed
## 231.734 0.076 231.807
## 233.008 0.055 233.087
```

:::{.query}
Expand Down Expand Up @@ -575,7 +575,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.770 0.263 0.878
## 0.551 0.348 0.701
```

The `outer()` function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The `rowSums()` function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index `i` in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.
Expand Down Expand Up @@ -603,7 +603,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.336 0.236 0.353
## 0.287 0.296 0.370
```

One optimized way to perform the same calculation is by using the `%*%` operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.
Expand Down
8 changes: 4 additions & 4 deletions docs/no_toc/refactoring-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1><span class="header-section-number">Chapter 4</span> Refactoring Code</h1>
<h2><span class="header-section-number">4.1</span> Learning Objectives</h2>
<ul>
<li>Describe how refactoring code involves optimization for maintainability, efficiency, and reuse</li>
<li>Explain why refactoring code is important for developers in the longterm</li>
<li>Explain why refactoring code is important for developers in the long-term</li>
<li>Recognize the benefits and limitations of using AI tools to refactor code, as well as why AI tools are uniquely poised to be beneficial</li>
<li>Implement prompt strategies that can be used to assist with refactoring code for correcting syntax, for adopting more consistent styling, for making code more concise, for making code easier to maintain, and for making code more efficient</li>
</ul>
Expand Down Expand Up @@ -746,7 +746,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb49-16"><a href="refactoring-code.html#cb49-16" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb49-17"><a href="refactoring-code.html#cb49-17" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 231.734 0.076 231.807</code></pre>
## 233.008 0.055 233.087</code></pre>
<div class="query">
<p>What is a faster, more optimized way of running the following R code?</p>
</div>
Expand All @@ -765,7 +765,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb51-12"><a href="refactoring-code.html#cb51-12" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb51-13"><a href="refactoring-code.html#cb51-13" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 0.770 0.263 0.878</code></pre>
## 0.551 0.348 0.701</code></pre>
<p>The <code>outer()</code> function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The <code>rowSums()</code> function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index <code>i</code> in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.</p>
</div>
<p>So much faster! We can look at another option by regenerating the response:</p>
Expand All @@ -784,7 +784,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb53-12"><a href="refactoring-code.html#cb53-12" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb53-13"><a href="refactoring-code.html#cb53-13" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 0.336 0.236 0.353</code></pre>
## 0.287 0.296 0.370</code></pre>
<p>One optimized way to perform the same calculation is by using the <code>%*%</code> operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.</p>
</div>
<p>While this second suggestion is faster, you will need to consider what aspects of the codebase are most important in each instance. For example, this code runs more quickly, but <a href="https://stat.ethz.ch/R-manual/R-patched/library/base/html/matmult.html">the <code>%*%</code> operator</a> might be unfamiliar to some R programmers. In cases where efficiency is less important, or the data are not large, you might consider maximizing readability.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/no_toc/search_index.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/refactoring-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1><span class="header-section-number">Chapter 4</span> Refactoring Code</h1>
<h2><span class="header-section-number">4.1</span> Learning Objectives</h2>
<ul>
<li>Describe how refactoring code involves optimization for maintainability, efficiency, and reuse</li>
<li>Explain why refactoring code is important for developers in the longterm</li>
<li>Explain why refactoring code is important for developers in the long-term</li>
<li>Recognize the benefits and limitations of using AI tools to refactor code, as well as why AI tools are uniquely poised to be beneficial</li>
<li>Implement prompt strategies that can be used to assist with refactoring code for correcting syntax, for adopting more consistent styling, for making code more concise, for making code easier to maintain, and for making code more efficient</li>
</ul>
Expand Down Expand Up @@ -746,7 +746,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb49-16"><a href="refactoring-code.html#cb49-16" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb49-17"><a href="refactoring-code.html#cb49-17" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 11.986 0.003 11.988</code></pre>
## 14.389 0.000 14.398</code></pre>
<div class="query">
<p>What is a faster, more optimized way of running the following R code?</p>
</div>
Expand All @@ -765,7 +765,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb51-12"><a href="refactoring-code.html#cb51-12" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb51-13"><a href="refactoring-code.html#cb51-13" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 0.745 0.504 0.832</code></pre>
## 0.670 0.392 0.698</code></pre>
<p>The <code>outer()</code> function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The <code>rowSums()</code> function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index <code>i</code> in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.</p>
</div>
<p>So much faster! We can look at another option by regenerating the response:</p>
Expand All @@ -784,7 +784,7 @@ <h2><span class="header-section-number">4.10</span> Code optimization</h2>
<span id="cb53-12"><a href="refactoring-code.html#cb53-12" aria-hidden="true" tabindex="-1"></a><span class="co"># End timer</span></span>
<span id="cb53-13"><a href="refactoring-code.html#cb53-13" aria-hidden="true" tabindex="-1"></a><span class="fu">proc.time</span>() <span class="sc">-</span> start_time</span></code></pre></div>
<pre><code>## user system elapsed
## 0.394 0.452 0.536</code></pre>
## 0.283 0.344 0.394</code></pre>
<p>One optimized way to perform the same calculation is by using the <code>%*%</code> operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.</p>
</div>
<p>While this second suggestion is faster, you will need to consider what aspects of the codebase are most important in each instance. For example, this code runs more quickly, but <a href="https://stat.ethz.ch/R-manual/R-patched/library/base/html/matmult.html">the <code>%*%</code> operator</a> might be unfamiliar to some R programmers. In cases where efficiency is less important, or the data are not large, you might consider maximizing readability.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/search_index.json

Large diffs are not rendered by default.

0 comments on commit 54caf12

Please sign in to comment.