-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
[numpy] torch.{all, any} : Extend Dtype Support #44790
Changes from 8 commits
72cec9a
1a439cb
34f4786
e98d5ef
07f5c9f
d17199a
039fd5d
ca11c80
1b242ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,41 +232,55 @@ static void norm_kernel_tensor_iterator_impl( | |
} | ||
|
||
static void and_kernel_impl(TensorIterator& iter) { | ||
binary_kernel_reduce_vec( | ||
iter, | ||
[=](uint8_t a, uint8_t b) -> uint8_t { return a && b; }, | ||
[=](Vec256<uint8_t> a, Vec256<uint8_t> b) { | ||
// Adding the implementation here instead of in vec256_base to avoid | ||
// return value inconsistency. Other comparison operators in vec256_base | ||
// return -1/0 (all bit 1 / all bit 0) as true/false to follow the AVX2 | ||
// convention. This would be convenient when combined with other | ||
// vectorized operations. For example, one can use the logical operation | ||
// results as a mask for a bit operation to retrieve/reset multiple | ||
// elements in a vector. | ||
// | ||
// In this method, users would expect, e.g., all(), to return 1/0 as | ||
// true/false. | ||
Vec256<uint8_t> c = Vec256<uint8_t>(); | ||
for (int i = 0; i != Vec256<uint8_t>::size(); i++) { | ||
c[i] = a[i] && b[i]; | ||
} | ||
return c; | ||
}, | ||
/*ident=*/true); | ||
if (c10::isIntegralType(iter.dtype(), /*include_bool=*/true)) { | ||
binary_kernel_reduce_vec( | ||
iter, | ||
[=](uint8_t a, uint8_t b) -> uint8_t { return a && b; }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid the implicit cast with: |
||
[=](Vec256<uint8_t> a, Vec256<uint8_t> b) { | ||
// Adding the implementation here instead of in vec256_base to avoid | ||
// return value inconsistency. Other comparison operators in | ||
// vec256_base return -1/0 (all bit 1 / all bit 0) as true/false to | ||
// follow the AVX2 convention. This would be convenient when combined | ||
// with other vectorized operations. For example, one can use the | ||
// logical operation results as a mask for a bit operation to | ||
// retrieve/reset multiple elements in a vector. | ||
// | ||
// In this method, users would expect, e.g., all(), to return 1/0 as | ||
// true/false. | ||
Vec256<uint8_t> c = Vec256<uint8_t>(); | ||
for (int i = 0; i != Vec256<uint8_t>::size(); i++) { | ||
c[i] = a[i] && b[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid implicit cast with: |
||
} | ||
return c; | ||
}, | ||
/*ident=*/true); | ||
} else { | ||
AT_DISPATCH_FLOATING_TYPES_AND(kHalf, iter.dtype(), "and_kernel", [&]() { | ||
binary_kernel_reduce( | ||
iter, AndOps<scalar_t>(), static_cast<scalar_t>(true)); | ||
}); | ||
} | ||
} | ||
|
||
static void or_kernel_impl(TensorIterator& iter) { | ||
binary_kernel_reduce_vec( | ||
iter, | ||
[=](uint8_t a, uint8_t b) -> uint8_t { return a || b; }, | ||
[=](Vec256<uint8_t> a, Vec256<uint8_t> b) { | ||
Vec256<uint8_t> c = Vec256<uint8_t>(); | ||
for (int i = 0; i != Vec256<uint8_t>::size(); i++) { | ||
c[i] = a[i] || b[i]; | ||
} | ||
return c; | ||
}, | ||
/*ident=*/false); | ||
if (c10::isIntegralType(iter.dtype(), /*include_bool=*/true)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include_bool -> includeBool |
||
binary_kernel_reduce_vec( | ||
iter, | ||
[=](uint8_t a, uint8_t b) -> uint8_t { return a || b; }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid the implicit cast with: |
||
[=](Vec256<uint8_t> a, Vec256<uint8_t> b) { | ||
Vec256<uint8_t> c = Vec256<uint8_t>(); | ||
for (int i = 0; i != Vec256<uint8_t>::size(); i++) { | ||
c[i] = a[i] || b[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid implicit cast with: |
||
} | ||
return c; | ||
}, | ||
/*ident=*/false); | ||
} else { | ||
AT_DISPATCH_FLOATING_TYPES_AND(kHalf, iter.dtype(), "or_kernel", [&]() { | ||
binary_kernel_reduce( | ||
iter, OrOps<scalar_t>(), static_cast<scalar_t>(false)); | ||
}); | ||
} | ||
} | ||
|
||
template<typename scalar_t> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include_bool -> includeBool