Skip to content

Commit 2ab43b1

Browse files
authored
Use namespace data import in mnist example (#645)
1 parent 422090a commit 2ab43b1

File tree

1 file changed

+14
-12
lines changed
  • apps/typegpu-docs/src/content/examples/algorithms/mnist-inference

1 file changed

+14
-12
lines changed

apps/typegpu-docs/src/content/examples/algorithms/mnist-inference/index.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tgpu, { type TgpuBuffer, type Storage } from 'typegpu';
2-
import { type F32, type TgpuArray, arrayOf, f32 } from 'typegpu/data';
2+
import * as d from 'typegpu/data';
33

44
const SIZE = 28;
55

@@ -39,12 +39,12 @@ const layerShader = `
3939
`;
4040

4141
const ReadonlyFloats = {
42-
storage: (n: number) => arrayOf(f32, n),
42+
storage: (n: number) => d.arrayOf(d.f32, n),
4343
access: 'readonly',
4444
} as const;
4545

4646
const MutableFloats = {
47-
storage: (n: number) => arrayOf(f32, n),
47+
storage: (n: number) => d.arrayOf(d.f32, n),
4848
access: 'mutable',
4949
} as const;
5050

@@ -73,19 +73,19 @@ const pipeline = device.createComputePipeline({
7373

7474
interface LayerData {
7575
shape: readonly [number] | readonly [number, number];
76-
buffer: TgpuBuffer<TgpuArray<F32>> & Storage;
76+
buffer: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
7777
}
7878

7979
interface Layer {
80-
weights: TgpuBuffer<TgpuArray<F32>> & Storage;
81-
biases: TgpuBuffer<TgpuArray<F32>> & Storage;
82-
state: TgpuBuffer<TgpuArray<F32>> & Storage;
80+
weights: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
81+
biases: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
82+
state: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
8383
}
8484

8585
interface Network {
8686
layers: Layer[];
87-
input: TgpuBuffer<TgpuArray<F32>> & Storage;
88-
output: TgpuBuffer<TgpuArray<F32>> & Storage;
87+
input: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
88+
output: TgpuBuffer<d.TgpuArray<d.F32>> & Storage;
8989

9090
inference(data: number[]): Promise<number[]>;
9191
}
@@ -107,12 +107,14 @@ function createNetwork(layers: [LayerData, LayerData][]): Network {
107107
return {
108108
weights: weights.buffer,
109109
biases: biases.buffer,
110-
state: root.createBuffer(arrayOf(f32, biases.shape[0])).$usage('storage'),
110+
state: root
111+
.createBuffer(d.arrayOf(d.f32, biases.shape[0]))
112+
.$usage('storage'),
111113
};
112114
});
113115

114116
const input = root
115-
.createBuffer(arrayOf(f32, layers[0][0].shape[0]))
117+
.createBuffer(d.arrayOf(d.f32, layers[0][0].shape[0]))
116118
.$usage('storage');
117119
const output = buffers[buffers.length - 1].state;
118120

@@ -202,7 +204,7 @@ function getLayerData(layer: ArrayBuffer): LayerData {
202204
}
203205

204206
const buffer = root
205-
.createBuffer(arrayOf(f32, data.length), [...data])
207+
.createBuffer(d.arrayOf(d.f32, data.length), [...data])
206208
.$usage('storage');
207209

208210
return {

0 commit comments

Comments
 (0)