Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e_weight不满足断言 #62

Open
unccx opened this issue Jun 25, 2024 · 0 comments
Open

e_weight不满足断言 #62

unccx opened this issue Jun 25, 2024 · 0 comments

Comments

@unccx
Copy link

unccx commented Jun 25, 2024

Describe the bug
dhg\structure\hypergraphs\hypergraph.py 的 add_hyperedges() 函数

// 判断e_weight 类型
        if e_weight is None:
            e_weight = [1.0] * len(e_list)
        elif type(e_weight) in (int, float):
            e_weight = [e_weight] // 这里错误 应该是 [e_weight] * len(e_list) 否则过不了下面的assert
        elif type(e_weight) is list:
            pass
        else:
            raise TypeError(f"The type of e_weight should be float or list, but got {type(e_weight)}")
        assert len(e_list) == len(e_weight), "The number of hyperedges and the number of weights are not equal."

To Reproduce
执行下面这段代码

from dhg import Hypergraph
hg = Hypergraph(4, [[0, 1, 2], [1, 2, 3]], e_weight=0.8)

显示

Traceback (most recent call last):
  File "D:\test.py", line 3, in <module>
    hg = Hypergraph(4, [[0, 1, 2], [1, 2, 3]], e_weight=0.8)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\miniforge3\envs\task_hg\Lib\site-packages\dhg\structure\hypergraphs\hypergraph.py", line 48, in __init__
    self.add_hyperedges(e_list, e_weight, merge_op=merge_op)
  File "C:\Users\xxx\miniforge3\envs\task_hg\Lib\site-packages\dhg\structure\hypergraphs\hypergraph.py", line 345, in add_hyperedges
    assert len(e_list) == len(e_weight), "The number of hyperedges and the number of weights are not equal."
AssertionError: The number of hyperedges and the number of weights are not equal.

Expected behavior
e_weight 应该被正确设置为 [e_weight] * len(e_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant