| 134 | } |
| 135 | |
| 136 | void Array::squeeze(const std::vector<int>& dims) { |
| 137 | std::vector<int64_t> mask(ndim(), true); |
| 138 | if (dims.empty()) { |
| 139 | for (int i = 0; i < ndim(); i++) { |
| 140 | if (shape_[i] == 1) { |
| 141 | mask[i] = false; |
| 142 | } |
| 143 | } |
| 144 | } else { |
| 145 | for (auto dim : dims) { |
| 146 | dim = checkdim(dim); |
| 147 | if (shape_[dim] == 1) { |
| 148 | mask[dim] = false; |
| 149 | } else { |
| 150 | throw std::runtime_error( |
| 151 | "Array: cannot squeeze a non-singleton dimension"); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | int newndim = 0; |
| 156 | for (int i = 0; i < shape_.size(); i++) { |
| 157 | if (mask[i]) { |
| 158 | if (i != newndim) { |
| 159 | shape_[newndim] = shape_[i]; |
| 160 | } |
| 161 | newndim++; |
| 162 | } |
| 163 | } |
| 164 | shape_.resize(newndim); |
| 165 | } |
| 166 | |
| 167 | void Array::reshape(const std::vector<int64_t>& shape) { |
| 168 | std::vector<int64_t> new_shape = shape; |
no test coverage detected