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

Function convertPythonicToTs

tfjs-layers/src/utils/serialization_utils.ts:44–82  ·  view source on GitHub ↗
(
    pythonicConfig: PyJsonValue, key?: string)

Source from the content-addressed store, hash-verified

42 * @returns Result of the conversion.
43 */
44export function convertPythonicToTs(
45 pythonicConfig: PyJsonValue, key?: string): serialization.ConfigDictValue {
46 if (pythonicConfig === null) {
47 return null;
48 } else if (typeof pythonicConfig === 'string') {
49 return generic_utils.toCamelCase(pythonicConfig);
50 } else if (
51 (typeof pythonicConfig === 'number') ||
52 (typeof pythonicConfig === 'boolean')) {
53 return pythonicConfig;
54 } else if (pythonicConfig instanceof Array) {
55 const tsArray = [];
56 const arrayLength = pythonicConfig.length;
57 for (let i = 0; i < arrayLength; ++i) {
58 const item = pythonicConfig[i];
59 if (isArrayItemInputOrOutputName(key, i, item)) {
60 tsArray.push(item);
61 } else {
62 tsArray.push(convertPythonicToTs(item, key));
63 }
64 }
65 return tsArray;
66 } else {
67 const tsDict: serialization.ConfigDict = {};
68 for (const pythonicKey of Object.keys(pythonicConfig)) {
69 const pythonicValue = pythonicConfig[pythonicKey];
70 if (pythonicKey === 'name' && typeof pythonicValue === 'string') {
71 // Special case the 'name' key with a string value. Name values, such as
72 // the names of LayersModel and Layer instances, should not undergo the
73 // camel-case conversion.
74 tsDict[pythonicKey] = pythonicValue;
75 } else {
76 const tsKey = generic_utils.toCamelCase(pythonicKey);
77 tsDict[tsKey] = convertPythonicToTs(pythonicValue, tsKey);
78 }
79 }
80 return tsDict;
81 }
82}
83
84/**
85 * Convert a TypeScript config object to Python config object.

Calls 2

pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…