MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / get_random_tensor_i32

Function get_random_tensor_i32

tests/test-grad0.cpp:163–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163static struct ggml_tensor * get_random_tensor_i32(
164 struct ggml_context * ctx0,
165 int ndims,
166 int64_t ne[],
167 int32_t imin,
168 int32_t imax) {
169 struct ggml_tensor * result = ggml_new_tensor(ctx0, GGML_TYPE_I32, ndims, ne);
170
171 switch (ndims) {
172 case 1:
173 for (int i0 = 0; i0 < ne[0]; i0++) {
174 ((int32_t *)result->data)[i0] = irand(imax - imin) + imin;
175 }
176 break;
177 case 2:
178 for (int i1 = 0; i1 < ne[1]; i1++) {
179 for (int i0 = 0; i0 < ne[0]; i0++) {
180 ((int32_t *)result->data)[i1*ne[0] + i0] = irand(imax - imin) + imin;
181 }
182 }
183 break;
184 case 3:
185 for (int i2 = 0; i2 < ne[2]; i2++) {
186 for (int i1 = 0; i1 < ne[1]; i1++) {
187 for (int i0 = 0; i0 < ne[0]; i0++) {
188 ((int32_t *)result->data)[i2*ne[1]*ne[0] + i1*ne[0] + i0] = irand(imax - imin) + imin;
189 }
190 }
191 }
192 break;
193 case 4:
194 for (int i3 = 0; i3 < ne[3]; i3++) {
195 for (int i2 = 0; i2 < ne[2]; i2++) {
196 for (int i1 = 0; i1 < ne[1]; i1++) {
197 for (int i0 = 0; i0 < ne[0]; i0++) {
198 ((int32_t *)result->data)[i3*ne[2]*ne[1]*ne[0] + i2*ne[1]*ne[0] + i1*ne[0] + i0] = irand(imax - imin) + imin;
199 }
200 }
201 }
202 }
203 break;
204 default:
205 assert(false);
206 }
207
208 return result;
209}
210
211static bool check_gradient(
212 const char * op_name,

Callers 1

mainFunction · 0.85

Calls 2

irandFunction · 0.70
ggml_new_tensorFunction · 0.50

Tested by

no test coverage detected