sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.34k stars 453 forks source link

Support for sparse tensors #35383

Open akanksha2305 opened 1 year ago

akanksha2305 commented 1 year ago

Is there an existing issue for this?

Problem Description

Sparse tensors are a common occurrence in applications such as graph theory, signal processing, and machine learning, as they often have a large number of zero entries. However, the current implementation of the Tensor module in SageMath does not have support for sparse tensors, making it inefficient for working with large sparse datasets. This can cause performance issues when dealing with these types of datasets, as the computations are not optimized for sparse tensors. Therefore, adding support for sparse tensors in the Tensor module would be beneficial to improve the efficiency of SageMath when working with large sparse datasets.

Proposed Solution

To add support for sparse tensors in the Tensor module of SageMath, we can extend the existing Tensor class to include the ability to handle sparse tensors. One possible approach would be to utilize the sparse matrix formats provided by SciPy, such as COO (Coordinate format) or CSR (Compressed Sparse Row) matrices, to store the data in a compressed format that only includes the non-zero entries.

We can define a new SparseTensor class that extends the Tensor class and takes as input the non-zero data, the corresponding indices, and the shape of the sparse tensor. The SparseTensor class can have methods to convert between the sparse matrix format and the Tensor format, as well as to perform operations on sparse tensors, such as addition, multiplication, and dot product. Additionally, visualization tools could be added to help users visualize sparse tensors and better understand their structure.

By adding support for sparse tensors in the Tensor module, SageMath can more efficiently handle large sparse datasets commonly found in applications such as graph theory, signal processing, and machine learning. This will improve the performance of SageMath when dealing with sparse tensors, making it a more effective tool for these applications.

Alternatives Considered

An alternative solution to adding support for sparse tensors in the Tensor module of SageMath would be to utilize an external library that specializes in handling sparse tensors. For example, the PyTorch library has built-in support for sparse tensors, and it is widely used in machine learning applications.

Additional Information

No response

Bharat1241 commented 1 year ago

Problem Solution

If you have searched for existing bug reports and did not find any that match your issue, then you can go ahead and file a new bug report. Here are some tips on how to do it effectively:

Provide a clear and concise summary of the problem in the title of the bug report.

Describe the problem in detail, including any steps to reproduce it. The more information you can provide, the better.

Include information about your environment, such as the operating system, browser, and version numbers.

If possible, provide a screenshot or video recording of the problem to help the developers understand the issue better.

Use a descriptive and informative language, but avoid using technical jargon unless it's necessary.

Check the bug tracker guidelines to make sure you follow the proper format and style.

Be patient and responsive when developers ask for more information or clarification about the issue.

By following these tips, you can increase the chances of your bug report getting addressed in a timely manner.

mkoeppe commented 1 year ago

[...] we can extend the existing Tensor class [...]

Can you edit the issue description to be more specific regarding the class(es) / module(s) that you are targeting? Likewise, please link to specific pages in the documentation of the libraries that you plan to use.