1 #include <gtest/gtest.h> 10 Tensor foo = rand({12, 12});
13 auto foo_a = foo.accessor<float, 2>();
16 for (
int i = 0; i < foo_a.size(0); i++) {
20 ASSERT_FLOAT_EQ(foo.trace().item<
float>(), trace);
27 auto foo = rand({12, 6});
29 ASSERT_EQ(foo.size(0), 12);
30 ASSERT_EQ(foo.size(1), 6);
36 float b = a.to<
float>();
39 foo = (foo * foo) == (foo.pow(3));
42 auto foo_v = foo.accessor<uint8_t, 2>();
44 for (
int i = 0; i < foo_v.size(0); i++) {
45 for (
int j = 0; j < foo_v.size(1); j++) {
50 ASSERT_TRUE(foo.equal(4 * ones({12, 6}, kByte)));
54 float data[] = {1, 2, 3, 4, 5, 6};
56 auto f = CPU(kFloat).tensorFromBlob(data, {1, 2, 3});
57 auto f_a = f.accessor<float, 3>();
59 ASSERT_EQ(f_a[0][0][0], 1.0);
60 ASSERT_EQ(f_a[0][1][1], 5.0);
62 ASSERT_EQ(f.strides()[0], 6);
63 ASSERT_EQ(f.strides()[1], 3);
64 ASSERT_EQ(f.strides()[2], 1);
65 ASSERT_EQ(f.sizes()[0], 1);
66 ASSERT_EQ(f.sizes()[1], 2);
67 ASSERT_EQ(f.sizes()[2], 3);
70 ASSERT_THROW(f.resize_({3, 4, 5}), std::exception);
75 CPU(kFloat).tensorFromBlob(data, {1, 2, 3}, [&](
void*) { isgone++; });
84 CPU(kFloat).tensorFromBlob(data, {1, 2, 3}, [&](
void*) { isgone++; });
85 a_view = f2.view({3, 2, 1});
96 auto f2 = CUDA(kFloat).tensorFromBlob(
97 base.data_ptr(), {1, 2, 3}, [&](
void*) { isgone++; });
Scalar represents a 0-dimensional tensor which contains a single element.
Flush-To-Zero and Denormals-Are-Zero mode.