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

Function ggml_set_f32

ggml.c:2668–2718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2666}
2667
2668struct ggml_tensor * ggml_set_f32(struct ggml_tensor * tensor, float value) {
2669 const int n = ggml_nrows(tensor);
2670 const int nc = tensor->ne[0];
2671 const size_t n1 = tensor->nb[1];
2672
2673 char * const data = tensor->data;
2674
2675 switch (tensor->type) {
2676 case GGML_TYPE_I8:
2677 {
2678 assert(tensor->nb[0] == sizeof(int8_t));
2679 for (int i = 0; i < n; i++) {
2680 ggml_vec_set_i8(nc, (int8_t *)(data + i*n1), value);
2681 }
2682 } break;
2683 case GGML_TYPE_I16:
2684 {
2685 assert(tensor->nb[0] == sizeof(int16_t));
2686 for (int i = 0; i < n; i++) {
2687 ggml_vec_set_i16(nc, (int16_t *)(data + i*n1), value);
2688 }
2689 } break;
2690 case GGML_TYPE_I32:
2691 {
2692 assert(tensor->nb[0] == sizeof(int32_t));
2693 for (int i = 0; i < n; i++) {
2694 ggml_vec_set_i32(nc, (int32_t *)(data + i*n1), value);
2695 }
2696 } break;
2697 case GGML_TYPE_F16:
2698 {
2699 assert(tensor->nb[0] == sizeof(ggml_fp16_t));
2700 for (int i = 0; i < n; i++) {
2701 ggml_vec_set_f16(nc, (ggml_fp16_t *)(data + i*n1), GGML_FP32_TO_FP16(value));
2702 }
2703 } break;
2704 case GGML_TYPE_F32:
2705 {
2706 assert(tensor->nb[0] == sizeof(float));
2707 for (int i = 0; i < n; i++) {
2708 ggml_vec_set_f32(nc, (float *)(data + i*n1), value);
2709 }
2710 } break;
2711 default:
2712 {
2713 GGML_ASSERT(false);
2714 } break;
2715 }
2716
2717 return tensor;
2718}
2719
2720void ggml_unravel_index(const struct ggml_tensor * tensor, int64_t i, int64_t * i0, int64_t * i1, int64_t * i2, int64_t * i3) {
2721 const int64_t ne2 = tensor->ne[2];

Callers 10

ggml_new_f32Function · 0.70
ggml_opt_adamFunction · 0.70
linesearch_backtrackingFunction · 0.70
ggml_opt_lbfgsFunction · 0.70
llama_build_graphFunction · 0.70
check_gradientFunction · 0.50
get_example_targetsFunction · 0.50
mainFunction · 0.50
clip_image_build_graphFunction · 0.50

Calls 6

ggml_nrowsFunction · 0.70
ggml_vec_set_i8Function · 0.70
ggml_vec_set_i16Function · 0.70
ggml_vec_set_i32Function · 0.70
ggml_vec_set_f16Function · 0.70
ggml_vec_set_f32Function · 0.70

Tested by 1

check_gradientFunction · 0.40