MCPcopy Create free account
hub / github.com/tensorflow/tfjs / getInputAtCoordsSnippet

Function getInputAtCoordsSnippet

tfjs-backend-webgpu/src/webgpu_program.ts:501–532  ·  view source on GitHub ↗
(
    inputInfo: InputInfo, component: number)

Source from the content-addressed store, hash-verified

499}
500
501function getInputAtCoordsSnippet(
502 inputInfo: InputInfo, component: number): string {
503 const texName = inputInfo.name;
504 const rank = inputInfo.shape.length;
505 const type = getCoordsDataType(rank);
506 const funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);
507 const dims = ['d0', 'd1', 'd2', 'd3', 'd4', 'd5'].slice(0, rank);
508 const inputs = dims.map(d => `${d} : i32`).join(', ');
509
510 if (rank < 1) {
511 return `
512 fn ${funcName}() -> ${typeSnippet(component)} {
513 return ${typeSnippet(component)}(${texName}[0]);
514 }
515 `;
516 }
517
518 const shapeStr =
519 `uniforms.${texName.charAt(0).toLowerCase() + texName.slice(1)}Shape`;
520 let rankStr = `${rank}D`;
521 if (rank === 0) {
522 rankStr = '1D';
523 }
524
525 return `
526 fn ${funcName}(${inputs}) -> ${typeSnippet(component)} {
527 return ${typeSnippet(component)}(${texName}[getIndexFromCoords${
528 rankStr}(${type}(${dims.join(',')}),
529 ${shapeStr})${component === 1 ? '' : ` / ${component}`}]);
530 }
531 `;
532}
533
534function getInputByOutputSnippet(
535 inputInfo: InputInfo, outShape: number[], component: number,

Callers 1

getInputSnippetFunction · 0.85

Calls 4

typeSnippetFunction · 0.85
joinMethod · 0.80
getCoordsDataTypeFunction · 0.70
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…