Skip to content

Commit c1b7f84

Browse files
committed
docs: simplify Extending Libraries to short overview with invitation
1 parent 5027237 commit c1b7f84

4 files changed

Lines changed: 127 additions & 266 deletions

File tree

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,25 @@
11
# Extending Libraries
22

3-
NumSharp's core functionality can be extended with additional packages that integrate with platform-specific features or external libraries.
3+
NumSharp is designed to integrate with the broader .NET ecosystem. Extension packages bridge NumSharp arrays with platform-specific features and external libraries.
44

5-
---
5+
## Official Extensions
66

7-
## Available Extensions
7+
| Package | Purpose |
8+
|---------|---------|
9+
| [NumSharp.Bitmap](bitmap.md) | Image ↔ NDArray conversion via `System.Drawing` |
810

9-
| Package | Description | Platform |
10-
|---------|-------------|----------|
11-
| [NumSharp.Bitmap](bitmap.md) | Convert between `System.Drawing.Bitmap` and `NDArray` | Windows |
11+
## Build Your Own
1212

13-
---
14-
15-
## NumSharp.Bitmap
16-
17-
Seamless image-to-array conversion for image processing and ML workflows.
18-
19-
```csharp
20-
using System.Drawing;
21-
using NumSharp;
22-
23-
// Image → Array
24-
var bitmap = new Bitmap("photo.jpg");
25-
var pixels = bitmap.ToNDArray(); // (1, height, width, channels)
26-
27-
// Process pixels with NumSharp operations...
28-
29-
// Array → Image
30-
var result = processedPixels.ToBitmap();
31-
result.Save("output.jpg");
32-
```
33-
34-
**Key Features:**
35-
- Zero-copy mode for performance-critical code
36-
- Supports 24bpp and 32bpp images
37-
- Alpha channel handling
38-
- Round-trip support (load → process → save)
39-
40-
[Full documentation →](bitmap.md)
41-
42-
---
43-
44-
## Installing Extensions
45-
46-
Extensions are separate NuGet packages:
47-
48-
```bash
49-
# Core library (always required)
50-
dotnet add package NumSharp
51-
52-
# Extensions (optional, add as needed)
53-
dotnet add package NumSharp.Bitmap
54-
```
55-
56-
---
57-
58-
## Creating Your Own Extensions
59-
60-
NumSharp is designed to be extensible. The key integration points:
61-
62-
### Working with NDArray Memory
13+
NumSharp exposes low-level memory access for integration with native libraries, GPU frameworks, or domain-specific formats:
6314

6415
```csharp
65-
// Get raw pointer to contiguous data
66-
unsafe
67-
{
68-
byte* ptr = (byte*)ndarray.Unsafe.Address;
69-
// Use with P/Invoke, native libraries, etc.
70-
}
71-
```
16+
// Access raw memory for interop
17+
byte* ptr = (byte*)ndarray.Unsafe.Address;
7218

73-
### Creating NDArray from External Memory
74-
75-
```csharp
76-
// Wrap existing unmanaged memory as NDArray
77-
unsafe
78-
{
79-
var slice = new ArraySlice<byte>(
80-
new UnmanagedMemoryBlock<byte>(ptr, length, disposeCallback)
81-
);
82-
var nd = new NDArray(slice);
83-
}
19+
// Wrap external memory as NDArray
20+
var nd = new NDArray(new ArraySlice<byte>(
21+
new UnmanagedMemoryBlock<byte>(ptr, length, onDispose)
22+
));
8423
```
8524

