当前位置: 首页>>代码示例>>Python>>正文


Python Parameter.name方法代码示例

本文整理汇总了Python中cvxpy.expressions.constants.Parameter.name方法的典型用法代码示例。如果您正苦于以下问题:Python Parameter.name方法的具体用法?Python Parameter.name怎么用?Python Parameter.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cvxpy.expressions.constants.Parameter的用法示例。


在下文中一共展示了Parameter.name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_parameters

# 需要导入模块: from cvxpy.expressions.constants import Parameter [as 别名]
# 或者: from cvxpy.expressions.constants.Parameter import name [as 别名]
    def test_parameters(self):
        p = Parameter(name='p')
        self.assertEqual(p.name(), "p")
        self.assertEqual(p.size, (1,1))

        p = Parameter(4, 3, sign="positive")
        with self.assertRaises(Exception) as cm:
            p.value = 1
        self.assertEqual(str(cm.exception), "Invalid dimensions (1,1) for Parameter value.")

        val = -np.ones((4,3))
        val[0,0] = 2

        p = Parameter(4, 3, sign="positive")
        with self.assertRaises(Exception) as cm:
            p.value = val
        self.assertEqual(str(cm.exception), "Invalid sign for Parameter value.")

        p = Parameter(4, 3, sign="negative")
        with self.assertRaises(Exception) as cm:         
            p.value = val
        self.assertEqual(str(cm.exception), "Invalid sign for Parameter value.")

        # No error for unknown sign.
        p = Parameter(4, 3)
        p.value = val
开发者ID:Russell91,项目名称:cvxpy,代码行数:28,代码来源:test_expressions.py

示例2: test_parameters

# 需要导入模块: from cvxpy.expressions.constants import Parameter [as 别名]
# 或者: from cvxpy.expressions.constants.Parameter import name [as 别名]
    def test_parameters(self):
        p = Parameter(name='p')
        self.assertEqual(p.name(), "p")
        self.assertEqual(p.size, (1, 1))

        p = Parameter(4, 3, sign="positive")
        with self.assertRaises(Exception) as cm:
            p.value = 1
        self.assertEqual(str(cm.exception), "Invalid dimensions (1, 1) for Parameter value.")

        val = -np.ones((4, 3))
        val[0, 0] = 2

        p = Parameter(4, 3, sign="positive")
        with self.assertRaises(Exception) as cm:
            p.value = val
        self.assertEqual(str(cm.exception), "Invalid sign for Parameter value.")

        p = Parameter(4, 3, sign="negative")
        with self.assertRaises(Exception) as cm:
            p.value = val
        self.assertEqual(str(cm.exception), "Invalid sign for Parameter value.")

        # No error for unknown sign.
        p = Parameter(4, 3)
        p.value = val

        # Initialize a parameter with a value.
        p = Parameter(value=10)
        self.assertEqual(p.value, 10)

        # Test assigning None.
        p.value = 10
        p.value = None
        assert p.value is None

        with self.assertRaises(Exception) as cm:
            p = Parameter(2, 1, sign="negative", value=[2, 1])
        self.assertEqual(str(cm.exception), "Invalid sign for Parameter value.")

        with self.assertRaises(Exception) as cm:
            p = Parameter(4, 3, sign="positive", value=[1, 2])
        self.assertEqual(str(cm.exception), "Invalid dimensions (2, 1) for Parameter value.")

        # Test repr.
        p = Parameter(4, 3, sign="negative")
        self.assertEqual(repr(p), 'Parameter(4, 3, sign="NEGATIVE")')
开发者ID:heath9,项目名称:cvxpy,代码行数:49,代码来源:test_expressions.py

示例3: test_parameters

# 需要导入模块: from cvxpy.expressions.constants import Parameter [as 别名]
# 或者: from cvxpy.expressions.constants.Parameter import name [as 别名]
 def test_parameters(self):
     p = Parameter(name='p')
     self.assertEqual(p.name(), "p")
     self.assertEqual(p.size, (1,1))
开发者ID:HapeMask,项目名称:cvxpy,代码行数:6,代码来源:test_expressions.py


注:本文中的cvxpy.expressions.constants.Parameter.name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。