MCPcopy
hub / github.com/tensorflow/tfjs / convertTsToPythonic

Function convertTsToPythonic

tfjs-layers/src/utils/serialization_utils.ts:90–128  ·  view source on GitHub ↗
(
    tsConfig: serialization.ConfigDictValue, key?: string)

Source from the content-addressed store, hash-verified

88 * @returns Result of the conversion.
89 */
90export function convertTsToPythonic(
91 tsConfig: serialization.ConfigDictValue, key?: string): PyJsonValue {
92 if (tsConfig === null || tsConfig === undefined) {
93 return null;
94 } else if (typeof tsConfig === 'string') {
95 return generic_utils.toSnakeCase(tsConfig);
96 } else if (
97 (typeof tsConfig === 'number') || (typeof tsConfig === 'boolean')) {
98 return tsConfig;
99 } else if (tsConfig instanceof Array) {
100 const pyArray = [];
101 const arrayLength = tsConfig.length;
102 for (let i = 0; i < arrayLength; ++i) {
103 const item = tsConfig[i];
104 if (isArrayItemInputOrOutputName(key, i, item)) {
105 pyArray.push(item);
106 } else {
107 pyArray.push(convertTsToPythonic(item, key));
108 }
109 }
110 return pyArray;
111 } else {
112 const pyDict: serialization.ConfigDict = {};
113 for (const tsKey of Object.keys(tsConfig)) {
114 const tsValue = tsConfig[tsKey];
115 const pyKey = generic_utils.toSnakeCase(tsKey);
116 if ((tsKey === 'name' || tsKey === 'className') &&
117 typeof tsValue === 'string') {
118 // Special case the 'name' key with a string value. Name values, such as
119 // the names of LayersModel and Layer instances, should not undergo the
120 // snake-case conversion.
121 pyDict[pyKey] = tsValue;
122 } else {
123 pyDict[pyKey] = convertTsToPythonic(tsValue, tsKey);
124 }
125 }
126 return pyDict;
127 }
128}

Callers 11

models_test.tsFile · 0.90
toJSONFunction · 0.90
merge_test.tsFile · 0.90
padding_test.tsFile · 0.90
recurrent_test.tsFile · 0.90
core_test.tsFile · 0.90

Calls 2

pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…