MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / setPixels

Method setPixels

assets/main.js:1231–1250  ·  view source on GitHub ↗
(pixels)

Source from the content-addressed store, hash-verified

1229 }
1230
1231 setPixels(pixels) {
1232 if (!pixels || typeof pixels.length !== "number") {
1233 throw new Error("Ungültige Pixelwerte für den Zeichenblock.");
1234 }
1235 if (pixels.length !== this.values.length) {
1236 throw new Error(
1237 `Erwartete ${this.values.length} Pixel, erhielt aber ${pixels.length}.`,
1238 );
1239 }
1240 for (let i = 0; i < this.values.length; i += 1) {
1241 const value = clamp(Number(pixels[i]) || 0, 0, 1);
1242 if (this.values[i] !== value) {
1243 this.values[i] = value;
1244 this.updateCellVisual(i);
1245 }
1246 }
1247 if (typeof this.onChange === "function") {
1248 this.onChange();
1249 }
1250 }
1251
1252 clear() {
1253 this.values.fill(0);

Callers 1

setupMnistSampleButtonsFunction · 0.80

Calls 2

updateCellVisualMethod · 0.95
clampFunction · 0.85

Tested by

no test coverage detected