Skip to content

Commit

Permalink
deploy: b3b532f
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Jan 3, 2025
1 parent 7c21442 commit 62a855c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
34 changes: 17 additions & 17 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,54 +217,54 @@ <h2 id="ranges"><a class="header" href="#ranges">Ranges</a></h2>
<p>Each element of a tensor can optionally give a <em>range</em> of index numbers, which is used by the compiler to determine the extent of each element.
This is useful when defining higher dimensional tensors, such as matrices. For example, to define a 2x3 matrix \( A \) with all elements set to <code>1.0</code>, we write:</p>
<pre><code>A_ij {
(0:2, 0:3) = 1.0,
(0:2, 0:3): 1.0,
}
</code></pre>
<p>Note the two subscript to indicate that this is a 2D tensor. The size of the
single element is given in the brackets, we have two ranges <code>0:2</code> and <code>0:3</code> that correspond to the two dimensions of the matrix.</p>
<p>Here is another example of a 4x2 matrix \( B \) with rows 0 to 2 set to <code>1.0</code> and rows 3 to 4 set to <code>2.0</code>:</p>
<pre><code>A_ij {
(0:2, 0:3) = 1.0,
(3:4, 0:3) = 2.0,
(0:2, 0:3): 1.0,
(3:4, 0:3): 2.0,
}
</code></pre>
<p>For specifying a single index, you can simply write the index number without the colon, for example to define a 3x3 identity matrix $I$:</p>
<pre><code>I_ij {
(0, 0) = 1.0,
(1, 1) = 1.0,
(2, 2) = 1.0,
(0, 0): 1.0,
(1, 1): 1.0,
(2, 2): 1.0,
}
</code></pre>
<p>Note that the compiler will automatically infer the size of the tensor from the ranges you provide, so you don't need to specify the size of the tensor explicitly.
Since the maximum index in the range is 2, the compiler will infer that the size of the tensor is 3x3.</p>
<p>Notice also that we have not defined all the elements of the matrix, only the non-zero elements. The compiler will assume that all other elements are zero.</p>
<p>Finally, you can also use the <code>..</code> operator to specify a <em>diagonal</em> range of indices. For example, to define a 3x3 matrix \( D \) with the diagonal elements set to <code>1.0</code>:</p>
<pre><code>D_ij {
(0..2, 0..2) = 1.0,
(0..2, 0..2): 1.0,
}
</code></pre>
<h2 id="sparse-and-diagonal-matrices"><a class="header" href="#sparse-and-diagonal-matrices">Sparse and diagonal matrices</a></h2>
<p>We can automatically define a sparse matrix \( B \) by simply specifying the non-zero elements:</p>
<pre><code>B_ij {
(0, 0) = 1.0,
(0, 1) = 2.0,
(1, 1) = 3.0,
(0, 0): 1.0,
(0, 1): 2.0,
(1, 1): 3.0,
}
</code></pre>
<p>The compiler will infer that this is a 2x2 matrix, and will automatically represent it as a sparse matrix.
We can force the compiler to use a dense representation by specifying the zeros explicitly:</p>
<pre><code>B_ij {
(0, 0) = 1.0,
(0, 1) = 2.0,
(1, 0) = 0.0,
(1, 1) = 3.0,
(0, 0): 1.0,
(0, 1): 2.0,
(1, 0): 0.0,
(1, 1): 3.0,
}
</code></pre>
<p>As well as specifying a sparse matrix, we can also define a diagonal matrix by specifying the diagonal elements:</p>
<pre><code>D_ij {
(0, 0) = 1.0,
(1, 1) = 2.0,
(2, 2) = 3.0,
(0, 0): 1.0,
(1, 1): 2.0,
(2, 2): 3.0,
}
</code></pre>
<p>The compiler will infer that this is a 3x3 matrix, and will automatically represent it as a diagonal matrix.</p>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions tensors.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,54 +184,54 @@ <h2 id="ranges"><a class="header" href="#ranges">Ranges</a></h2>
<p>Each element of a tensor can optionally give a <em>range</em> of index numbers, which is used by the compiler to determine the extent of each element.
This is useful when defining higher dimensional tensors, such as matrices. For example, to define a 2x3 matrix \( A \) with all elements set to <code>1.0</code>, we write:</p>
<pre><code>A_ij {
(0:2, 0:3) = 1.0,
(0:2, 0:3): 1.0,
}
</code></pre>
<p>Note the two subscript to indicate that this is a 2D tensor. The size of the
single element is given in the brackets, we have two ranges <code>0:2</code> and <code>0:3</code> that correspond to the two dimensions of the matrix.</p>
<p>Here is another example of a 4x2 matrix \( B \) with rows 0 to 2 set to <code>1.0</code> and rows 3 to 4 set to <code>2.0</code>:</p>
<pre><code>A_ij {
(0:2, 0:3) = 1.0,
(3:4, 0:3) = 2.0,
(0:2, 0:3): 1.0,
(3:4, 0:3): 2.0,
}
</code></pre>
<p>For specifying a single index, you can simply write the index number without the colon, for example to define a 3x3 identity matrix $I$:</p>
<pre><code>I_ij {
(0, 0) = 1.0,
(1, 1) = 1.0,
(2, 2) = 1.0,
(0, 0): 1.0,
(1, 1): 1.0,
(2, 2): 1.0,
}
</code></pre>
<p>Note that the compiler will automatically infer the size of the tensor from the ranges you provide, so you don't need to specify the size of the tensor explicitly.
Since the maximum index in the range is 2, the compiler will infer that the size of the tensor is 3x3.</p>
<p>Notice also that we have not defined all the elements of the matrix, only the non-zero elements. The compiler will assume that all other elements are zero.</p>
<p>Finally, you can also use the <code>..</code> operator to specify a <em>diagonal</em> range of indices. For example, to define a 3x3 matrix \( D \) with the diagonal elements set to <code>1.0</code>:</p>
<pre><code>D_ij {
(0..2, 0..2) = 1.0,
(0..2, 0..2): 1.0,
}
</code></pre>
<h2 id="sparse-and-diagonal-matrices"><a class="header" href="#sparse-and-diagonal-matrices">Sparse and diagonal matrices</a></h2>
<p>We can automatically define a sparse matrix \( B \) by simply specifying the non-zero elements:</p>
<pre><code>B_ij {
(0, 0) = 1.0,
(0, 1) = 2.0,
(1, 1) = 3.0,
(0, 0): 1.0,
(0, 1): 2.0,
(1, 1): 3.0,
}
</code></pre>
<p>The compiler will infer that this is a 2x2 matrix, and will automatically represent it as a sparse matrix.
We can force the compiler to use a dense representation by specifying the zeros explicitly:</p>
<pre><code>B_ij {
(0, 0) = 1.0,
(0, 1) = 2.0,
(1, 0) = 0.0,
(1, 1) = 3.0,
(0, 0): 1.0,
(0, 1): 2.0,
(1, 0): 0.0,
(1, 1): 3.0,
}
</code></pre>
<p>As well as specifying a sparse matrix, we can also define a diagonal matrix by specifying the diagonal elements:</p>
<pre><code>D_ij {
(0, 0) = 1.0,
(1, 1) = 2.0,
(2, 2) = 3.0,
(0, 0): 1.0,
(1, 1): 2.0,
(2, 2): 3.0,
}
</code></pre>
<p>The compiler will infer that this is a 3x3 matrix, and will automatically represent it as a diagonal matrix.</p>
Expand Down

0 comments on commit 62a855c

Please sign in to comment.