Skip to content

Commit

Permalink
Overload np.exp
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 committed Mar 19, 2022
1 parent ae82240 commit ba041ff
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions integration_tests/test_numpy_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def arange(n: i32) -> i64[n]:
A[i] = i
return A

#: sqrt() as a generic procedure.
#: supported types for argument:
#: i32, i64, f32, f64, bool
@overload
def sqrt(n: i32) -> f64:
return n**(1/2)
Expand All @@ -55,14 +58,32 @@ def sqrt(b: bool) -> f64:
else:
return 0.0

#: exp() as a generic procedure.
#: supported types for argument:
#: i32, i64, f32, f64, bool
@overload
def exp(n: i32) -> f64:
return e**n

@overload
def exp(n: i64) -> f64:
return e**n

@overload
def exp(f: f32) -> f32:
return e**f

@overload
def exp(f: f64) -> f64:
return e**f

@overload
def exp(b: bool) -> f64:
if b:
return 2.719
else:
return 1.0

@overload
def fabs(f: f64) -> f64:
if f < 0.0:
Expand Down Expand Up @@ -142,6 +163,16 @@ def test_exp():
eps = 1e-12
assert abs(a - 403.4287934927351) < eps
assert abs(a2 - 270.42640742615254) < eps
assert abs(exp(True) - 2.719) < eps

i: i64
i = 4
a = exp(i)
assert abs(a - 54.598150033144236) < eps

f: f32
f = -4.0
print(exp(f))

def test_fabs():
a: f64
Expand Down

0 comments on commit ba041ff

Please sign in to comment.