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

sign function #99

Merged
merged 4 commits into from
Feb 2, 2017
Merged

sign function #99

merged 4 commits into from
Feb 2, 2017

Conversation

wolfv
Copy link
Member

@wolfv wolfv commented Feb 1, 2017

Behaves equivalent to numpy's sign function.

@SylvainCorlay
Copy link
Member

Since #85 was merged, this needs to be rebased on master and use the new pattern for ufuncs.

-> detail::get_xfunction_free_type<E>
{
using functor_type = detail::mf_type<E>;
return detail::make_xfunction((functor_type)detail::sign_impl, e.derived_cast());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.derived_cast -> std::forward<E>(e)

{
return std::numeric_limits<T>::quiet_NaN();
}
return x == 0 ? copysign(T(0), x) : copysign(T(1), x);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what causes the windows failure. One cannot have multiple return statements in a constexpr function. So this leaves you with

return std::isnan(x)? std::numeric_limits<T>::quiet_NaN() : (x == 0 ? copysign(T(0), x) : copysign(T(1), x));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the statement about isnan required?

Would the last statement suffice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to remove the constexpr, but I guess going with your solution will work as well.

The isnan is what numpy is doing. Not sure if required.

You can decide! ;)

@SylvainCorlay
Copy link
Member

I think that it would make sense for me to squash these few commits together while merging.

@wolfv
Copy link
Member Author

wolfv commented Feb 2, 2017 via email

@SylvainCorlay SylvainCorlay merged commit 3a44789 into xtensor-stack:master Feb 2, 2017
@wolfv wolfv deleted the sign_fn branch February 6, 2017 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants