MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / squeeze

Method squeeze

mlx/data/Array.cpp:136–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void 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
167void Array::reshape(const std::vector<int64_t>& shape) {
168 std::vector<int64_t> new_shape = shape;

Callers 5

mlx_data_export_datasetFunction · 0.45
squeezeFunction · 0.45
__getitem__Method · 0.45
process_sample_implFunction · 0.45
iterateFunction · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected