Exemple #1
0
 def test_calculate_broken_mock_is_repeated(self):
     with self.assertRaisesRegexp(
             ValueError,
             "Expression Node0 returned the wrong type: expected: repeated <dtype: "
             "'int64'> actual: optional <dtype: 'int64'>."):
         single_node = expression_test_util.get_mock_broken_leaf(
             True, tf.int64, False, tf.int64, name="Node0")
         calculate.calculate_values([single_node])
Exemple #2
0
 def test_calculate_root_direct(self):
   """Calculates the value of a node with no sources."""
   for options in options_to_test:
     tree = create_expression.create_expression_from_prensor(
         prensor_test_util.create_simple_prensor())
     [root_value] = calculate.calculate_values([tree], options=options)
     self.assertAllEqual(root_value.size, 3)
Exemple #3
0
 def test_create_query_and_calculate_event_value(self):
   """Calculating a child value in a proto tests dependencies."""
   for options in options_to_test:
     expr = proto_test_util._get_expression_from_session_empty_user_info()
     [event_value
     ] = calculate.calculate_values([expr.get_child_or_error("event")],
                                    options=options)
     self.assertAllEqual(event_value.parent_index, [0, 0, 0, 1, 1])
Exemple #4
0
 def test_calculate_root_indirect(self):
   """Calculates the value of a node with one source."""
   for options in options_to_test:
     tree = create_expression.create_expression_from_prensor(
         prensor_test_util.create_simple_prensor())
     tree_2 = expression_add.add_paths(tree, {})
     [root_value] = calculate.calculate_values([tree_2], options=options)
     self.assertAllEqual(root_value.size, 3)
Exemple #5
0
 def test_calculate_root_direct(self):
     """Calculates the value of a node with no sources."""
     for options in options_to_test:
         with self.session(use_gpu=False) as sess:
             tree = create_expression.create_expression_from_prensor(
                 prensor_test_util.create_simple_prensor())
             [root_value] = calculate.calculate_values([tree],
                                                       options=options)
             size_result = sess.run(root_value.size)
             self.assertAllEqual(size_result, 3)
Exemple #6
0
 def test_create_query_modify_and_calculate_event_value(self):
   """Calculating a child value in a proto tests dependencies."""
   for options in options_to_test:
     root = proto_test_util._get_expression_from_session_empty_user_info()
     root_2 = expression_add.add_paths(
         root, {path.Path(["event_copy"]): root.get_child_or_error("event")})
     [event_value
     ] = calculate.calculate_values([root_2.get_child_or_error("event_copy")],
                                    options=options)
     self.assertAllEqual(event_value.parent_index, [0, 0, 0, 1, 1])
Exemple #7
0
    def testPlaceholderExpression(self):
        pren = prensor_test_util.create_nested_prensor()
        expected_pren = prensor.create_prensor_from_descendant_nodes({
            path.Path([]):
            prensor.RootNodeTensor(tf.constant(3, dtype=tf.int64)),
            path.Path(["new_friends"]):
            prensor.LeafNodeTensor(
                tf.constant([0, 1, 1, 1, 2], dtype=tf.int64),
                tf.constant(["a", "b", "c", "d", "e"], dtype=tf.string), True)
        })

        root_schema = mpp.create_schema(is_repeated=True,
                                        children={
                                            "doc": {
                                                "is_repeated": True,
                                                "children": {
                                                    "bar": {
                                                        "is_repeated": True,
                                                        "dtype": tf.string
                                                    },
                                                    "keep_me": {
                                                        "is_repeated": False,
                                                        "dtype": tf.bool
                                                    }
                                                }
                                            },
                                            "user": {
                                                "is_repeated": True,
                                                "children": {
                                                    "friends": {
                                                        "is_repeated": True,
                                                        "dtype": tf.string
                                                    }
                                                }
                                            }
                                        })

        exp = placeholder.create_expression_from_schema(root_schema)
        promote_exp = promote.promote(exp, path.Path(["user", "friends"]),
                                      "new_friends")
        project_exp = project.project(promote_exp,
                                      [path.Path(["new_friends"])])
        new_friends_exp = project_exp.get_descendant(path.Path(["new_friends"
                                                                ]))

        result = calculate.calculate_values([new_friends_exp],
                                            feed_dict={exp: pren})

        res_node = result[0]
        exp_node = expected_pren.get_descendant(path.Path(["new_friends"
                                                           ])).node

        self.assertAllEqual(res_node.is_repeated, exp_node.is_repeated)
        self.assertAllEqual(res_node.values, exp_node.values)
        self.assertAllEqual(res_node.parent_index, exp_node.parent_index)
