| 56 | } // namespace |
| 57 | |
| 58 | std::vector<SVDTestcase> SVDTestcase::make() { |
| 59 | std::vector<SVDTestcase> ret; |
| 60 | |
| 61 | auto param = Param(false /* compute_uv */, false /* full_matrices */); |
| 62 | auto add_shape = [&ret, ¶m](const TensorShape& shape) { |
| 63 | ret.push_back({param, TensorLayout{shape, dtype::Float32()}}); |
| 64 | }; |
| 65 | |
| 66 | add_shape({1, 7, 7}); |
| 67 | add_shape({1, 3, 7}); |
| 68 | add_shape({1, 7, 3}); |
| 69 | for (size_t rows : {2, 3, 5, 7, 10, 32, 100}) { |
| 70 | for (size_t cols : {2, 3, 5, 7, 10, 32, 100}) { |
| 71 | param.compute_uv = false; |
| 72 | param.full_matrices = false; |
| 73 | add_shape({3, rows, cols}); |
| 74 | |
| 75 | param.compute_uv = true; |
| 76 | add_shape({2, rows, cols}); |
| 77 | param.full_matrices = true; |
| 78 | add_shape({3, rows, cols}); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | NormalRNG data_rng; |
| 83 | auto fill_data = [&](TensorND& data) { |
| 84 | auto sz = data.layout.span().dist_byte(), szf = sz / sizeof(dt_float32); |
| 85 | auto pf = static_cast<dt_float32*>(data.raw_ptr()); |
| 86 | data_rng.fill_fast_float32(pf, szf); |
| 87 | }; |
| 88 | |
| 89 | for (auto&& i : ret) { |
| 90 | i.m_mem.reset(new dt_float32[i.m_mat.layout.span().dist_elem()]); |
| 91 | i.m_mat.reset_ptr(i.m_mem.get()); |
| 92 | fill_data(i.m_mat); |
| 93 | } |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | SVDTestcase::Result SVDTestcase::run(SVDForward* opr) { |
| 99 | auto handle = opr->handle(); |