Skip to content
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

Causes error in registration of cumsum and cumprod functions #3892

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 66 additions & 82 deletions arkouda/numpy/_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from typing import TYPE_CHECKING, List, Sequence, Tuple, TypeVar, Union
from typing import cast as type_cast
from typing import no_type_check

from arkouda.groupbyclass import groupable
import numpy as np
from typeguard import typechecked

from arkouda.client import generic_msg
from arkouda.dtypes import str_ as akstr_
from arkouda.groupbyclass import GroupBy, groupable
from arkouda.groupbyclass import GroupBy
from arkouda.numpy.dtypes import DTypes, bigint
from arkouda.numpy.dtypes import bool_ as ak_bool
from arkouda.numpy.dtypes import dtype as akdtype
Expand All @@ -26,13 +26,7 @@
from arkouda.numpy.dtypes import _datatype_check
from arkouda.pdarrayclass import all as ak_all
from arkouda.pdarrayclass import any as ak_any
from arkouda.pdarrayclass import (
argmax,
broadcast_if_needed,
create_pdarray,
pdarray,
sum,
)
from arkouda.pdarrayclass import argmax, broadcast_if_needed, create_pdarray, pdarray, sum
from arkouda.pdarraycreation import array, linspace, scalar_array
from arkouda.sorting import sort
from arkouda.strings import Strings
Expand Down Expand Up @@ -119,7 +113,6 @@ def _merge_where(new_pda, where, ret):
new_pda[where] = ret
return new_pda


