Skip to content

Commit

Permalink
ndarray: remap hyperbolic function (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Dec 15, 2017
1 parent 27c66ec commit bfb1cc4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@
* `arccos(x)` -> `acos.(x)`
* `arctan(x)` -> `atan.(x)`

* Please use dot-call on following hyperbolic functions.
Also, the `arc*` has been renamed to keep consistent with `Base`.
(#TBD)

* `sinh.(x)`
* `cosh.(x)`
* `tanh.(x)`
* `arcsinh(x)` -> `asinh.(x)`
* `arccosh(x)` -> `acosh.(x)`
* `arctanh(x)` -> `atanh.(x)`

# v0.3.0 (2017.11.16)

Expand Down
7 changes: 7 additions & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
@deprecate arcsin(x::NDArray) asin.(x)
@deprecate arccos(x::NDArray) acos.(x)
@deprecate arctan(x::NDArray) atan.(x)

@deprecate sinh(x::NDArray) sinh.(x)
@deprecate cosh(x::NDArray) cosh.(x)
@deprecate tanh(x::NDArray) tanh.(x)
@deprecate arcsinh(x::NDArray) asinh.(x)
@deprecate arccosh(x::NDArray) acosh.(x)
@deprecate arctanh(x::NDArray) atanh.(x)
16 changes: 16 additions & 0 deletions src/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,14 @@ _mxsig[:reshape] = :(reshape(arr; shape = dim, reverse = !reverse))
@_remap broadcast_(::typeof(acos), x::NDArray) arccos(x)
@_remap broadcast_(::typeof(atan), x::NDArray) arctan(x)

# hyperbolic funcs, remap to keep consistent with Base
@_remap broadcast_(::typeof(sinh), x::NDArray) sinh(x)
@_remap broadcast_(::typeof(cosh), x::NDArray) cosh(x)
@_remap broadcast_(::typeof(tanh), x::NDArray) tanh(x)
@_remap broadcast_(::typeof(asinh), x::NDArray) arcsinh(x)
@_remap broadcast_(::typeof(acosh), x::NDArray) arccosh(x)
@_remap broadcast_(::typeof(atanh), x::NDArray) arctanh(x)

################################################################################
# remapping to solving type unstablility
################################################################################
Expand Down Expand Up @@ -1275,6 +1283,14 @@ const _op_import_bl = [ # import black list; do not import these funcs
"arcsin",
"arccos",
"arctan",

# hyperbolic
"sinh",
"cosh",
"tanh",
"arcsinh",
"arccosh",
"arctanh",
]

macro _import_ndarray_functions()
Expand Down
27 changes: 27 additions & 0 deletions test/unittest/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,32 @@ function test_trigonometric()
end
end # function test_trigonometric

function check_hyperbolic(f, A)
info("NDArray::$f")
let x = NDArray(A)
B = f.(A)
y = f.(x)
@test copy(y) B
end

let A = Float32.(A), x = NDArray(A)
B = f.(A)
y = f.(x)
@test copy(y) B
end
end # function check_hyperbolic

function test_hyperbolic()
for f [sinh, cosh, tanh, asinh, acosh, atanh]
A = if f == acosh
[1.1, 1.2, 1.3, 1.4]
else
[.1, .2, .3, .4]
end
check_hyperbolic(f, A)
end
end # function test_hyperbolic

################################################################################
# Run tests
################################################################################
Expand Down Expand Up @@ -875,6 +901,7 @@ end # function test_trigonometric
test_show()
test_size()
test_trigonometric()
test_hyperbolic()
end

end

0 comments on commit bfb1cc4

Please sign in to comment.