Keras 3 API documentation / Utilities / Backend utilities

Backend utilities

[source]

get_uid function

keras.backend.get_uid(prefix="")

Associates a string prefix with an integer counter.

Arguments

  • prefix: String prefix to index.

Returns

Unique integer ID.

Example

>>> get_uid('dense')
1
>>> get_uid('dense')
2

[source]

result_type function

keras.backend.result_type(*dtypes)

Returns the type from applying the Keras type promotion rules.

In general, each argument is first parsed by backend.standardize_dtype, and the resulting dtype is determined by the least upper bound of the type promotion lattice.

Note: This function attempts to match the result of jnp.result_type.

Arguments

  • dtypes: Input dtypes.

Returns

The result dtype.

Examples

>>> x = keras.ops.ones((1,), dtype="bfloat16")
>>> keras.backend.result_type(x.dtype, int)
"bfloat16"
>>> x = keras.ops.ones((1,), dtype="int32")
>>> y = keras.ops.ones((1,), dtype="float32")
>>> keras.backend.result_type(x.dtype, y.dtype)
"float32"
>>> z= keras.ops.ones((1,), dtype='complex64')
>>> keras.backend.result_type(z.dtype, int)
"float64"