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

Function ggml_set_i32_1d

ggml.c:2785–2823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2783}
2784
2785void ggml_set_i32_1d(const struct ggml_tensor * tensor, int i, int32_t value) {
2786 if (!ggml_is_contiguous(tensor)) {
2787 int64_t id[4] = { 0, 0, 0, 0 };
2788 ggml_unravel_index(tensor, i, &id[0], &id[1], &id[2], &id[3]);
2789 ggml_set_i32_nd(tensor, id[0], id[1], id[2], id[3], value);
2790 return;
2791 }
2792 switch (tensor->type) {
2793 case GGML_TYPE_I8:
2794 {
2795 GGML_ASSERT(tensor->nb[0] == sizeof(int8_t));
2796 ((int8_t *)(tensor->data))[i] = value;
2797 } break;
2798 case GGML_TYPE_I16:
2799 {
2800 GGML_ASSERT(tensor->nb[0] == sizeof(int16_t));
2801 ((int16_t *)(tensor->data))[i] = value;
2802 } break;
2803 case GGML_TYPE_I32:
2804 {
2805 GGML_ASSERT(tensor->nb[0] == sizeof(int32_t));
2806 ((int32_t *)(tensor->data))[i] = value;
2807 } break;
2808 case GGML_TYPE_F16:
2809 {
2810 GGML_ASSERT(tensor->nb[0] == sizeof(ggml_fp16_t));
2811 ((ggml_fp16_t *)(tensor->data))[i] = GGML_FP32_TO_FP16(value);
2812 } break;
2813 case GGML_TYPE_F32:
2814 {
2815 GGML_ASSERT(tensor->nb[0] == sizeof(float));
2816 ((float *)(tensor->data))[i] = value;
2817 } break;
2818 default:
2819 {
2820 GGML_ASSERT(false);
2821 } break;
2822 }
2823}
2824
2825int32_t ggml_get_i32_nd(const struct ggml_tensor * tensor, int i0, int i1, int i2, int i3) {
2826 void * data = (char *) tensor->data + i0*tensor->nb[0] + i1*tensor->nb[1] + i2*tensor->nb[2] + i3*tensor->nb[3];

Callers 5

sample_softmaxFunction · 0.50
get_example_targetsFunction · 0.50
lshift_examplesFunction · 0.50
mainFunction · 0.50
clip_image_build_graphFunction · 0.50

Calls 3

ggml_is_contiguousFunction · 0.70
ggml_unravel_indexFunction · 0.70
ggml_set_i32_ndFunction · 0.70

Tested by

no test coverage detected