コード例 #1
0
    def test_math_utils(self):
        a = initializeAutoDiff([1, 2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1, 2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a), np.eye(3))

        a, b = initializeAutoDiffTuple([1], [2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1]]))
        np.testing.assert_array_equal(autoDiffToValueMatrix(b),
                                      np.array([[2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a),
                                      np.eye(1, 3))
        np.testing.assert_array_equal(autoDiffToGradientMatrix(b),
                                      np.hstack((np.zeros((2, 1)), np.eye(2))))
コード例 #2
0
    def test_math_utils(self):
        a = initializeAutoDiff([1, 2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1, 2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a), np.eye(3))

        a, b = initializeAutoDiffTuple([1], [2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1]]))
        np.testing.assert_array_equal(autoDiffToValueMatrix(b),
                                      np.array([[2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a),
                                      np.eye(1, 3))
        np.testing.assert_array_equal(autoDiffToGradientMatrix(b),
                                      np.hstack((np.zeros((2, 1)), np.eye(2))))
コード例 #3
0
    def test_math_utils(self):
        a = initializeAutoDiff([1, 2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1, 2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a), np.eye(3))

        a, b = initializeAutoDiffTuple([1], [2, 3])
        np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                      np.array([[1]]))
        np.testing.assert_array_equal(autoDiffToValueMatrix(b),
                                      np.array([[2, 3]]).T)
        np.testing.assert_array_equal(autoDiffToGradientMatrix(a),
                                      np.eye(1, 3))
        np.testing.assert_array_equal(autoDiffToGradientMatrix(b),
                                      np.hstack((np.zeros((2, 1)), np.eye(2))))

        c_grad = [[2, 4, 5], [1, -1, 0]]
        c = initializeAutoDiffGivenGradientMatrix([2, 3], c_grad)
        np.testing.assert_array_equal(autoDiffToValueMatrix(c),
                                      np.array([2, 3]).reshape((2, 1)))
        np.testing.assert_array_equal(autoDiffToGradientMatrix(c),
                                      np.array(c_grad))
コード例 #4
0
    def test_deprecated_math_utils(self):
        with catch_drake_warnings(expected_count=1):
            a = initializeAutoDiff([1, 2, 3])
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                          np.array([[1, 2, 3]]).T)
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToGradientMatrix(a),
                                          np.eye(3))

        with catch_drake_warnings(expected_count=1):
            a, b = initializeAutoDiffTuple([1], [2, 3])

        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToValueMatrix(a),
                                          np.array([[1]]))
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToValueMatrix(b),
                                          np.array([[2, 3]]).T)
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToGradientMatrix(a),
                                          np.eye(1, 3))
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(
                autoDiffToGradientMatrix(b),
                np.hstack((np.zeros((2, 1)), np.eye(2))))

        c_grad = [[2, 4, 5], [1, -1, 0]]
        with catch_drake_warnings(expected_count=1):
            c = initializeAutoDiffGivenGradientMatrix([2, 3], c_grad)
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToValueMatrix(c),
                                          np.array([2, 3]).reshape((2, 1)))
        with catch_drake_warnings(expected_count=1):
            np.testing.assert_array_equal(autoDiffToGradientMatrix(c),
                                          np.array(c_grad))