Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add further customizations to the documentation site #159

Merged
merged 7 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<a href="https://mathematics.hamlettanyavong.com">
<img src="https://raw.githubusercontent.com/HamletTanyavong/Mathematics.NET/main/docs/images/logo/mathematics.net.svg" width="128" height="128" alt="Mathematics.NET Logo">
<img src="https://raw.githubusercontent.com/HamletTanyavong/Mathematics.NET/main/docs/static/img/mathematics.net.svg" width="128" height="128" alt="Mathematics.NET Logo">
</a>
<h1>Mathematics.NET</h1>
<p>Mathematics.NET is a C# class library that provides tools for solving mathematical problems.</p>
Expand Down
3 changes: 2 additions & 1 deletion docs/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
"useTabs": false,
"plugins": ["prettier-plugin-tailwindcss"]
}
4 changes: 3 additions & 1 deletion docs/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
hamlettanyavong:
name: Hamlet Tanyavong
title: Physicist, Mathematician, & .NET Developer
title: Mathematics.NET maintainer
url: https://hamlettanyavong.com
image_url: https://github.com/hamlettanyavong.png
page: true
description: A physicist, mathematician, and .NET developer who loves to learn and share knowledge with others.
socials:
bluesky: hamlettanyavong.com
github: hamlettanyavong
linkedin: hamlettanyavong
21 changes: 21 additions & 0 deletions docs/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "src/components",
"utils": "src/lib/utils",
"ui": "src/components/ui",
"lib": "src/lib",
"hooks": "src/hooks"
},
"iconLibrary": "lucide"
}
2 changes: 1 addition & 1 deletion docs/docs/autodiff/_category_.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"position": 3,
"link": {
"type": "generated-index",
"description": "Automatic Differentiation in Mathematics.NET."
"description": "Automatic differentiation in Mathematics.NET."
}
}
114 changes: 67 additions & 47 deletions docs/docs/gpu/opencl.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Here is an example of matrix multiplication on an [NVIDIA GeForce RTX 2080 Ti](h
### Setup

One way to set up OpenCL for Mathematics.NET is with the following:

```csharp
using CommunityToolkit.HighPerformance;
using Mathematics.NET.Core;
Expand Down Expand Up @@ -47,44 +48,52 @@ builder.Logging.AddFilter(logLevel => logLevel >= LogLevel.Warning);
// Build the application.
var app = builder.Build();
```
We can also instantiate [OpenCLService](xref:Mathematics.NET.GPU.OpenCL.OpenCLService) directly, but for this example, we will use the former. To get the service, use

We can also instantiate [OpenCLService] directly, but for this example, we will use the former. To get the service, use

```csharp
// Get the OpenCL service.
using var openCL = app.Services.GetRequiredService<IComputeService>();
```

### Matrix Multiplication Without Padding

Suppose we want to compute $ M=AB $, where

$$
A = \begin{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\
16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 \\
32 & 33 & 34 & 35 & 36 & 37 & 38 & 39 & 40 & 41 & 42 & 43 & 44 & 45 & 46 & 47 \\
48 & 49 & 50 & 51 & 52 & 53 & 54 & 55 & 56 & 57 & 58 & 59 & 60 & 61 & 62 & 63
\end{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\
16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 \\
32 & 33 & 34 & 35 & 36 & 37 & 38 & 39 & 40 & 41 & 42 & 43 & 44 & 45 & 46 & 47 \\
48 & 49 & 50 & 51 & 52 & 53 & 54 & 55 & 56 & 57 & 58 & 59 & 60 & 61 & 62 & 63
\end{pmatrix}
$$

and

$$
B = \begin{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\
16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 \\
24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 \\
32 & 33 & 34 & 35 & 36 & 37 & 38 & 39 \\
40 & 41 & 42 & 43 & 44 & 45 & 46 & 47 \\
48 & 49 & 50 & 51 & 52 & 53 & 54 & 55 \\
56 & 57 & 58 & 59 & 60 & 61 & 62 & 63 \\
64 & 65 & 66 & 67 & 68 & 69 & 70 & 71 \\
72 & 73 & 74 & 75 & 76 & 77 & 78 & 79 \\
80 & 81 & 82 & 83 & 84 & 85 & 86 & 87 \\
88 & 89 & 90 & 91 & 92 & 93 & 94 & 95 \\
96 & 97 & 98 & 99 & 100 & 101 & 102 & 103 \\
104 & 105 & 106 & 107 & 108 & 109 & 110 & 111 \\
112 & 113 & 114 & 115 & 116 & 117 & 118 & 119 \\
120 & 121 & 122 & 123 & 124 & 125 & 126 & 127
\end{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\
16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 \\
24 & 25 & 26 & 27 & 28 & 29 & 30 & 31 \\
32 & 33 & 34 & 35 & 36 & 37 & 38 & 39 \\
40 & 41 & 42 & 43 & 44 & 45 & 46 & 47 \\
48 & 49 & 50 & 51 & 52 & 53 & 54 & 55 \\
56 & 57 & 58 & 59 & 60 & 61 & 62 & 63 \\
64 & 65 & 66 & 67 & 68 & 69 & 70 & 71 \\
72 & 73 & 74 & 75 & 76 & 77 & 78 & 79 \\
80 & 81 & 82 & 83 & 84 & 85 & 86 & 87 \\
88 & 89 & 90 & 91 & 92 & 93 & 94 & 95 \\
96 & 97 & 98 & 99 & 100 & 101 & 102 & 103 \\
104 & 105 & 106 & 107 & 108 & 109 & 110 & 111 \\
112 & 113 & 114 & 115 & 116 & 117 & 118 & 119 \\
120 & 121 & 122 & 123 & 124 & 125 & 126 & 127
\end{pmatrix}
$$
We can use the method [MatMul](xref:Mathematics.NET.GPU.OpenCL.OpenCLService.MatMul*) to perform matrix multiplication on the GPU.

We can use the method [MatMul] to perform matrix multiplication on the GPU.

```csharp
// Create and fill the left matrix.
Span2D<Real> matA = new Real[4, 16];
Expand All @@ -110,61 +119,72 @@ for (int i = 0; i < 16; i++)
var result = openCL.MatMul(openCL.Devices[0], new(4, 8), new(4, 8), matA, matB);
Console.WriteLine(result.ToDisplayString());
```

This gives us the following result:

$$
M = \begin{pmatrix}
9920 & 10040 & 10160 & 10280 & 10400 & 10520 & 10640 & 10760 \\
25280 & 25656 & 26032 & 26408 & 26784 & 27160 & 27536 & 27912 \\
40640 & 41272 & 41904 & 42536 & 43168 & 43800 & 44432 & 45064 \\
56000 & 56888 & 57776 & 58664 & 59552 & 60440 & 61328 & 62216
\end{pmatrix}
9920 & 10040 & 10160 & 10280 & 10400 & 10520 & 10640 & 10760 \\
25280 & 25656 & 26032 & 26408 & 26784 & 27160 & 27536 & 27912 \\
40640 & 41272 & 41904 & 42536 & 43168 & 43800 & 44432 & 45064 \\
56000 & 56888 & 57776 & 58664 & 59552 & 60440 & 61328 & 62216
\end{pmatrix}
$$

### Matrix Multiplication with Padding

Sometimes, the matrices we want to multiply my not have ideal dimensions; more specifically, the dimensions of the matrices are such that they cannot be evenly divided by our local work size. In such a case, we have to pad our matrices to get them to the proper dimensions. Now, suppose

$$
A = \begin{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 \\
7 & 8 & 9 & 10 & 11 & 12 & 13 \\
14 & 15 & 16 & 17 & 18 & 19 & 20
\end{pmatrix}
0 & 1 & 2 & 3 & 4 & 5 & 6 \\
7 & 8 & 9 & 10 & 11 & 12 & 13 \\
14 & 15 & 16 & 17 & 18 & 19 & 20 \\
\end{pmatrix}
$$

and

$$
B = \begin{pmatrix}
0 & 1 & 2 & 3 & 4 \\
5 & 6 & 7 & 8 & 9 \\
10 & 11 & 12 & 13 & 14 \\
15 & 16 & 17 & 18 & 19 \\
20 & 21 & 22 & 23 & 24 \\
25 & 26 & 27 & 28 & 29 \\
30 & 31 & 32 & 33 & 34
\end{pmatrix}
0 & 1 & 2 & 3 & 4 \\
5 & 6 & 7 & 8 & 9 \\
10 & 11 & 12 & 13 & 14 \\
15 & 16 & 17 & 18 & 19 \\
20 & 21 & 22 & 23 & 24 \\
25 & 26 & 27 & 28 & 29 \\
30 & 31 & 32 & 33 & 34
\end{pmatrix}
$$
We can use [Pad](xref:Mathematics.NET.LinearAlgebra.LinAlgExtensions.Pad``1(CommunityToolkit.HighPerformance.Span2D{``0},System.Int32,System.Int32)) to add zeros to the right and bottom of each of these matrices so that $ A $ and $ B $ have dimensions `4 x 8` and `8 x 8`, respectively.

We can use [Pad] to add zeros to the right and bottom of each of these matrices so that $ A $ and $ B $ have dimensions `4 x 8` and `8 x 8`, respectively.

```csharp
var pMatA = matA.Pad(4, 8);
var pMatB = matB.Pad(8, 8);
```

Then using the same method above, we can perform matrix multiplication with the two matrices.

```csharp
var result = openCL.MatMul(openCL.Devices[0], new(4, 8), new(4, 4), pMatA, pMatB);
Console.WriteLine(result.Slice(0, 0, 3, 5).ToDisplayString());
```

Here, we chose a local work size of `{ 4, 4 }`, which is a multiple of our global work size.

:::note

For performance reasons, matrices should only be padded once. When finished, use [Slice](xref:System.Span`1.Slice*), or the 2D version from [CommunityToolkit](https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.highperformance.span2d-1.slice), to get the unpadded result.
For performance reasons, matrices should only be padded once. When finished, use [Slice], or the 2D version from [CommunityToolkit](https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.highperformance.span2d-1.slice), to get the unpadded result.

:::

With that, we now have our result:

$$
M = \begin{pmatrix}
455 & 476 & 497 & 518 & 539 \\
1190 & 1260 & 1330 & 1400 & 1470 \\
1925 & 2044 & 2163 & 2282 & 2401
\end{pmatrix}
455 & 476 & 497 & 518 & 539 \\
1190 & 1260 & 1330 & 1400 & 1470 \\
1925 & 2044 & 2163 & 2282 & 2401
\end{pmatrix}
$$
3 changes: 3 additions & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import tailwindPlugin from './plugins/tailwind-plugin.cjs';

// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)

Expand All @@ -26,6 +27,8 @@ const config: Config = {
locales: ['en']
},

plugins: [tailwindPlugin],

presets: [
[
'classic',
Expand Down
Loading
Loading