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

Function registerClass

tfjs-core/src/serialization.ts:234–265  ·  view source on GitHub ↗
(
    cls: SerializableConstructor<T>, pkg?: string, name?: string)

Source from the content-addressed store, hash-verified

232 * @doc {heading: 'Models', subheading: 'Serialization', ignoreCI: true}
233 */
234export function registerClass<T extends Serializable>(
235 cls: SerializableConstructor<T>, pkg?: string, name?: string) {
236 assert(
237 cls.className != null,
238 () => `Class being registered does not have the static className ` +
239 `property defined.`);
240 assert(
241 typeof cls.className === 'string',
242 () => `className is required to be a string, but got type ` +
243 typeof cls.className);
244 assert(
245 cls.className.length > 0,
246 () => `Class being registered has an empty-string as its className, ` +
247 `which is disallowed.`);
248
249 if (typeof pkg === 'undefined') {
250 pkg = 'Custom';
251 }
252
253 if (typeof name === 'undefined') {
254 name = cls.className;
255 }
256
257 const className = name;
258 const registerName = pkg + '>' + className;
259
260 SerializationMap.register(cls);
261 GLOBAL_CUSTOM_OBJECT.set(registerName, cls);
262 GLOBAL_CUSTOM_NAMES.set(cls, registerName);
263
264 return cls;
265}
266
267/**
268 * Get the registered name of a class. If the class has not been registered,

Callers 2

registerOptimizersFunction · 0.90

Calls 3

assertFunction · 0.90
registerMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…