本文整理汇总了Python中hail.linalg.BlockMatrix.fromfile方法的典型用法代码示例。如果您正苦于以下问题:Python BlockMatrix.fromfile方法的具体用法?Python BlockMatrix.fromfile怎么用?Python BlockMatrix.fromfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hail.linalg.BlockMatrix
的用法示例。
在下文中一共展示了BlockMatrix.fromfile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_from_numpy
# 需要导入模块: from hail.linalg import BlockMatrix [as 别名]
# 或者: from hail.linalg.BlockMatrix import fromfile [as 别名]
def test_to_from_numpy(self):
n_rows = 10
n_cols = 11
data = np.random.rand(n_rows * n_cols)
bm = BlockMatrix._create(n_rows, n_cols, data.tolist(), block_size=4)
a = data.reshape((n_rows, n_cols))
with tempfile.NamedTemporaryFile() as bm_f:
with tempfile.NamedTemporaryFile() as a_f:
bm.tofile(bm_f.name)
a.tofile(a_f.name)
a1 = bm.to_numpy()
a2 = BlockMatrix.from_numpy(a, block_size=5).to_numpy()
a3 = np.fromfile(bm_f.name).reshape((n_rows, n_cols))
a4 = BlockMatrix.fromfile(a_f.name, n_rows, n_cols, block_size=3).to_numpy()
a5 = BlockMatrix.fromfile(bm_f.name, n_rows, n_cols).to_numpy()
self._assert_eq(a1, a)
self._assert_eq(a2, a)
self._assert_eq(a3, a)
self._assert_eq(a4, a)
self._assert_eq(a5, a)
bmt = bm.T
at = a.T
with tempfile.NamedTemporaryFile() as bmt_f:
with tempfile.NamedTemporaryFile() as at_f:
bmt.tofile(bmt_f.name)
at.tofile(at_f.name)
at1 = bmt.to_numpy()
at2 = BlockMatrix.from_numpy(at).to_numpy()
at3 = np.fromfile(bmt_f.name).reshape((n_cols, n_rows))
at4 = BlockMatrix.fromfile(at_f.name, n_cols, n_rows).to_numpy()
at5 = BlockMatrix.fromfile(bmt_f.name, n_cols, n_rows).to_numpy()
self._assert_eq(at1, at)
self._assert_eq(at2, at)
self._assert_eq(at3, at)
self._assert_eq(at4, at)
self._assert_eq(at5, at)
self._assert_eq(bm.to_numpy(_force_blocking=True), a)