Skip to content

Commit

Permalink
Create test_containers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ASEM000 committed Aug 16, 2023
1 parent bed96b4 commit 09b82f4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 Serket authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import jax.random as jr

import serket as sk


def test_sequential_without_key():
layer = sk.nn.Sequential(lambda x: x + 1, lambda x: x * 2)
assert layer(1) == 4


def test_sequential_with_key():
layer = sk.nn.Sequential(lambda x: x + 1, lambda x: x * 2)
assert layer(1, key=jr.PRNGKey(0)) == 4


def test_random_apply():
layer = sk.nn.RandomApply(lambda x: x + 1, rate=1.0)
assert layer(1, key=jr.PRNGKey(0)) == 2
layer = sk.nn.RandomApply(lambda x: x + 1, rate=0.0)
assert layer(1, key=jr.PRNGKey(0)) == 1


def test_random_choice():
layer = sk.nn.RandomChoice(lambda x: x + 2, lambda x: x * 2)
key = jr.PRNGKey(0)
assert layer(1, key=key) == 3.0
key = jr.PRNGKey(10)
assert layer(1, key=key) == 2.0

0 comments on commit 09b82f4

Please sign in to comment.