本文整理汇总了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
示例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")')
示例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))