Skip to content

e_weight不满足断言 #62

@unccx

Description

@unccx

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions