AlenkaF commented on code in PR #45160:
URL: https://github.com/apache/arrow/pull/45160#discussion_r1903963210
##########
python/pyarrow/tensor.pxi:
##########
@@ -595,7 +595,25 @@ shape: {0.shape}""".format(self)
cdef class SparseCSRMatrix(_Weakrefable):
"""
- A sparse CSR matrix.
+ SparseCSRMatrix represents a sparse matrix in Compressed Sparse Row (CSR)
format.
+
+ Attributes:
+ indptr : array
+ Index pointer array.
+ indices : array
+ Column indices of the corresponding non-zero values.
+ shape : tuple
+ Shape of the matrix.
+ dim_names : list, optional
+ Names of the dimensions.
+
+ Example:
+ >>> import pyarrow as pa
+ >>> indptr = pa.array([0, 2, 3])
+ >>> indices = pa.array([0, 2, 1])
+ >>> shape = (2, 3)
+ >>> tensor = pa.SparseCSRMatrix(indptr, indices, shape)
+ >>> print(tensor)
Review Comment:
Did you meant to use one of the `from_*` methods here?
We do not use `SparseCSRMatrix`'s constructor directly, see:
https://github.com/apache/arrow/blob/ada8750917cd2ec2ae8a605d2673d78ef04c82e4/python/pyarrow/tensor.pxi#L617-L619
Could you change the example to use one of `pyarrow.SparseCSRMatrix.from_*`
functions and also add examples in separate `pyarrow.SparseCSRMatrix.from_*`
functions?
Attributes part should also be removed here (note we use NumPy style
docstrings).
Could we also then add similar examples (with outputs) to other tensor
formats/classes?
##########
docs/source/python/api/tensors.rst:
##########
@@ -0,0 +1,114 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements. See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership. The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied. See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+.. currentmodule:: pyarrow
+
+.. _api.tensor:
+
+Tensors
+=======
+
+PyArrow supports both dense and sparse tensors. Dense tensors store all data
values explicitly, while sparse tensors represent only the non-zero elements
and their locations, making them efficient for storage and computation.
+
+Dense Tensors
+^^^^^^^^^^^^^
+
+.. autosummary::
+ :toctree: ../generated/
+
+ Tensor
+
+Sparse Tensors
+^^^^^^^^^^^^^
+
+PyArrow supports the following sparse tensor formats:
+
+.. autosummary::
+ :toctree: ../generated/
+
+ SparseCOOTensor
+ SparseCSRMatrix
+ SparseCSCMatrix
+ SparseCSFTensor
+
+"""SparseCOOTensor"""
+
+The ``SparseCOOTensor`` represents a sparse tensor in Coordinate (COO) format,
where non-zero elements are stored as tuples of row and column indices.
+
+Example:
+.. code-block:: python
+
+ import pyarrow as pa
+
+ indices = pa.array([[0, 0], [1, 2]])
+ data = pa.array([1, 2])
+ shape = (2, 3)
+
+ tensor = pa.SparseCOOTensor(indices, data, shape)
Review Comment:
We should use one of the `pyarrow.SparseCOOTensor.from_*` functions here and
add the output from the print statement.
##########
docs/source/python/api/tensors.rst:
##########
@@ -0,0 +1,114 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements. See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership. The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License. You may obtain a copy of the License at
+
+.. http://www.apache.org/licenses/LICENSE-2.0
+
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied. See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+.. currentmodule:: pyarrow
+
+.. _api.tensor:
+
+Tensors
+=======
+
+PyArrow supports both dense and sparse tensors. Dense tensors store all data
values explicitly, while sparse tensors represent only the non-zero elements
and their locations, making them efficient for storage and computation.
+
+Dense Tensors
+^^^^^^^^^^^^^
+
+.. autosummary::
+ :toctree: ../generated/
+
+ Tensor
+
+Sparse Tensors
+^^^^^^^^^^^^^
+
+PyArrow supports the following sparse tensor formats:
+
+.. autosummary::
+ :toctree: ../generated/
+
+ SparseCOOTensor
+ SparseCSRMatrix
+ SparseCSCMatrix
+ SparseCSFTensor
+
+"""SparseCOOTensor"""
+
+The ``SparseCOOTensor`` represents a sparse tensor in Coordinate (COO) format,
where non-zero elements are stored as tuples of row and column indices.
Review Comment:
I would add code examples to `docs/source/python/data.rst` and keep the
reference docs cleaner.
We do not have a unified way of writing code blocks,
[unfortunately](https://github.com/apache/arrow/issues/28859). But we do use
prompt characters and add output, see example
https://raw.githubusercontent.com/apache/arrow/refs/heads/main/docs/source/python/numpy.rst.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]