Example #1
0
def test_to_np():
  array = np.arange(0, 3).astype(np.float)
  assert core.to_np(array) is array

  tensor = core.T(array)
  result = core.to_np([tensor, tensor])
  np.testing.assert_equal(result[0], array)
  np.testing.assert_equal(result[1], array)

  variable = core.V(array)
  np.testing.assert_equal(core.to_np(variable), array)
Example #2
0
def test_to_np():
    array = np.arange(0, 3).astype(np.float)
    assert core.to_np(array) is array

    tensor = core.T(array)
    result = core.to_np([tensor, tensor])
    np.testing.assert_equal(result[0], array)
    np.testing.assert_equal(result[1], array)

    variable = core.V(array)
    np.testing.assert_equal(core.to_np(variable), array)

    with mock.patch("torch.cuda") as cuda_mock:
        tensor_long = core.T(array.astype(np.int))
        cuda_mock.is_available(return_value=True)
        cuda_mock.HalfTensor = torch.LongTensor

        array = core.to_np(tensor_long)
        np.testing.assert_equal(array, [0., 1., 2.])
        assert array.dtype in (np.float32, np.float64)
Example #3
0
def test_to_np():
    array = np.arange(0, 3).astype(np.float)
    assert core.to_np(array) is array

    tensor = core.T(array)
    result = core.to_np([tensor, tensor])
    np.testing.assert_equal(result[0], array)
    np.testing.assert_equal(result[1], array)

    variable = core.V(array)
    np.testing.assert_equal(core.to_np(variable), array)

    with mock.patch("torch.cuda.is_available") as is_available_mock:
        with mock.patch("fastai.core.is_half_tensor") as is_half_tensor_mock:
            is_available_mock.return_value = True
            is_half_tensor_mock.return_value = True

            tensor = core.T(array.astype(np.int))

            array = core.to_np(tensor)
            np.testing.assert_equal(array, [0., 1., 2.])
            assert array.dtype in (np.float32, np.float64)
Example #4
0
def test_V(map_over_mock):
    core.V("foo")

    assert map_over_mock.call_args[0][0] == 'foo'
    assert type(map_over_mock.call_args[0][1]) == type(lambda: 0)
Example #5
0
    def test_forward(self):
        x = core.V(np.array([[1., 2.]]), requires_grad=False)
        output = core.to_np(self.simple_net.forward(x))

        np.testing.assert_almost_equal(output, [[-1.435481, -0.27181]],
                                       decimal=4)