-
Notifications
You must be signed in to change notification settings - Fork 3.8k
GH-43352: [Docs][Python] Add all tensor classes documentation #45160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShaiviAgarwal2
wants to merge
8
commits into
apache:main
Choose a base branch
from
ShaiviAgarwal2:fix/tensor-classes-documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8eb2af8
GH-43352: [Docs][Python] Add all tensor classes documentation
ShaiviAgarwal2 b48e1ac
Add tensors.rst and update index.rst to include Tensors documentation
ShaiviAgarwal2 59e8197
apacheGH-43352: [Docs][Python] Add all tensor classes documentation
ShaiviAgarwal2 e3c549e
apacheGH-43352: [Docs][Python] Add all tensor classes documentation
ShaiviAgarwal2 38c0fd3
apacheGH-43352: [Docs][Python] Add all tensor classes documentation
ShaiviAgarwal2 2648f27
Resolved conflicts and merged master into fix/tensor-classes-document…
ShaiviAgarwal2 576207d
resolve conflicts
ShaiviAgarwal2 09831a8
Fix missing newline issue
ShaiviAgarwal2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
^^^^^^^^^^^^^ | ||
ShaiviAgarwal2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. autosummary:: | ||
:toctree: ../generated/ | ||
|
||
Tensor | ||
|
||
Sparse Tensors | ||
^^^^^^^^^^^^^ | ||
|
||
PyArrow supports the following sparse tensor formats: | ||
|
||
.. autosummary:: | ||
:toctree: ../generated/ | ||
|
||
SparseCOOTensor | ||
SparseCSRMatrix | ||
SparseCSCMatrix | ||
SparseCSFTensor | ||
|
||
"""SparseCOOTensor""" | ||
ShaiviAgarwal2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The ``SparseCOOTensor`` represents a sparse tensor in Coordinate (COO) format, where non-zero elements are stored as tuples of row and column indices. | ||
ShaiviAgarwal2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
ShaiviAgarwal2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(tensor.to_dense()) | ||
|
||
"""SparseCSRMatrix""" | ||
|
||
The ``SparseCSRMatrix`` represents a sparse matrix in Compressed Sparse Row (CSR) format. This format is useful for matrix-vector multiplication. | ||
|
||
Example: | ||
.. code-block:: python | ||
|
||
import pyarrow as pa | ||
|
||
data = pa.array([1, 2, 3]) | ||
indptr = pa.array([0, 2, 3]) | ||
indices = pa.array([0, 2, 1]) | ||
shape = (2, 3) | ||
|
||
sparse_matrix = pa.SparseCSRMatrix.from_numpy(data, indptr, indices, shape) | ||
print(sparse_matrix) | ||
|
||
"""SparseCSCMatrix""" | ||
|
||
The ``SparseCSCMatrix`` represents a sparse matrix in Compressed Sparse Column (CSC) format, where data is stored by columns. | ||
|
||
Example: | ||
.. code-block:: python | ||
|
||
import pyarrow as pa | ||
|
||
data = pa.array([1, 2, 3]) | ||
indptr = pa.array([0, 1, 3]) | ||
indices = pa.array([0, 1, 2]) | ||
shape = (3, 2) | ||
|
||
sparse_matrix = pa.SparseCSCMatrix.from_numpy(data, indptr, indices, shape) | ||
print(sparse_matrix) | ||
|
||
"""SparseCSFTensor""" | ||
|
||
The ``SparseCSFTensor`` represents a sparse tensor in Compressed Sparse Fiber (CSF) format, which is a generalization of the CSR format for higher dimensions. | ||
|
||
Example: | ||
.. code-block:: python | ||
|
||
import pyarrow as pa | ||
|
||
data = pa.array([1, 2, 3]) | ||
indptr = [pa.array([0, 1, 3]), pa.array([0, 2, 3])] | ||
indices = [pa.array([0, 1]), pa.array([0, 1, 2])] | ||
shape = (2, 3, 2) | ||
|
||
sparse_tensor = pa.SparseCSFTensor.from_numpy(data, indptr, indices, shape) | ||
print(sparse_tensor) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.