code: def test_ItemSetDict_length():
      # Single iterable with valid length.
      user_ids = torch.arange(0, 5)
      item_ids = torch.arange(0, 5)
      item_set = gb.ItemSetDict(
          {
              "user": gb.ItemSet(user_ids),
              "item": gb.ItemSet(item_ids),
          }
      )
      assert len(item_set) == len(user_ids) + len(item_ids)
  
      # Tuple of iterables with valid length.
      node_pairs_like = torch.arange(0, 10).reshape(-1, 2)
      neg_dsts_like = torch.arange(10, 20).reshape(-1, 2)
      node_pairs_follow = torch.arange(0, 10).reshape(-1, 2)
      neg_dsts_follow = torch.arange(10, 20).reshape(-1, 2)
      item_set = gb.ItemSetDict(
          {
              "user:like:item": gb.ItemSet(
                  (node_pairs_like, neg_dsts_like)
              ),
              "user:follow:user": gb.ItemSet(
                  (node_pairs_follow, neg_dsts_follow)
              ),
          }
      )
      assert len(item_set) == node_pairs_like.size(
          0
      ) + node_pairs_follow.size(0)
  
      class InvalidLength:
          def __iter__(self):
              return iter([0, 1, 2])
  
      # Single iterable with invalid length.
      item_set = gb.ItemSetDict(
          {
              "user": gb.ItemSet(InvalidLength()),
              "item": gb.ItemSet(InvalidLength()),
          }
      )
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't have valid length."
      ):
          _ = len(item_set)
      with pytest.raises(
          TypeError,
          match="ItemSetDict instance doesn't support indexing.",
      ):
          _ = item_set[0]
  
      # Tuple of iterables with invalid length.
      item_set = gb.ItemSetDict(
          {
              "user:like:item": gb.ItemSet(
                  (InvalidLength(), InvalidLength())
              ),
              "user:follow:user": gb.ItemSet(
                  (InvalidLength(), InvalidLength())
              ),
          }
      )
      with pytest.raises(
          TypeError, match="ItemSet instance doesn't have valid length."
      ):
          _ = len(item_set)
      with pytest.raises(
          TypeError,
          match="ItemSetDict instance doesn't support indexing.",
      ):
          _ = item_set[0]
  
imports: import re
  import dgl
  import pytest
  import torch
  from dgl import graphbolt
  from torch.testing import assert_close
label_desc: Use image node_id 10 for calling a global function with example usage: test_ItemSetDict_length() and returns: iter