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
Change function signature T Inverse()
to std::optional<T> Inverse()
#76
Comments
hey i can take this up |
@saliaku Oh thanks :) That would be awesome! If you have any questions on this, please feel free to ask us. |
@chokobole can you tell me which files to work on so that it would be easier for me to work |
The tachyon/tachyon/math/base/groups.h Lines 79 to 86 in c6c7f83
My idea is to change the content as follows. // Inverse: a⁻¹
template <
typename G2 = G,
std::enable_if_t<internal::SupportsInverseInPlace<G2>::value>* = nullptr>
[[nodiscard]] constexpr bool Inverse(G* inverse) const {
*inverse = *static_cast<const G*>(this);
return inverse->InverseInPlace();
} Then it turns out you need to change all the Then you need to change tachyon/tachyon/math/finite_fields/prime_field.h Lines 244 to 248 in c6c7f83
constexpr bool InverseInPlace() {
return value_.template MontgomeryInverse<Config::kModulusHasSpareBit>(
Config::kModulus, Config::kMontgomeryR2, &value_);
} Then it continues to tachyon/tachyon/math/base/big_int.h Lines 732 to 805 in c6c7f83
Here there is a template <bool ModulusHasSpareBit>
constexpr bool MontgomeryInverse(const BigInt& modulus,
const BigInt& r2, BigInt* inverse) const {
// See https://github.com/kroma-network/tachyon/issues/76
if (IsZero()) return false;
// ...
if (u.IsOne()) {
*inverse = b;
} else {
*inverse = c;
}
return true;
} I think this is a just start and if you compile this with the change above, you'll face many compile error because of the changing return type of |
The trade-off is other than this |
T Inverse()
to bool Inverse(T*)
T Inverse()
to std::optional<T> Inverse()
Issue type
Feature Request
Current behavior?
Currently
Inverse()
method returns a inverse and panics if failed usingCHECK()
. But this isn't GPU interoperable code. So I suggest it to change it to returnstd::optional<T>
when it failed.Expected Behavior?
Returns false if failed and true and populates the
out
parameter.The text was updated successfully, but these errors were encountered: