(
batch_size,
seq_len,
input_size,
hidden_size,
num_layers,
bidirectional,
init_hidden,
batch_first,
)
| 67 | ], |
| 68 | ) |
| 69 | def test_rnn( |
| 70 | batch_size, |
| 71 | seq_len, |
| 72 | input_size, |
| 73 | hidden_size, |
| 74 | num_layers, |
| 75 | bidirectional, |
| 76 | init_hidden, |
| 77 | batch_first, |
| 78 | ): |
| 79 | rnn = RNN( |
| 80 | input_size, |
| 81 | hidden_size, |
| 82 | batch_first=batch_first, |
| 83 | num_layers=num_layers, |
| 84 | bidirectional=bidirectional, |
| 85 | ) |
| 86 | if batch_first: |
| 87 | x_shape = (batch_size, seq_len, input_size) |
| 88 | else: |
| 89 | x_shape = (seq_len, batch_size, input_size) |
| 90 | x = mge.random.normal(size=x_shape) |
| 91 | total_hidden_size = num_layers * (2 if bidirectional else 1) * hidden_size |
| 92 | if init_hidden: |
| 93 | h = mge.random.normal(size=(batch_size, total_hidden_size)) |
| 94 | else: |
| 95 | h = None |
| 96 | output, h_n = rnn(x, h) |
| 97 | num_directions = 2 if bidirectional else 1 |
| 98 | if batch_first: |
| 99 | assert_tuple_equal( |
| 100 | output.shape, (batch_size, seq_len, num_directions * hidden_size) |
| 101 | ) |
| 102 | else: |
| 103 | assert_tuple_equal( |
| 104 | output.shape, (seq_len, batch_size, num_directions * hidden_size) |
| 105 | ) |
| 106 | assert_tuple_equal( |
| 107 | h_n.shape, (num_directions * num_layers, batch_size, hidden_size) |
| 108 | ) |
| 109 | |
| 110 | |
| 111 | @pytest.mark.skipif(get_device_count("gpu") > 0, reason="no algorithm on cuda") |
nothing calls this directly
no test coverage detected