{}, error_spec_);
}
-XLA_TEST_F(ArrayElementwiseOpTest, NegConstantS64) {
- ComputationBuilder builder(client_, TestName());
- auto a = builder.ConstantR1<int64>({
- -1,
- 1,
- 0,
- 0x12345678,
- static_cast<int64>(0xffffffff12345678l),
- static_cast<int64>(0x8000000000000000LL),
- static_cast<int64>(0x8000000000000001LL),
- });
- auto result = builder.Neg(a);
- LOG(INFO) << -static_cast<int64>(0x7FFFFFFFFFFFFFFFLL);
-
- ComputeAndCompareR1<int64>(&builder,
- {
- 1,
- -1,
- 0,
- -0x12345678,
- 0xedcba988,
- static_cast<int64>(0x8000000000000000LL),
- -static_cast<int64>(0x8000000000000001LL),
- },
- {});
-}
-
XLA_TEST_F(ArrayElementwiseOpTest, IsFiniteZeroElementF32s) {
ComputationBuilder builder(client_, TestName());
auto a = builder.ConstantR1<float>({});
ComputeAndCompareR1<complex64>(&builder, {}, {}, error_spec_);
}
-XLA_TEST_F(ArrayElementwiseOpTest, AddTwoConstantU64s) {
- ComputationBuilder b(client_, TestName());
-
- std::vector<uint64> lhs{0xFFFFFFFF,
- static_cast<uint64>(-1),
- 0,
- 0,
- 0x7FFFFFFFFFFFFFFFLL,
- 0x7FFFFFFFFFFFFFFLL,
- 0x8000000000000000LL,
- 0x8000000000000000LL,
- 1};
- std::unique_ptr<Literal> lhs_literal = Literal::CreateR1<uint64>({lhs});
- auto lhs_param = b.Parameter(0, lhs_literal->shape(), "lhs_param");
- std::unique_ptr<GlobalData> lhs_data =
- client_->TransferToServer(*lhs_literal).ConsumeValueOrDie();
-
- std::vector<uint64> rhs{1,
- 0x7FFFFFFFFFFFFFFLL,
- 0x7FFFFFFFFFFFFFFFLL,
- 0x8000000000000000LL,
- 0,
- static_cast<uint64>(-1),
- 0,
- 1,
- 0x8000000000000000LL};
- std::unique_ptr<Literal> rhs_literal = Literal::CreateR1<uint64>({rhs});
- auto rhs_param = b.Parameter(1, rhs_literal->shape(), "rhs_param");
- std::unique_ptr<GlobalData> rhs_data =
- client_->TransferToServer(*rhs_literal).ConsumeValueOrDie();
-
- auto add = b.Add(lhs_param, rhs_param);
-
- std::vector<uint64> expected(lhs.size());
- for (int64 i = 0; i < lhs.size(); ++i) {
- expected[i] = lhs[i] + rhs[i];
- }
-
- ComputeAndCompareR1<uint64>(&b, expected, {lhs_data.get(), rhs_data.get()});
-}
-
-XLA_TEST_F(ArrayElementwiseOpTest, SubTwoConstantS64s) {
- ComputationBuilder b(client_, TestName());
-
- std::vector<int64> lhs{static_cast<int64>(0x8000000000000000LL),
- static_cast<int64>(0x8000000000000000LL),
- -1,
- 0x7FFFFFFFFFFFFFFLL,
- 0x7FFFFFFFFFFFFFFFLL,
- 1,
- 0,
- -1};
- std::unique_ptr<Literal> lhs_literal = Literal::CreateR1<int64>({lhs});
- auto lhs_param = b.Parameter(0, lhs_literal->shape(), "lhs_param");
- std::unique_ptr<GlobalData> lhs_data =
- client_->TransferToServer(*lhs_literal).ConsumeValueOrDie();
-
- std::vector<int64> rhs{-1,
- 0,
- static_cast<int64>(0x8000000000000000LL),
- 1,
- 0,
- 0x7FFFFFFFFFFFFFFLL,
- 0x7FFFFFFFFFFFFFFFLL,
- 0x7FFFFFFFFFFFFFFFLL};
- std::unique_ptr<Literal> rhs_literal = Literal::CreateR1<int64>({rhs});
- auto rhs_param = b.Parameter(1, rhs_literal->shape(), "rhs_param");
- std::unique_ptr<GlobalData> rhs_data =
- client_->TransferToServer(*rhs_literal).ConsumeValueOrDie();
-
- auto sub = b.Sub(lhs_param, rhs_param);
-
- std::vector<int64> expected(lhs.size());
- for (int64 i = 0; i < lhs.size(); ++i) {
- expected[i] = lhs[i] - rhs[i];
- }
-
- ComputeAndCompareR1<int64>(&b, expected, {lhs_data.get(), rhs_data.get()});
-}
-
TEST_P(ArrayElementwiseOpTestParamCount, AddManyValues) {
const int count = GetParam();
ComputationBuilder builder(client_, TestName());
XLA_TEST_F(ConvertTest, ConvertR1S64ToR1F32) {
ComputationBuilder builder(client_, TestName());
- std::vector<int64> arg{
- -9223371216516022272,
- -2,
- -1,
- -0x7FFFFFFF,
- -0x80000000,
- 0,
- 1,
- 2,
- 1073742145,
- 1073742656,
- 0x7FFFFFFF,
- 0x80000000,
- 826720496944058148,
- 4296062029846194332,
- 0x0007FB72E4000000LL,
- 0x0007FB72E4000001LL,
- 0x0007FB72E6000000LL,
- 0x0007FB72E7000000LL,
- 0x0007FB72E7FFFFFFLL,
- 0x0007FB72E8000000LL,
- 0x0007FB72E8000001LL,
- 0x0007FB72EA000000LL,
- 0x0007FB72EB000000LL,
- 0x0007FB72EBFFFFFFLL,
- 0x0007FB72EC000000LL,
- 0x7FFFFF0000000000LL,
- 0x7FFFFF8000000000LL,
- 0x7FFFFFFFFFFFFF00,
- static_cast<int64>(0xFFFFFFFFFFFFFFFF),
- static_cast<int64>(0x0000f234e67e0001LL),
- static_cast<int64>(0x8000000000000000),
- static_cast<int64>(0x8000000000000000LL),
- static_cast<int64>(0x8000000000000001LL),
- static_cast<int64>(0x8000008000000000LL),
- static_cast<int64>(0x8000010000000000LL),
- };
- std::unique_ptr<Literal> arg_literal = Literal::CreateR1<int64>({arg});
- auto arg_param = builder.Parameter(0, arg_literal->shape(), "arg_param");
- std::unique_ptr<GlobalData> arg_data =
- client_->TransferToServer(*arg_literal).ConsumeValueOrDie();
-
- builder.ConvertElementType(arg_param, F32);
-
- std::vector<float> expected(arg.size());
- for (int64 i = 0; i < arg.size(); ++i) {
- expected[i] = static_cast<float>(arg[i]);
- }
- ComputeAndCompareR1<float>(&builder, expected, {arg_data.get()});
-}
+ auto a = builder.ConstantR1<int64>({32, 64});
+ builder.ConvertElementType(a, F32);
-XLA_TEST_F(ConvertTest, ConvertR1U32ToR1F32) {
- ComputationBuilder builder(client_, TestName());
- std::vector<uint32> arg{0, 1, 0x1000, 0x7fffffff,
- 0x80000000, 0x80000001, 0x80000002, 0xFFFFFFFF};
- std::unique_ptr<Literal> arg_literal = Literal::CreateR1<uint32>({arg});
- auto arg_param = builder.Parameter(0, arg_literal->shape(), "arg_param");
- std::unique_ptr<GlobalData> arg_data =
- client_->TransferToServer(*arg_literal).ConsumeValueOrDie();
-
- builder.ConvertElementType(arg_param, F32);
-
- std::vector<float> expected(arg.size());
- for (int64 i = 0; i < arg.size(); ++i) {
- expected[i] = static_cast<float>(arg[i]);
- }
- ComputeAndCompareR1<float>(&builder, expected, {arg_data.get()});
+ std::vector<float> expected = {32.0, 64.0};
+ ComputeAndCompareR1<float>(&builder, expected, {});
}
XLA_TEST_F(ConvertTest, ConvertR1U8ToR1F32) {