Repository: ivy-llc/ivy

Issue:
Add Sparse Array Functions to Paddle Backend
Add [Sparse Array Functions](https://www.paddlepaddle.org.cn/documentation/docs/en/api/index\_en.html) to Paddle backend

\_

>Please keep in mind that the proper way to link an issue to this list is to comment "- [ ] #issue\_number" while the issue's title only includes the name of the function you've chosen.

\_

## Experimental

- [x] is\_native\_sparse\_array
- [x] native\_sparse\_array
- [x] native\_sparse\_array\_to\_indices\_values\_and\_shape


Discussion:
hiii @MahmoudAshraf97 I am interested to work on this issue 

Hi @Ishaan-Chandak , feel free to pick an unassigned task an d work on it
Hi @MahmoudAshraf97 can you please provide me with some resources so that I get to know a little more about native_sparse_arrays

Hi @Ishaan-Chandak, I don't know other source other than the official docs unfortunately
The paddepaddle branch is private

Resolving patch:
diff --git a/ivy/functional/backends/paddle/experimental/sparse_array.py b/ivy/functional/backends/paddle/experimental/sparse_array.py
--- a/ivy/functional/backends/paddle/experimental/sparse_array.py
+++ b/ivy/functional/backends/paddle/experimental/sparse_array.py
@@ -1,11 +1,26 @@
+import ivy
+from ivy.functional.ivy.experimental.sparse_array import (
+    _verify_coo_components,
+    _verify_csr_components,
+    _is_data_not_indices_values_and_shape,
+)
+from ivy.func_wrapper import (
+    with_unsupported_device_and_dtypes,
+)
 from ivy.utils.exceptions import IvyNotImplementedException
 import paddle
 
+# local
+from .. import backend_version
+
 
 def is_native_sparse_array(x: paddle.Tensor) -> bool:
     return x.is_sparse_coo() or x.is_sparse_csr()
 
 
+@with_unsupported_device_and_dtypes(
+    {"2.4.2 and below": {"cpu": ("int8",)}}, backend_version
+)
 def native_sparse_array(
     data=None,
     *,
@@ -17,9 +32,67 @@ def native_sparse_array(
     values=None,
     dense_shape=None,
     format="coo",
-):
-    raise IvyNotImplementedException()
+) -> paddle.Tensor:
+    format = format.lower()
+
+    if format not in ["coo", "csr"]:
+        raise IvyNotImplementedException(
+            "paddle only supports 'coo' and 'csr' sparse formats."
+        )
+
+    if _is_data_not_indices_values_and_shape(
+        data,
+        coo_indices,
+        crow_indices,
+        col_indices,
+        ccol_indices,
+        row_indices,
+        values,
+        dense_shape,
+    ):
+        ivy.utils.assertions.check_true(
+            ivy.is_native_sparse_array(data), message="not a sparse array"
+        )
+        return data
+
+    if format == "coo":
+        _verify_coo_components(
+            indices=coo_indices, values=values, dense_shape=dense_shape
+        )
+        return paddle.sparse.sparse_coo_tensor(
+            indices=coo_indices,
+            values=values,
+            shape=dense_shape,
+            dtype=dtype,
+            place=device,
+            stop_gradient=not requires_grad,
+        )
+    else:
+        _verify_csr_components(
+            crow_indices=crow_indices,
+            col_indices=col_indices,
+            values=values,
+            dense_shape=dense_shape,
+        )
+        return paddle.sparse.sparse_csr_tensor(
+            crows=crow_indices,
+            cols=col_indices,
+            values=values,
+            shape=dense_shape,
+            dtype=dtype,
+            place=device,
+            stop_gradient=not requires_grad,
+        )
 
 
 def native_sparse_array_to_indices_values_and_shape(x):
-    raise IvyNotImplementedException()
+    if not is_native_sparse_array(x):
+        raise ivy.utils.exceptions.IvyException("not a Paddle Sparse Array")
+    if x.is_sparse_coo():
+        return {"coo_indices": x.indices()}, x.values(), x.shape
+    else:
+        return (
+            {"crow_indices": x.crows(), "col_indices": x.cols()},
+            x.values(),
+            x.shape,
+        )


Test patch: