(is_varnode)
| 174 | |
| 175 | @pytest.mark.parametrize("is_varnode", [True, False]) |
| 176 | def test_stack(is_varnode): |
| 177 | if is_varnode: |
| 178 | network = Network() |
| 179 | else: |
| 180 | network = None |
| 181 | |
| 182 | data1 = np.random.random((3, 2, 2)).astype("float32") |
| 183 | data2 = np.random.random((3, 2, 2)).astype("float32") |
| 184 | data3 = np.random.random((3, 2, 2)).astype("float32") |
| 185 | |
| 186 | cases = [{"input": [data1, data2]}, {"input": [data1, data3]}] |
| 187 | for ai in range(3): |
| 188 | |
| 189 | def run(data1, data2): |
| 190 | return F.stack([data1, data2], axis=ai) |
| 191 | |
| 192 | opr_test( |
| 193 | cases, run, ref_fn=lambda x, y: np.stack([x, y], axis=ai), network=network |
| 194 | ) |
| 195 | |
| 196 | x1 = Tensor(np.arange(0, 3, dtype=np.float32).reshape((3))) |
| 197 | x2 = Tensor(np.arange(6, 9, dtype=np.float32).reshape((3))) |
| 198 | y = F.stack([x1, x2], axis=-1) |
| 199 | np.testing.assert_equal( |
| 200 | y.numpy(), np.array([[0, 6], [1, 7], [2, 8]]).astype(np.float32) |
| 201 | ) |
| 202 | |
| 203 | x1 = Tensor(np.arange(0, 3, dtype=np.float32).reshape((3))) |
| 204 | x2 = Tensor(np.arange(6, 9, dtype=np.float32).reshape((3))) |
| 205 | y = F.stack([x1, x2], axis=-1) |
| 206 | np.testing.assert_equal( |
| 207 | y.numpy(), np.array([[0, 6], [1, 7], [2, 8]]).astype(np.float32) |
| 208 | ) |
| 209 | |
| 210 | x1 = Tensor(np.random.rand(600)) |
| 211 | x2 = F.broadcast_to(Tensor(np.array(3)), (600,)) |
| 212 | |
| 213 | y = F.stack([x2, x1], axis=0) |
| 214 | np.testing.assert_equal(y.numpy(), np.stack((x2.numpy(), x1.numpy()), axis=0)) |
| 215 | |
| 216 | y = F.stack([x2, x2], axis=0) |
| 217 | np.testing.assert_equal(y.numpy(), np.stack((x2.numpy(), x2.numpy()), axis=0)) |
| 218 | |
| 219 | |
| 220 | @pytest.mark.parametrize("is_varnode", [True, False]) |
nothing calls this directly
no test coverage detected