diff --git a/_modules/arkouda/sparrayclass.html b/_modules/arkouda/sparrayclass.html index fcf2fd236..53c6df507 100644 --- a/_modules/arkouda/sparrayclass.html +++ b/_modules/arkouda/sparrayclass.html @@ -354,7 +354,7 @@
from __future__ import annotations
import builtins
-from typing import Optional, Sequence, Union, cast
+from typing import List, Optional, Sequence, Union, cast
import numpy as np
from typeguard import typechecked
@@ -391,6 +391,8 @@ Source code for arkouda.sparrayclass
The element type of the array
size : int_scalars
The size of any one dimension of the array (all dimensions are assumed to be equal sized for now)
+ nnz: int_scalars
+ The number of non-zero elements in the array
ndim : int_scalars
The rank of the array (currently only rank 2 arrays supported)
shape : Sequence[int]
@@ -426,7 +428,7 @@ Source code for arkouda.sparrayclass
def __del__(self):
try:
- logger.debug(f"deleting pdarray with name {self.name}")
+ logger.debug(f"deleting sparray with name {self.name}")
generic_msg(cmd="delete", args={"name": self.name})
except (RuntimeError, AttributeError):
pass
@@ -445,7 +447,7 @@ Source code for arkouda.sparrayclass
def __getitem__(self, key):
raise NotImplementedError("sparray does not support __getitem__")
- def __str__(self): # This won't work out of the box for sparrays need to add this in later
+ def __str__(self):
from arkouda.client import sparrayIterThresh
return generic_msg(cmd="str", args={"array": self, "printThresh": sparrayIterThresh})
@@ -473,7 +475,7 @@ Source code for arkouda.sparrayclass
[docs]
@typechecked
- def to_pdarray(self):
+ def to_pdarray(self) -> List[pdarray]:
dtype = self.dtype
dtype_name = cast(np.dtype, dtype).name
# check dtype for error
@@ -499,7 +501,7 @@ Source code for arkouda.sparrayclass
generic_msg(
cmd=f"fill_sparse_vals<{self.dtype},2,{self.layout},{a.dtype},1>",
- args={"matrix": self, "vals": a}
+ args={"matrix": self, "vals": a},
)
diff --git a/_modules/arkouda/sparsematrix.html b/_modules/arkouda/sparsematrix.html
index 850bb0c89..bba9b6e2d 100644
--- a/_modules/arkouda/sparsematrix.html
+++ b/_modules/arkouda/sparsematrix.html
@@ -353,16 +353,20 @@
Source code for arkouda.sparsematrix
from __future__ import annotations
+from typing import Union, cast
+
+import numpy as np
from typeguard import typechecked
from arkouda.client import generic_msg
+from arkouda.dtypes import dtype as akdtype
+from arkouda.dtypes import int64
from arkouda.logger import getArkoudaLogger
+from arkouda.numpy.dtypes.dtypes import NumericDTypes
+from arkouda.pdarrayclass import pdarray
from arkouda.sparrayclass import create_sparray, sparray
-from typing import Union
-from arkouda.dtypes import int64
-from arkouda.dtypes import dtype as akdtype
-__all__ = ["random_sparse_matrix", "sparse_matrix_matrix_mult"]
+__all__ = ["random_sparse_matrix", "sparse_matrix_matrix_mult", "create_sparse_matrix"]
logger = getArkoudaLogger(name="sparsematrix")
@@ -447,6 +451,53 @@ Source code for arkouda.sparsematrix
return create_sparray(repMsg)
+
+
+
+[docs]
+def create_sparse_matrix(size: int, rows: pdarray, cols: pdarray, vals: pdarray, layout: str) -> sparray:
+ """
+ Create a sparse matrix from three pdarrays representing the row indices,
+ column indices, and values of the non-zero elements of the matrix.
+
+ Parameters
+ ----------
+ rows : pdarray
+ The row indices of the non-zero elements
+ cols : pdarray
+ The column indices of the non-zero elements
+ vals : pdarray
+ The values of the non-zero elements
+
+ Returns
+ -------
+ sparray
+ A sparse matrix with the specified row and column indices and values
+ """
+ if not (isinstance(rows, pdarray) and isinstance(cols, pdarray) and isinstance(vals, pdarray)):
+ raise TypeError("rows, cols, and vals must be pdarrays for create_sparse_matrix")
+ if not (rows.ndim == 1 and cols.ndim == 1 and vals.ndim == 1):
+ raise ValueError("rows, cols, and vals must be 1D for create_sparse_matrix")
+ if not (rows.size == cols.size and rows.size == vals.size):
+ raise ValueError("rows, cols, and vals must have the same size for create_sparse_matrix")
+ if not (rows.dtype == int64 and cols.dtype == int64):
+ raise ValueError("rows and cols must have dtype int64 for create_sparse_matrix")
+ if layout not in ["CSR", "CSC"]:
+ raise ValueError("layout must be 'CSR' or 'CSC'")
+
+ vals_dtype_name = cast(np.dtype, vals.dtype).name
+ # check dtype for error
+ if vals_dtype_name not in NumericDTypes:
+ raise TypeError(f"unsupported dtype {vals.dtype}")
+
+ shape = (size, size)
+ repMsg = generic_msg(
+ cmd=f"sparse_matrix_from_pdarrays<{vals.dtype},{layout}>",
+ args={"rows": rows.name, "cols": cols.name, "vals": vals.name, "shape": shape},
+ )
+
+ return create_sparray(repMsg)
+
diff --git a/_sources/autoapi/arkouda/index.rst.txt b/_sources/autoapi/arkouda/index.rst.txt
index 4928412cb..c4cc9181c 100644
--- a/_sources/autoapi/arkouda/index.rst.txt
+++ b/_sources/autoapi/arkouda/index.rst.txt
@@ -45837,6 +45837,12 @@ Package Contents
:type: int_scalars
+ .. attribute:: nnz
+
+ The number of non-zero elements in the array
+
+ :type: int_scalars
+
.. attribute:: ndim
The rank of the array (currently only rank 2 arrays supported)
@@ -45889,7 +45895,7 @@ Package Contents
.. py:attribute:: size
- .. py:method:: to_pdarray()
+ .. py:method:: to_pdarray() -> List[arkouda.pdarrayclass.pdarray]
.. py:function:: sqrt(pda: pdarray, where: Union[bool, pdarray] = True) -> pdarray
diff --git a/_sources/autoapi/arkouda/sparrayclass/index.rst.txt b/_sources/autoapi/arkouda/sparrayclass/index.rst.txt
index fe662e875..814df51de 100644
--- a/_sources/autoapi/arkouda/sparrayclass/index.rst.txt
+++ b/_sources/autoapi/arkouda/sparrayclass/index.rst.txt
@@ -68,6 +68,12 @@ Module Contents
:type: int_scalars
+ .. attribute:: nnz
+
+ The number of non-zero elements in the array
+
+ :type: int_scalars
+
.. attribute:: ndim
The rank of the array (currently only rank 2 arrays supported)
@@ -120,6 +126,6 @@ Module Contents
.. py:attribute:: size
- .. py:method:: to_pdarray()
+ .. py:method:: to_pdarray() -> List[arkouda.pdarrayclass.pdarray]
diff --git a/_sources/autoapi/arkouda/sparsematrix/index.rst.txt b/_sources/autoapi/arkouda/sparsematrix/index.rst.txt
index d76f9515f..0a5b04522 100644
--- a/_sources/autoapi/arkouda/sparsematrix/index.rst.txt
+++ b/_sources/autoapi/arkouda/sparsematrix/index.rst.txt
@@ -9,6 +9,7 @@ Functions
.. autoapisummary::
+ arkouda.sparsematrix.create_sparse_matrix
arkouda.sparsematrix.random_sparse_matrix
arkouda.sparsematrix.sparse_matrix_matrix_mult
@@ -16,6 +17,22 @@ Functions
Module Contents
---------------
+.. py:function:: create_sparse_matrix(size: int, rows: arkouda.pdarrayclass.pdarray, cols: arkouda.pdarrayclass.pdarray, vals: arkouda.pdarrayclass.pdarray, layout: str) -> arkouda.sparrayclass.sparray
+
+ Create a sparse matrix from three pdarrays representing the row indices,
+ column indices, and values of the non-zero elements of the matrix.
+
+ :param rows: The row indices of the non-zero elements
+ :type rows: pdarray
+ :param cols: The column indices of the non-zero elements
+ :type cols: pdarray
+ :param vals: The values of the non-zero elements
+ :type vals: pdarray
+
+ :returns: A sparse matrix with the specified row and column indices and values
+ :rtype: sparray
+
+
.. py:function:: random_sparse_matrix(size: int, density: float, layout: str, dtype: Union[type, str] = int64) -> arkouda.sparrayclass.sparray
Create a random sparse matrix with the specified number of rows and columns
diff --git a/autoapi/arkouda/index.html b/autoapi/arkouda/index.html
index b34132f95..0bba41660 100644
--- a/autoapi/arkouda/index.html
+++ b/autoapi/arkouda/index.html
@@ -992,10 +992,10 @@ Classes¶
The class for sparse arrays. This class contains only the
-
+
A unicode string.
-
+
A unicode string.
@@ -1811,10 +1811,10 @@ Functionstanh
(→ arkouda.pdarrayclass.pdarray)
Return the element-wise hyperbolic tangent of the array.
-timedelta_range
([start, end, periods, freq, name, closed])
+timedelta_range
([start, end, periods, freq, name, closed])
Return a fixed frequency TimedeltaIndex, with day as the default
-timedelta_range
([start, end, periods, freq, name, closed])
+timedelta_range
([start, end, periods, freq, name, closed])
Return a fixed frequency TimedeltaIndex, with day as the default
to_csv
(columns, prefix_path[, names, col_delim, overwrite])
@@ -42206,7 +42206,7 @@ Package ContentsReturns:
-- With string data:
False if one array is type ak.str_ & the other isn’t, True if both are ak.str_ & they match.
+- With string data:
False if one array is type ak.str_ & the other isn’t, True if both are ak.str_ & they match.
- With numeric data:
True if neither array has any nan elements, and all elements pairwise equal.
True if equal_Nan True, all non-nans pairwise equal & nans in pda_a correspond to nans in pda_b
@@ -43089,7 +43089,7 @@ Package Contents[1]_. A N-bit two’s-complement
+representing signed integers on computers [1]_. A N-bit two’s-complement
system can represent every integer in the range
\(-2^{N-1}\) to \(+2^{N-1}-1\).
@@ -46282,7 +46282,7 @@ Package Contentssmallest_normal is not actually the smallest positive
representable value in a NumPy floating point type. As in the IEEE-754
-standard [1]_, NumPy floating point types make use of subnormal numbers to
+standard [1]_, NumPy floating point types make use of subnormal numbers to
fill the gap between 0 and smallest_normal
. However, subnormal numbers
may have significantly reduced precision [2].
This function can also be used for complex data types as well. If used,
@@ -58758,7 +58758,7 @@
Package ContentsParameters:
A (pdarray) – Value(s) used when mask is False (see Notes for allowed dtypes)
-mask (pdarray) – Used to choose values from A or B, must be same size as A, and of type ak.bool_
+mask (pdarray) – Used to choose values from A or B, must be same size as A, and of type ak.bool_
Values (pdarray) – Value(s) used when mask is False (see Notes for allowed dtypes)
@@ -58786,10 +58786,10 @@ Package ContentsNotes
A and mask must be the same size. Values can be any size.
Allowed dtypes for A and Values conform to types accepted by numpy putmask.
-If A is ak.float64, Values can be ak.float64, ak.int64, ak.uint64, ak.bool_.
-If A is ak.int64, Values can be ak.int64 or ak.bool_.
-If A is ak.uint64, Values can be ak.int64, ak.uint64, or ak.bool_.
-If A is ak.bool_, Values must be ak.bool_.
+If A is ak.float64, Values can be ak.float64, ak.int64, ak.uint64, ak.bool_.
+If A is ak.int64, Values can be ak.int64 or ak.bool_.
+If A is ak.uint64, Values can be ak.int64, ak.uint64, or ak.bool_.
+If A is ak.bool_, Values must be ak.bool_.
Only one conditional clause is supported e.g., n < 5, n > 1, which is supported in numpy
is not currently supported in Arkouda
Only 1D pdarrays are implemented for now.
@@ -60260,6 +60260,17 @@ Package Contents
+-
+nnz¶
+The number of non-zero elements in the array
+
+- Type:
+-
+
+
+
+
-
ndim¶
@@ -60335,23 +60346,23 @@ Package Contents
--
-nnz¶
+-
+nnz¶
-
-to_pdarray()[source]¶
+to_pdarray() List[arkouda.pdarrayclass.pdarray] [source]¶
@@ -61104,8 +61115,8 @@ Package Contents
-
-class arkouda.str_¶
+
+class arkouda.str_¶
A unicode string.
This type strips trailing null codepoints.
@@ -61133,8 +61144,8 @@ Package Contents
-
-T(*args, **kwargs)¶
+
+T(*args, **kwargs)¶
Scalar attribute identical to the corresponding array attribute.
Please see ndarray.T.
@@ -61142,8 +61153,8 @@ Package Contents
-
-all(*args, **kwargs)¶
+
+all(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.all.
@@ -61151,8 +61162,8 @@ Package Contents
-
-any(*args, **kwargs)¶
+
+any(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.any.
@@ -61160,8 +61171,8 @@ Package Contents
-
-argmax(*args, **kwargs)¶
+
+argmax(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.argmax.
@@ -61169,8 +61180,8 @@ Package Contents
-
-argmin(*args, **kwargs)¶
+
+argmin(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.argmin.
@@ -61178,8 +61189,8 @@ Package Contents
-
-argsort(*args, **kwargs)¶
+
+argsort(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.argsort.
@@ -61187,8 +61198,8 @@ Package Contents
-
-astype(*args, **kwargs)¶
+
+astype(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.astype.
@@ -61196,8 +61207,8 @@ Package Contents
-
-base(*args, **kwargs)¶
+
+base(*args, **kwargs)¶
Scalar attribute identical to the corresponding array attribute.
Please see ndarray.base.
@@ -61205,8 +61216,8 @@ Package Contents
-
-byteswap(*args, **kwargs)¶
+
+byteswap(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.byteswap.
@@ -61214,8 +61225,8 @@ Package Contents
-
-choose(*args, **kwargs)¶
+
+choose(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.choose.
@@ -61223,8 +61234,8 @@ Package Contents
-
-clip(*args, **kwargs)¶
+
+clip(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.clip.
@@ -61232,8 +61243,8 @@ Package Contents
-
-compress(*args, **kwargs)¶
+
+compress(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.compress.
@@ -61241,13 +61252,13 @@ Package Contents
-
-conj(*args, **kwargs)¶
+
+conj(*args, **kwargs)¶
--
-conjugate(*args, **kwargs)¶
+-
+conjugate(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.conjugate.
@@ -61255,8 +61266,8 @@ Package Contents
--
-copy(*args, **kwargs)¶
+-
+copy(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.copy.
@@ -61264,8 +61275,8 @@ Package Contents
--
-cumprod(*args, **kwargs)¶
+-
+cumprod(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.cumprod.
@@ -61273,8 +61284,8 @@ Package Contents
--
-cumsum(*args, **kwargs)¶
+-
+cumsum(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.cumsum.
@@ -61282,14 +61293,14 @@ Package Contents
--
-data(*args, **kwargs)¶
+-
+data(*args, **kwargs)¶
Pointer to start of data.
--
-diagonal(*args, **kwargs)¶
+-
+diagonal(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.diagonal.
@@ -61297,14 +61308,14 @@ Package Contents
--
-dtype(*args, **kwargs)¶
+-
+dtype(*args, **kwargs)¶
Get array data-descriptor.
--
-dump(*args, **kwargs)¶
+-
+dump(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.dump.
@@ -61312,8 +61323,8 @@ Package Contents
--
-dumps(*args, **kwargs)¶
+-
+dumps(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.dumps.
@@ -61321,8 +61332,8 @@ Package Contents
--
-fill(*args, **kwargs)¶
+-
+fill(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.fill.
@@ -61330,20 +61341,20 @@ Package Contents
--
-flags(*args, **kwargs)¶
+-
+flags(*args, **kwargs)¶
The integer value of flags.
--
-flatten(*args, **kwargs)¶
+-
+flatten(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.flatten.
@@ -61351,8 +61362,8 @@ Package Contents
--
-getfield(*args, **kwargs)¶
+-
+getfield(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.getfield.
@@ -61360,14 +61371,14 @@ Package Contents
--
-imag(*args, **kwargs)¶
+-
+imag(*args, **kwargs)¶
The imaginary part of the scalar.
--
-item(*args, **kwargs)¶
+-
+item(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.item.
@@ -61375,8 +61386,8 @@ Package Contents
--
-itemset(*args, **kwargs)¶
+-
+itemset(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.itemset.
@@ -61384,14 +61395,14 @@ Package Contents
--
-itemsize(*args, **kwargs)¶
+-
+itemsize(*args, **kwargs)¶
The length of one element in bytes.
--
-max(*args, **kwargs)¶
+-
+max(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.max.
@@ -61399,8 +61410,8 @@ Package Contents
--
-mean(*args, **kwargs)¶
+-
+mean(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.mean.
@@ -61408,8 +61419,8 @@ Package Contents
--
-min(*args, **kwargs)¶
+-
+min(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.min.
@@ -61417,20 +61428,20 @@ Package Contents
--
-nbytes(*args, **kwargs)¶
+-
+nbytes(*args, **kwargs)¶
The length of the scalar in bytes.
--
-newbyteorder(*args, **kwargs)¶
+-
+newbyteorder(*args, **kwargs)¶
newbyteorder(new_order=’S’, /)
Return a new dtype with a different byte order.
@@ -61457,8 +61468,8 @@ Package Contents
--
-nonzero(*args, **kwargs)¶
+-
+nonzero(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.nonzero.
@@ -61466,8 +61477,8 @@ Package Contents
--
-prod(*args, **kwargs)¶
+-
+prod(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.prod.
@@ -61475,8 +61486,8 @@ Package Contents
--
-ptp(*args, **kwargs)¶
+-
+ptp(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.ptp.
@@ -61484,8 +61495,8 @@ Package Contents
--
-put(*args, **kwargs)¶
+-
+put(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.put.
@@ -61493,8 +61504,8 @@ Package Contents
--
-ravel(*args, **kwargs)¶
+-
+ravel(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.ravel.
@@ -61502,14 +61513,14 @@ Package Contents
--
-real(*args, **kwargs)¶
+-
+real(*args, **kwargs)¶
The real part of the scalar.
--
-repeat(*args, **kwargs)¶
+-
+repeat(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.repeat.
@@ -61517,8 +61528,8 @@ Package Contents
--
-reshape(*args, **kwargs)¶
+-
+reshape(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.reshape.
@@ -61526,8 +61537,8 @@ Package Contents
--
-resize(*args, **kwargs)¶
+-
+resize(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.resize.
@@ -61535,8 +61546,8 @@ Package Contents
--
-round(*args, **kwargs)¶
+-
+round(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.round.
@@ -61544,8 +61555,8 @@ Package Contents
--
-searchsorted(*args, **kwargs)¶
+-
+searchsorted(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.searchsorted.
@@ -61553,8 +61564,8 @@ Package Contents
--
-setfield(*args, **kwargs)¶
+-
+setfield(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.setfield.
@@ -61562,8 +61573,8 @@ Package Contents
--
-setflags(*args, **kwargs)¶
+-
+setflags(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.setflags.
@@ -61571,20 +61582,20 @@ Package Contents
--
-shape(*args, **kwargs)¶
+-
+shape(*args, **kwargs)¶
Tuple of array dimensions.
--
-sort(*args, **kwargs)¶
+-
+sort(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.sort.
@@ -61592,8 +61603,8 @@ Package Contents
--
-squeeze(*args, **kwargs)¶
+-
+squeeze(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.squeeze.
@@ -61601,8 +61612,8 @@ Package Contents
--
-std(*args, **kwargs)¶
+-
+std(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.std.
@@ -61610,14 +61621,14 @@ Package Contents
--
-strides(*args, **kwargs)¶
+-
+strides(*args, **kwargs)¶
Tuple of bytes steps in each dimension.
--
-sum(*args, **kwargs)¶
+-
+sum(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see ndarray.sum.
@@ -61625,8 +61636,8 @@ Package Contents
--
-swapaxes(*args, **kwargs)¶
+-
+swapaxes(*args, **kwargs)¶
Scalar method identical to the corresponding array attribute.
Please see