-
Notifications
You must be signed in to change notification settings - Fork 19.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11edb68
commit da41073
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import numpy as np | ||
|
||
from keras.src import ops | ||
from keras.src import testing | ||
from keras.src.backend.common.symbolic_scope import SymbolicScope | ||
from keras.src.backend.common.symbolic_scope import in_symbolic_scope | ||
|
||
|
||
class TestSymbolicScope(testing.TestCase): | ||
def test_basic_flow(self): | ||
|
||
# Define a function that behaves differently according to | ||
# `in_symbolic_scope`. | ||
def compute_loss(y, y_pred): | ||
if in_symbolic_scope(): | ||
return ops.zeros_like(y) | ||
return ops.add(y, y_pred) | ||
|
||
y = ops.ones(shape=(2,)) | ||
y_pred = ops.ones(shape=(2,)) | ||
with SymbolicScope(): | ||
loss = compute_loss(y, y_pred) | ||
self.assertAllClose(loss, np.zeros((2,))) | ||
|
||
loss = compute_loss(y, y_pred) | ||
self.assertAllClose(loss, 2 * np.ones((2,))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters