jax.experimental.sparse.BCOO#
- class jax.experimental.sparse.BCOO(args, *, shape, indices_sorted=False, unique_indices=False)[源代码]#
JAX 中实现的实验性批量 COO 矩阵
- 参数:
示例
从密集数组创建稀疏数组
>>> M = jnp.array([[0., 2., 0.], [1., 0., 4.]]) >>> M_sp = BCOO.fromdense(M) >>> M_sp BCOO(float32[2, 3], nse=3)
检查内部表示
>>> M_sp.data Array([2., 1., 4.], dtype=float32) >>> M_sp.indices Array([[0, 1], [1, 0], [1, 2]], dtype=int32)
从稀疏数组创建密集数组
>>> M_sp.todense() Array([[0., 2., 0.], [1., 0., 4.]], dtype=float32)
从 COO 数据和索引创建稀疏数组
>>> data = jnp.array([1., 3., 5.]) >>> indices = jnp.array([[0, 0], ... [1, 1], ... [2, 2]]) >>> mat = BCOO((data, indices), shape=(3, 3)) >>> mat BCOO(float32[3, 3], nse=3) >>> mat.todense() Array([[1., 0., 0.], [0., 3., 0.], [0., 0., 5.]], dtype=float32)
方法
__init__(args, *, shape[, indices_sorted, ...])astype(*args, **kwargs)复制数组并转换为指定的数据类型。
block_until_ready()from_scipy_sparse(mat, *[, index_dtype, ...])从
scipy.sparse数组创建 BCOO 数组。fromdense(mat, *[, nse, index_dtype, ...])从 (密集)
Array创建 BCOO 数组。reshape(*args, **kwargs)返回一个包含相同数据但具有新形状的数组。
sort_indices()返回一个索引已排序的矩阵的副本。
sum(*args, **kwargs)沿轴求和数组。
sum_duplicates([nse, remove_zeros])返回一个累加了重复索引的数组的副本。
todense()创建数组的密集版本。
transpose([axes])创建包含转置的新数组。
tree_flatten()tree_unflatten(aux_data, children)update_layout(*[, n_batch, n_dense, ...])更新 BCOO 矩阵的存储布局(即 n_batch 和 n_dense)。
属性
Tdtypen_batchn_densen_sparsendimnsesizeshapeindices_sortedunique_indices