Skip to content

Commit f6b75b2

Browse files
authored
Merge pull request #18 from ibelem/softmax-4-d-update-3
Playground - softmax() on N-D tensors - update 3
2 parents 35d328b + 5f98fef commit f6b75b2

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

app/[lang]/playground/editor-files-webnn.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ button {
978978
active: true,
979979
code: `let resultArray = null;
980980
let currentIndex = 0;
981-
let chunkSize = 512;
981+
let chunkSize = 256;
982982
983983
async function webnn() {
984984
// Compute softmax() on N-D tensors (N > 2)
@@ -1012,17 +1012,18 @@ function showChunk() {
10121012
if (!resultArray) return;
10131013
const end = Math.min(currentIndex + chunkSize, resultArray.length);
10141014
const chunk = Array.from(resultArray.slice(currentIndex, end));
1015-
output.textContent += (currentIndex === 0 ? "" : "\n") + chunk.join(', ');
1015+
output.textContent += (currentIndex === 0 ? "" : "") + chunk.join(', ');
1016+
10161017
currentIndex = end;
10171018
// Hide button if all data is shown
10181019
if (currentIndex >= resultArray.length) {
1019-
document.getElementById("showMoreBtn").style.display = "none";
1020+
document.getElementById("more").style.display = "none";
10201021
}
10211022
}
10221023
10231024
async function main() {
10241025
const output = document.querySelector("#output");
1025-
const btn = document.getElementById("showMoreBtn");
1026+
const btn = document.getElementById("more");
10261027
const chunkInput = document.getElementById("chunkInput");
10271028
chunkSize = parseInt(chunkInput.value, 10) || 256;
10281029
output.textContent = "Inferencing...";
@@ -1040,18 +1041,17 @@ async function main() {
10401041
}
10411042
}
10421043
1043-
document.getElementById("showMoreBtn").addEventListener("click", showChunk);
1044+
document.getElementById("more").addEventListener("click", showChunk);
10441045
document.getElementById("chunkInput").addEventListener("change", function () {
10451046
chunkSize = parseInt(this.value, 10) || 256;
10461047
currentIndex = 0;
10471048
document.querySelector("#output").textContent = "";
10481049
showChunk();
10491050
if (resultArray && resultArray.length > chunkSize) {
1050-
document.getElementById("showMoreBtn").style.display = "inline-block";
1051+
document.getElementById("more").style.display = "inline-block";
10511052
}
10521053
});
1053-
document.addEventListener("DOMContentLoaded", main, false);
1054-
`
1054+
document.addEventListener("DOMContentLoaded", main, false);`
10551055
},
10561056
'/index.html': {
10571057
code: `<!DOCTYPE html>
@@ -1069,7 +1069,7 @@ document.addEventListener("DOMContentLoaded", main, false);
10691069
<label for="chunkInput">Chunk size:</label>
10701070
<input type="number" id="chunkInput" value="512" min="1" style="width:80px;">
10711071
<div id="output"></div>
1072-
<button id="showMore" style="display:none;">Show next chunk</button>
1072+
<button id="more" style="display:none;">Show next chunk</button>
10731073
<script src="./webnn.js"></script>
10741074
</body>
10751075
@@ -1081,16 +1081,21 @@ document.addEventListener("DOMContentLoaded", main, false);
10811081
}
10821082
10831083
h1 {
1084-
color: #E44D26;
1085-
font-size: 0.8rem;
1084+
font-size: 1rem;
1085+
}
1086+
1087+
label {
1088+
font-size: 0.9rem;
10861089
}
10871090
10881091
button {
10891092
margin: 0.5rem 0;
1090-
padding: 0.5rem 1rem;
1093+
padding: 0.2rem 1rem;
10911094
}
10921095
10931096
#output {
1097+
color: #333;
1098+
padding: 0.5rem 0;
10941099
font-size: 0.6rem;
10951100
}`}
10961101
},

0 commit comments

Comments
 (0)