本文整理汇总了Python中torch.pstrf方法的典型用法代码示例。如果您正苦于以下问题:Python torch.pstrf方法的具体用法?Python torch.pstrf怎么用?Python torch.pstrf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch
的用法示例。
在下文中一共展示了torch.pstrf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pstrf
# 需要导入模块: import torch [as 别名]
# 或者: from torch import pstrf [as 别名]
def test_pstrf(self):
def checkPsdCholesky(a, uplo, inplace):
if inplace:
u = torch.Tensor(a.size())
piv = torch.IntTensor(a.size(0))
args = [u, piv, a]
else:
args = [a]
if uplo is not None:
args += [uplo]
u, piv = torch.pstrf(*args)
if uplo is False:
a_reconstructed = torch.mm(u, u.t())
else:
a_reconstructed = torch.mm(u.t(), u)
piv = piv.long()
a_permuted = a.index_select(0, piv).index_select(1, piv)
self.assertEqual(a_permuted, a_reconstructed, 1e-14)
dimensions = ((5, 1), (5, 3), (5, 5), (10, 10))
for dim in dimensions:
m = torch.Tensor(*dim).uniform_()
a = torch.mm(m, m.t())
# add a small number to the diagonal to make the matrix numerically positive semidefinite
for i in range(m.size(0)):
a[i][i] = a[i][i] + 1e-7
for inplace in (True, False):
for uplo in (None, True, False):
checkPsdCholesky(a, uplo, inplace)
示例2: test_pstrf
# 需要导入模块: import torch [as 别名]
# 或者: from torch import pstrf [as 别名]
def test_pstrf(self):
def checkPsdCholesky(a, uplo, inplace):
if inplace:
u = torch.Tensor(a.size())
piv = torch.IntTensor(a.size(0))
kwargs = {'out': (u, piv)}
else:
kwargs = {}
args = [a]
if uplo is not None:
args += [uplo]
u, piv = torch.pstrf(*args, **kwargs)
if uplo is False:
a_reconstructed = torch.mm(u, u.t())
else:
a_reconstructed = torch.mm(u.t(), u)
piv = piv.long()
a_permuted = a.index_select(0, piv).index_select(1, piv)
self.assertEqual(a_permuted, a_reconstructed, 1e-14)
dimensions = ((5, 1), (5, 3), (5, 5), (10, 10))
for dim in dimensions:
m = torch.Tensor(*dim).uniform_()
a = torch.mm(m, m.t())
# add a small number to the diagonal to make the matrix numerically positive semidefinite
for i in range(m.size(0)):
a[i][i] = a[i][i] + 1e-7
for inplace in (True, False):
for uplo in (None, True, False):
checkPsdCholesky(a, uplo, inplace)