:mod:`heat.sparse.arithmetics` ============================== .. py:module:: heat.sparse.arithmetics .. autoapi-nested-parse:: Arithmetic functions for Dcsr_matrices Module Contents --------------- .. function:: add(t1: heat.sparse.dcsx_matrix.DCSR_matrix, t2: heat.sparse.dcsx_matrix.DCSR_matrix, orientation: str = 'row') -> heat.sparse.dcsx_matrix.DCSR_matrix Element-wise addition of values from two operands, commutative. Takes the first and second operand (scalar or :class:`~heat.sparse.DCSR_matrix`) whose elements are to be added as argument and returns a ``DCSR_matrix`` containing the results of element-wise addition of ``t1`` and ``t2``. :param t1: The first operand involved in the addition :type t1: DCSR_matrix :param t2: The second operand involved in the addition :type t2: DCSR_matrix :param orientation: The orientation of the operation. Options: 'row' or 'col' Default: 'row' :type orientation: str, optional .. rubric:: Examples >>> heat_sparse_csr (indptr: tensor([0, 2, 3]), indices: tensor([0, 2, 2]), data: tensor([1., 2., 3.]), dtype=ht.float32, device=cpu:0, split=0) >>> heat_sparse_csr.todense() DNDarray([[1., 0., 2.], [0., 0., 3.]], dtype=ht.float32, device=cpu:0, split=0) >>> sum_sparse = heat_sparse_csr + heat_sparse_csr (or) >>> sum_sparse = ht.sparse.sparse_add(heat_sparse_csr, heat_sparse_csr) >>> sum_sparse (indptr: tensor([0, 2, 3], dtype=torch.int32), indices: tensor([0, 2, 2], dtype=torch.int32), data: tensor([2., 4., 6.]), dtype=ht.float32, device=cpu:0, split=0) >>> sum_sparse.todense() DNDarray([[2., 0., 4.], [0., 0., 6.]], dtype=ht.float32, device=cpu:0, split=0) .. function:: mul(t1: heat.sparse.dcsx_matrix.DCSR_matrix, t2: heat.sparse.dcsx_matrix.DCSR_matrix, orientation: str = 'row') -> heat.sparse.dcsx_matrix.DCSR_matrix Element-wise multiplication (NOT matrix multiplication) of values from two operands, commutative. Takes the first and second operand (scalar or :class:`~heat.sparse.DCSR_matrix`) whose elements are to be multiplied as argument. :param t1: The first operand involved in the multiplication :type t1: DCSR_matrix :param t2: The second operand involved in the multiplication :type t2: DCSR_matrix :param orientation: The orientation of the operation. Options: 'row' or 'col' Default: 'row' :type orientation: str, optional .. rubric:: Examples >>> heat_sparse_csr (indptr: tensor([0, 2, 3]), indices: tensor([0, 2, 2]), data: tensor([1., 2., 3.]), dtype=ht.float32, device=cpu:0, split=0) >>> heat_sparse_csr.todense() DNDarray([[1., 0., 2.], [0., 0., 3.]], dtype=ht.float32, device=cpu:0, split=0) >>> pdt_sparse = heat_sparse_csr * heat_sparse_csr (or) >>> pdt_sparse = ht.sparse.sparse_mul(heat_sparse_csr, heat_sparse_csr) >>> pdt_sparse (indptr: tensor([0, 2, 3]), indices: tensor([0, 2, 2]), data: tensor([1., 4., 9.]), dtype=ht.float32, device=cpu:0, split=0) >>> pdt_sparse.todense() DNDarray([[1., 0., 4.], [0., 0., 9.]], dtype=ht.float32, device=cpu:0, split=0)