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

Function getCustomConverterOpsModule

tfjs/tools/custom_module/custom_module.ts:77–114  ·  view source on GitHub ↗
(
    ops: string[], moduleProvider: ImportProvider)

Source from the content-addressed store, hash-verified

75}
76
77export function getCustomConverterOpsModule(
78 ops: string[], moduleProvider: ImportProvider): string {
79 const result: string[] = ['// This file is autogenerated\n'];
80
81 // Separate namespaced apis from non namespaced ones as they require a
82 // different export pattern that treats each namespace as a whole.
83
84 const flatOps = [];
85 const namespacedOps: {[key: string]: string[]} = {};
86
87 for (const opSymbol of ops) {
88 if (opSymbol.match(/\./)) {
89 const parts = opSymbol.split(/\./);
90 const namespace = parts[0];
91 const opName = parts[1];
92
93 if (namespacedOps[namespace] == null) {
94 namespacedOps[namespace] = [];
95 }
96 namespacedOps[namespace].push(opName);
97 } else {
98 flatOps.push(opSymbol);
99 }
100 }
101
102 // Group the namespaced symbols by namespace
103 for (const namespace of Object.keys(namespacedOps)) {
104 const opSymbols = namespacedOps[namespace];
105 result.push(moduleProvider.importNamespacedOpsForConverterStr(
106 namespace, opSymbols));
107 }
108
109 for (const opSymbol of flatOps) {
110 result.push(moduleProvider.importOpForConverterStr(opSymbol));
111 }
112
113 return result.join('\n');
114}
115
116function addLine(target: string[], line: string) {
117 target.push(line);

Callers 2

Calls 3

joinMethod · 0.80
splitMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…