MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / slice

Function slice

subprojects/llama.cpp/common/jinja/value.cpp:71–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 */
70template<typename T>
71static T slice(const T & array, int64_t start, int64_t stop, int64_t step = 1) {
72 int64_t len = static_cast<int64_t>(array.size());
73 int64_t direction = (step > 0) ? 1 : ((step < 0) ? -1 : 0);
74 int64_t start_val = 0;
75 int64_t stop_val = 0;
76 if (direction >= 0) {
77 start_val = start;
78 if (start_val < 0) {
79 start_val = std::max(len + start_val, (int64_t)0);
80 } else {
81 start_val = std::min(start_val, len);
82 }
83
84 stop_val = stop;
85 if (stop_val < 0) {
86 stop_val = std::max(len + stop_val, (int64_t)0);
87 } else {
88 stop_val = std::min(stop_val, len);
89 }
90 } else {
91 start_val = len - 1;
92 if (start_val < 0) {
93 start_val = std::max(len + start_val, (int64_t)-1);
94 } else {
95 start_val = std::min(start_val, len - 1);
96 }
97
98 stop_val = -1;
99 if (stop_val < -1) {
100 stop_val = std::max(len + stop_val, (int64_t)-1);
101 } else {
102 stop_val = std::min(stop_val, len - 1);
103 }
104 }
105 T result;
106 if (direction == 0) {
107 return result;
108 }
109 for (int64_t i = start_val; direction * i < direction * stop_val; i += step) {
110 if (i >= 0 && i < len) {
111 result.push_back(array[static_cast<size_t>(i)]);
112 }
113 }
114 return result;
115}
116
117template<typename T>
118static value empty_value_fn(const func_args &) {

Callers 7

__getitem__Method · 0.85
dequant_simpleMethod · 0.85
value.cppFile · 0.85
get_data_by_rangeMethod · 0.85
contentsMethod · 0.85
dump_metadataFunction · 0.85

Calls 4

maxFunction · 0.85
minFunction · 0.85
sizeMethod · 0.65
push_backMethod · 0.45

Tested by

no test coverage detected