Skip to content

Commit

Permalink
第四章更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhellofss committed Jul 1, 2024
1 parent 06ef5d5 commit c7fc02a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/test_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,34 @@ TEST(test_tensor, init4) {
ASSERT_EQ(*t1.ptr<float>(), 31);
delete[] ptr;
}

TEST(test_tensor, index) {
using namespace base;
float* ptr = new float[32];
auto alloc_cu = base::CPUDeviceAllocatorFactory::get_instance();
ptr[0] = 31;
tensor::Tensor t1(base::DataType::kDataTypeFp32, 32, false, nullptr, ptr);
void* p1 = t1.ptr<void>();
p1 += 1;

float* f1 = t1.ptr<float>();
f1 += 1;
ASSERT_NE(f1, p1);
delete[] ptr;
}

TEST(test_tensor, dims_stride) {
using namespace base;
auto alloc_cu = base::CPUDeviceAllocatorFactory::get_instance();

tensor::Tensor t1(base::DataType::kDataTypeFp32, 32, 32, 3, true, alloc_cu);
ASSERT_EQ(t1.is_empty(), false);
ASSERT_EQ(t1.get_dim(0), 32);
ASSERT_EQ(t1.get_dim(1), 32);
ASSERT_EQ(t1.get_dim(2), 3);

const auto& strides = t1.strides();
ASSERT_EQ(strides.at(0), 32 * 3);
ASSERT_EQ(strides.at(1), 3);
ASSERT_EQ(strides.at(2), 1);
}

0 comments on commit c7fc02a

Please sign in to comment.