Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbolic Args test #536

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions keras_core/ops/symbolic_arguments_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import tree

from keras_core import testing
from keras_core.backend import KerasTensor
from keras_core.ops.symbolic_arguments import SymbolicArguments


class SymbolicArgumentsTest(testing.TestCase):
def test_args(self):
shape = (2, 3, 4)
a = KerasTensor(shape=shape)
b = KerasTensor(shape=shape)
args = SymbolicArguments(
(
a,
b,
),
{},
)

self.assertEqual(args.keras_tensors, [a, b])
self.assertEqual(args.__dict__["_flat_arguments"], [a, b])

def test_conversion_fn(self):
shape = (2, 3, 4)
a = KerasTensor(shape=shape)
b = KerasTensor(shape=shape)
sym_args = SymbolicArguments(
(
a,
b,
),
{},
)

(value, _) = sym_args.convert(lambda x: x**2)
args1 = value[0][0]
args2 = value[0][1]

self.assertIsInstance(args1, KerasTensor)
self.assertNotEqual(args1, a)
self.assertNotEqual(args2, b)

mapped_value = tree.map_structure(lambda x: x**2, a)
self.assertEqual(mapped_value.shape, args1.shape)
self.assertEqual(mapped_value.dtype, args1.dtype)

def test_fill_in(self):
adi-kmt marked this conversation as resolved.
Show resolved Hide resolved
pass