86-
### Extension Method Pattern
87-
88-
Follow the NumSharp.Bitmap pattern for consistent API:
89-
90-
```csharp
91-
public static class YourExtensions
92-
{
93-
public static NDArray ToNDArray(this YourType source, ...)
94-
{
95-
// Convert to NDArray
96-
}
97-
98-
public static YourType ToYourType(this NDArray nd, ...)
99-
{
100-
// Convert from NDArray
101-
}
102-
}
103-
```
25+
Have an extension to share? [Open a PR](https://github.com/SciSharp/NumSharp) to add it to this list.

docs/website/docs/extensions/index.html

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -87,94 +87,33 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
8787
<article data-uid="">
8888
<h1 id="extending-libraries">Extending Libraries</h1>
8989

90-
<p>NumSharp's core functionality can be extended with additional packages that integrate with platform-specific features or external libraries.</p>
91-
<hr>
92-
<h2 id="available-extensions">Available Extensions</h2>
90+
<p>NumSharp is designed to integrate with the broader .NET ecosystem. Extension packages bridge NumSharp arrays with platform-specific features and external libraries.</p>
91+
<h2 id="official-extensions">Official Extensions</h2>
9392
<table>
9493
<thead>
9594
<tr>
9695
<th>Package</th>
97-
<th>Description</th>
98-
<th>Platform</th>
96+
<th>Purpose</th>
9997
</tr>
10098
</thead>
10199
<tbody>
102100
<tr>
103101
<td><a href="bitmap.html">NumSharp.Bitmap</a></td>
104-
<td>Convert between <code>System.Drawing.Bitmap</code> and <code>NDArray</code></td>
105-
<td>Windows</td>
102+
<td>Image ↔ NDArray conversion via <code>System.Drawing</code></td>
106103
</tr>
107104
</tbody>
108105
</table>
109-
<hr>
110-
<h2 id="numsharpbitmap">NumSharp.Bitmap</h2>
111-
<p>Seamless image-to-array conversion for image processing and ML workflows.</p>
112-
<pre><code class="lang-csharp">using System.Drawing;
113-
using NumSharp;
114-
115-
// Image → Array
116-
var bitmap = new Bitmap(&quot;photo.jpg&quot;);
117-
var pixels = bitmap.ToNDArray(); // (1, height, width, channels)
118-
119-
// Process pixels with NumSharp operations...
120-
121-
// Array → Image
122-
var result = processedPixels.ToBitmap();
123-
result.Save(&quot;output.jpg&quot;);
124-
</code></pre>
125-
<p><strong>Key Features:</strong></p>
126-
<ul>
127-
<li>Zero-copy mode for performance-critical code</li>
128-
<li>Supports 24bpp and 32bpp images</li>
129-
<li>Alpha channel handling</li>
130-
<li>Round-trip support (load → process → save)</li>
131-
</ul>
132-
<p><a href="bitmap.html">Full documentation →</a></p>
133-
<hr>
134-
<h2 id="installing-extensions">Installing Extensions</h2>
135-
<p>Extensions are separate NuGet packages:</p>
136-
<pre><code class="lang-bash"># Core library (always required)
137-
dotnet add package NumSharp
138-
139-
# Extensions (optional, add as needed)
140-
dotnet add package NumSharp.Bitmap
141-
</code></pre>
142-
<hr>
143-
<h2 id="creating-your-own-extensions">Creating Your Own Extensions</h2>
144-
<p>NumSharp is designed to be extensible. The key integration points:</p>
145-
<h3 id="working-with-ndarray-memory">Working with NDArray Memory</h3>
146-
<pre><code class="lang-csharp">// Get raw pointer to contiguous data
147-
unsafe
148-
{
149-
byte* ptr = (byte*)ndarray.Unsafe.Address;
150-
// Use with P/Invoke, native libraries, etc.
151-
}
152-
</code></pre>
153-
<h3 id="creating-ndarray-from-external-memory">Creating NDArray from External Memory</h3>
154-
<pre><code class="lang-csharp">// Wrap existing unmanaged memory as NDArray
155-
unsafe
156-
{
157-
var slice = new ArraySlice&lt;byte&gt;(
158-
new UnmanagedMemoryBlock&lt;byte&gt;(ptr, length, disposeCallback)
159-
);
160-
var nd = new NDArray(slice);
161-
}
162-
</code></pre>
163-
<h3 id="extension-method-pattern">Extension Method Pattern</h3>
164-
<p>Follow the NumSharp.Bitmap pattern for consistent API:</p>
165-
<pre><code class="lang-csharp">public static class YourExtensions
166-
{
167-
public static NDArray ToNDArray(this YourType source, ...)
168-
{
169-
// Convert to NDArray
170-
}
171-
172-
public static YourType ToYourType(this NDArray nd, ...)
173-
{
174-
// Convert from NDArray
175-
}
176-
}
106+
<h2 id="build-your-own">Build Your Own</h2>
107+
<p>NumSharp exposes low-level memory access for integration with native libraries, GPU frameworks, or domain-specific formats:</p>
108+
<pre><code class="lang-csharp">// Access raw memory for interop
109+
byte* ptr = (byte*)ndarray.Unsafe.Address;
110+
111+
// Wrap external memory as NDArray
112+
var nd = new NDArray(new ArraySlice&lt;byte&gt;(
113+
new UnmanagedMemoryBlock&lt;byte&gt;(ptr, length, onDispose)
114+
));
177115
</code></pre>
116+
<p>Have an extension to share? <a href="https://github.com/SciSharp/NumSharp">Open a PR</a> to add it to this list.</p>
178117

179118
</article>
180119

docs/website/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@
477477
"docs/extensions/index.html": {
478478
"href": "docs/extensions/index.html",
479479
"title": "Extending Libraries | NumSharp Documentation",
480-
"summary": "Extending Libraries NumSharp's core functionality can be extended with additional packages that integrate with platform-specific features or external libraries. Available Extensions Package Description Platform NumSharp.Bitmap Convert between System.Drawing.Bitmap and NDArray Windows NumSharp.Bitmap Seamless image-to-array conversion for image processing and ML workflows. using System.Drawing; using NumSharp; // Image → Array var bitmap = new Bitmap(\"photo.jpg\"); var pixels = bitmap.ToNDArray(); // (1, height, width, channels) // Process pixels with NumSharp operations... // Array → Image var result = processedPixels.ToBitmap(); result.Save(\"output.jpg\"); Key Features: Zero-copy mode for performance-critical code Supports 24bpp and 32bpp images Alpha channel handling Round-trip support (load → process → save) Full documentation → Installing Extensions Extensions are separate NuGet packages: # Core library (always required) dotnet add package NumSharp # Extensions (optional, add as needed) dotnet add package NumSharp.Bitmap Creating Your Own Extensions NumSharp is designed to be extensible. The key integration points: Working with NDArray Memory // Get raw pointer to contiguous data unsafe { byte* ptr = (byte*)ndarray.Unsafe.Address; // Use with P/Invoke, native libraries, etc. } Creating NDArray from External Memory // Wrap existing unmanaged memory as NDArray unsafe { var slice = new ArraySlice<byte>( new UnmanagedMemoryBlock<byte>(ptr, length, disposeCallback) ); var nd = new NDArray(slice); } Extension Method Pattern Follow the NumSharp.Bitmap pattern for consistent API: public static class YourExtensions { public static NDArray ToNDArray(this YourType source, ...) { // Convert to NDArray } public static YourType ToYourType(this NDArray nd, ...) { // Convert from NDArray } }"
480+
"summary": "Extending Libraries NumSharp is designed to integrate with the broader .NET ecosystem. Extension packages bridge NumSharp arrays with platform-specific features and external libraries. Official Extensions Package Purpose NumSharp.Bitmap Image ↔ NDArray conversion via System.Drawing Build Your Own NumSharp exposes low-level memory access for integration with native libraries, GPU frameworks, or domain-specific formats: // Access raw memory for interop byte* ptr = (byte*)ndarray.Unsafe.Address; // Wrap external memory as NDArray var nd = new NDArray(new ArraySlice<byte>( new UnmanagedMemoryBlock<byte>(ptr, length, onDispose) )); Have an extension to share? Open a PR to add it to this list."
481481
},
482482
"docs/intro.html": {
483483
"href": "docs/intro.html",

0 commit comments

Comments
 (0)