@typechecked
def cast(
pda: Union[pdarray, Strings, Categorical], # type: ignore
Expand Down Expand Up @@ -249,10 +242,9 @@ def abs(pda: pdarray) -> pdarray:
array([5, 4, 3, 2, 1])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"abs<{pda.dtype},{pda.ndim}>",
args={
"func": "abs",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -282,10 +274,10 @@ def ceil(pda: pdarray) -> pdarray:
>>> ak.ceil(ak.linspace(1.1,5.5,5))
array([2, 3, 4, 5, 6])
"""
_datatype_check(pda.dtype, [float], 'ceil')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"ceil<{pda.dtype},{pda.ndim}>",
args={
"func": "ceil",
"array": pda,
},
)
Expand Down Expand Up @@ -316,11 +308,11 @@ def floor(pda: pdarray) -> pdarray:
>>> ak.floor(ak.linspace(1.1,5.5,5))
array([1, 2, 3, 4, 5])
"""
_datatype_check(pda.dtype, [float], 'floor')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"floor<{pda.dtype},{pda.ndim}>",
args={
"func": "floor",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -350,11 +342,11 @@ def round(pda: pdarray) -> pdarray:
>>> ak.round(ak.array([1.1, 2.5, 3.14159]))
array([1, 3, 3])
"""
_datatype_check(pda.dtype, [float], 'round')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"round<{pda.dtype},{pda.ndim}>",
args={
"func": "round",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -384,15 +376,17 @@ def trunc(pda: pdarray) -> pdarray:
>>> ak.trunc(ak.array([1.1, 2.5, 3.14159]))
array([1, 2, 3])
"""
_datatype_check(pda.dtype, [float], 'trunc')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"trunc<{pda.dtype},{pda.ndim}>",
args={
"func": "trunc",
"array": pda,
},
)
return create_pdarray(type_cast(str, repMsg))

# Noted during Sept 2024 rewrite of EfuncMsg.chpl -- although it's "sign" here, inside the
# chapel code, it's "sgn"

@typechecked
def sign(pda: pdarray) -> pdarray:
Expand All @@ -418,11 +412,11 @@ def sign(pda: pdarray) -> pdarray:
>>> ak.sign(ak.array([-10, -5, 0, 5, 10]))
array([-1, -1, 0, 1, 1])
"""
_datatype_check(pda.dtype, [int, float], 'sign')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"sgn<{pda.dtype},{pda.ndim}>",
args={
"func": "sign",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -456,10 +450,9 @@ def isfinite(pda: pdarray) -> pdarray:
array([True, True, False])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"isfinite<{pda.ndim}>",
args={
"func": "isfinite",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -493,10 +486,9 @@ def isinf(pda: pdarray) -> pdarray:
array([False, False, True])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"isinf<{pda.ndim}>",
args={
"func": "isinf",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -539,10 +531,9 @@ def isnan(pda: pdarray) -> pdarray:
raise TypeError("isnan only supports pdarray of numeric type.")

repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"isnan<{pda.ndim}>",
args={
"func": "isnan",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -586,82 +577,78 @@ def log(pda: pdarray) -> pdarray:
array([0, 3.3219280948873626, 6.6438561897747253])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"log<{pda.dtype},{pda.ndim}>",
args={
"func": "log",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))


@typechecked
def log10(x: pdarray) -> pdarray:
def log10(pda: pdarray) -> pdarray:
"""
Return the element-wise base 10 log of the array.

Parameters
__________
x : pdarray
array to compute on
pda : pdarray
array to compute on

Returns
_______
pdarray contain values of the base 10 log
"""
repMsg = generic_msg(
cmd=f"efunc{x.ndim}D",
cmd=f"log10<{pda.dtype},{pda.ndim}>",
args={
"func": "log10",
"array": x,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))


@typechecked
def log2(x: pdarray) -> pdarray:
def log2(pda: pdarray) -> pdarray:
"""
Return the element-wise base 2 log of the array.

Parameters
__________
x : pdarray
array to compute on
pda : pdarray
array to compute on

Returns
_______
pdarray contain values of the base 2 log
"""
repMsg = generic_msg(
cmd=f"efunc{x.ndim}D",
cmd=f"log2<{pda.dtype},{pda.ndim}>",
args={
"func": "log2",
"array": x,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))


@typechecked
def log1p(x: pdarray) -> pdarray:
def log1p(pda: pdarray) -> pdarray:
"""
Return the element-wise natural log of one plus the array.

Parameters
__________
x : pdarray
array to compute on
pda : pdarray
array to compute on

Returns
_______
pdarray contain values of the natural log of one plus the array
"""
repMsg = generic_msg(
cmd=f"efunc{x.ndim}D",
cmd=f"log1p<{pda.dtype},{pda.ndim}>",
args={
"func": "log1p",
"array": x,
"pda": pda,
},
)
return create_pdarray(repMsg)
Expand Down Expand Up @@ -697,10 +684,9 @@ def exp(pda: pdarray) -> pdarray:
33.494295836924771, 13.478894913238722])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"exp<{pda.dtype},{pda.ndim}>",
args={
"func": "exp",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -736,10 +722,9 @@ def expm1(pda: pdarray) -> pdarray:
32.494295836924771, 12.478894913238722])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"expm1<{pda.dtype},{pda.ndim}>",
args={
"func": "expm1",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -771,10 +756,9 @@ def square(pda: pdarray) -> pdarray:
array([1, 4, 9, 16])
"""
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"square<{pda.dtype},{pda.ndim}>",
args={
"func": "square",
"array": pda,
"pda": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -815,11 +799,11 @@ def cumsum(pda: pdarray) -> pdarray:
>>> ak.cumsum(ak.randint(0, 1, 5, dtype=ak.bool_))
array([0, 1, 1, 2, 3])
"""
_datatype_check(pda.dtype, [int, float, ak_uint64, ak_bool], 'cumsum')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"cumsum<{pda.dtype},{pda.ndim}>",
args={
"func": "cumsum",
"array": pda,
"x": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -857,11 +841,11 @@ def cumprod(pda: pdarray) -> pdarray:
array([1.5728783400481925, 7.0472855509390593, 33.78523998586553,
134.05309592737584, 450.21589865655358])
"""
_datatype_check(pda.dtype, [int, float, ak_uint64, ak_bool], 'cumprod')
repMsg = generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"cumprod<{pda.dtype},{pda.ndim}>",
args={
"func": "cumprod",
"array": pda,
"x": pda,
},
)
return create_pdarray(type_cast(str, repMsg))
Expand Down Expand Up @@ -1373,7 +1357,7 @@ def rad2deg(pda: pdarray, where: Union[bool, pdarray] = True) -> pdarray:
elif where is False:
return pda
else:
return _merge_where(pda[:], where, 180 * (pda[where] / np.pi))
return _merge_where(pda[:], where, 180*(pda[where]/np.pi))


@typechecked
Expand Down Expand Up @@ -1405,7 +1389,7 @@ def deg2rad(pda: pdarray, where: Union[bool, pdarray] = True) -> pdarray:
elif where is False:
return pda
else:
return _merge_where(pda[:], where, (np.pi * pda[where] / 180))
return _merge_where(pda[:], where, (np.pi*pda[where]/180))


def _hash_helper(a):
Expand Down Expand Up @@ -1532,13 +1516,14 @@ def hash(
def _hash_single(pda: pdarray, full: bool = True):
if pda.dtype == bigint:
return hash(pda.bigint_to_uint_arrays())
_datatype_check (pda.dtype, [float, int, ak_uint64], 'hash')
hname = "hash128" if full else "hash64"
repMsg = type_cast(
str,
generic_msg(
cmd=f"efunc{pda.ndim}D",
cmd=f"{hname}<{pda.dtype},{pda.ndim}>",
args={
"func": "hash128" if full else "hash64",
"array": pda,
"x": pda,
},
),
)
Expand Down Expand Up @@ -2599,19 +2584,18 @@ def matmul(pdaLeft: pdarray, pdaRight: pdarray):
"""
if pdaLeft.ndim != pdaRight.ndim:
raise ValueError("matmul requires matrices of matching rank.")

cmd = f"matmul<{pdaLeft.dtype},{pdaRight.dtype},{pdaLeft.ndim}>"
args = {
"x1": pdaLeft,
"x2": pdaRight,
}
repMsg = generic_msg(
cmd=cmd,
args=args,
return create_pdarray(
generic_msg(
cmd=cmd,
args=args,
)
)

return create_pdarray(repMsg)


def vecdot(x1: pdarray, x2: pdarray):
"""
Expand Down
Loading