本文记录了 PROJECT #0 - C++ PRIMER 的实验过程

PROJECT #0 - C++ PRIMER

实现一些简单的矩阵操作,编写 TODO 下面的代码

注,请先了解 C++ 的知识

  1. 模版类
  2. 虚函数
  3. C++ 的类和继承
  4. 智能指针 unique_ptr
  5. std::move() 的用法

Matrix

  • 在构造函数中对 rowscols 进行赋值,然后为 linear 指针分配 $r*c$ 大小的数组
  • 在析构函数中释放分配给 linear 的空间

RowMatrix

  • 在构造函数中给 data_ 分配一个行指针数组,然后初始化指针的值
  • MatImport 函数会通过数组 arr 来设置矩阵对应的值,arr 的大小会等于 $r*c$
  • 在析构函数中释放分配给 data_ 的空间
  • 注:访问父类 Matrix 的保护成员时,需要加上 this 指针才能访问

RowMatrixOperations

  • 实现矩阵的加、乘、GEMM 操作
  • 会用到 std::move() 函数对 unique_ptr 进行操作

测试

  • 去掉 test/primer/starter_test.cpp 中的 DISABLED_
1
2
3
cd build
make starter_test
./test/starter_test

代码格式验证

1
2
3
make format
make check-lint
make check-clang-tidy

打包提交

  • 打包代码
1
zip project0-submission.zip src/include/primer/p0_starter.h