Exemple #8
0
 def test_calculate_promote_anonymous(self):
   """Performs promote_test.PromoteValuesTest, but with calculate_values."""
   for options in options_to_test:
     expr = create_expression.create_expression_from_prensor(
         prensor_test_util.create_nested_prensor())
     new_root, new_path = promote.promote_anonymous(
         expr, path.Path(["user", "friends"]))
     new_field = new_root.get_descendant_or_error(new_path)
     [leaf_node] = calculate.calculate_values([new_field], options=options)
     self.assertAllEqual(leaf_node.parent_index, [0, 1, 1, 1, 2])
     self.assertAllEqual(leaf_node.values, [b"a", b"b", b"c", b"d", b"e"])
Exemple #9
0
 def test_calculate_promote_named(self):
   """Performs promote_test.PromoteValuesTest, but with calculate_values."""
   for options in options_to_test:
     expr = create_expression.create_expression_from_prensor(
         prensor_test_util.create_nested_prensor())
     new_root = promote.promote(expr, path.Path(["user", "friends"]),
                                "new_friends")
     # projected = project.project(new_root, [path.Path(["new_friends"])])
     new_field = new_root.get_child_or_error("new_friends")
     [leaf_node] = calculate.calculate_values([new_field], options=options)
     self.assertAllEqual(leaf_node.parent_index, [0, 1, 1, 1, 2])
     self.assertAllEqual(leaf_node.values, [b"a", b"b", b"c", b"d", b"e"])
Exemple #10
0
    def testCreateExpressionFromSchema(self):
        root_schema = mpp.create_schema(is_repeated=True, children={})
        exp = placeholder.create_expression_from_schema(root_schema)
        pren = prensor.create_prensor_from_descendant_nodes({
            path.Path([]):
            prensor.RootNodeTensor(tf.constant(1, dtype=tf.int64))
        })
        result = calculate.calculate_values([exp], feed_dict={exp: pren})
        res_node = result[0]
        exp_node = pren.get_descendant(path.Path([])).node

        self.assertAllEqual(res_node.is_repeated, exp_node.is_repeated)
        self.assertAllEqual(res_node.size, exp_node.size)
Exemple #11
0
  def test_calculate_random_mock(self):
    """Test calculate on 1000 graphs with 20 nodes.

    This will have identity operations.
    This will not have equal operations (outside of identity operations).
    All nodes in the graph are leaf expressions.
    """
    random.seed(a=12345)
    for options in options_to_test:
      for _ in range(1000):
        my_input = create_random_graph(20, 0.5, 0.2)
        [result] = calculate.calculate_values([my_input], options=options)
        self.assertIs(my_input._calculate_output, result)
Exemple #12
0
 def testPlaceholderRootExpressionRequiresSideInfo(self):
     root_schema = mpp.create_schema(is_repeated=True, children={})
     exp = placeholder.create_expression_from_schema(root_schema)
     with self.assertRaisesRegex(
             ValueError, "_PlaceholderRootExpression requires side_info"):
         calculate.calculate_values([exp], feed_dict={exp: None})
Exemple #13
0
 def test_calculate_mock(self):
     my_input = get_mock_linear_graph(5)
     [result] = calculate.calculate_values([my_input])
     self.assertIs(my_input._calculate_output, result)