@@ -25,14 +25,10 @@ impl LlamaContext<'_> {
2525 /// * `p0` - The start position of the cache to clear. If `None`, the entire cache is copied up to [p1].
2626 /// * `p1` - The end position of the cache to clear. If `None`, the entire cache is copied starting from [p0].
2727 pub fn copy_kv_cache_seq ( & mut self , src : i32 , dest : i32 , p0 : Option < u16 > , p1 : Option < u16 > ) {
28+ let p0 = p0. map_or ( -1 , i32:: from) ;
29+ let p1 = p1. map_or ( -1 , i32:: from) ;
2830 unsafe {
29- llama_cpp_sys_2:: llama_kv_cache_seq_cp (
30- self . context . as_ptr ( ) ,
31- src,
32- dest,
33- p0. map_or ( -1 , i32:: from) ,
34- p1. map_or ( -1 , i32:: from) ,
35- )
31+ llama_cpp_sys_2:: llama_kv_cache_seq_cp ( self . context . as_ptr ( ) , src, dest, p0, p1)
3632 }
3733 }
3834
@@ -44,13 +40,10 @@ impl LlamaContext<'_> {
4440 /// * `p0` - The start position of the cache to clear. If `None`, the entire cache is cleared up to [p1].
4541 /// * `p1` - The end position of the cache to clear. If `None`, the entire cache is cleared from [p0].
4642 pub fn clear_kv_cache_seq ( & mut self , src : i32 , p0 : Option < u16 > , p1 : Option < u16 > ) {
43+ let p0 = p0. map_or ( -1 , i32:: from) ;
44+ let p1 = p1. map_or ( -1 , i32:: from) ;
4745 unsafe {
48- llama_cpp_sys_2:: llama_kv_cache_seq_rm (
49- self . context . as_ptr ( ) ,
50- src,
51- p0. map_or ( -1 , i32:: from) ,
52- p1. map_or ( -1 , i32:: from) ,
53- ) ;
46+ llama_cpp_sys_2:: llama_kv_cache_seq_rm ( self . context . as_ptr ( ) , src, p0, p1) ;
5447 }
5548 }
5649
@@ -85,14 +78,10 @@ impl LlamaContext<'_> {
8578 /// * `p1` - The end position of the cache to update. If `None`, the entire cache is updated starting from [p0].
8679 /// * `delta` - The relative position to add to the tokens
8780 pub fn kv_cache_seq_add ( & mut self , seq_id : i32 , p0 : Option < u16 > , p1 : Option < u16 > , delta : i32 ) {
81+ let p0 = p0. map_or ( -1 , i32:: from) ;
82+ let p1 = p1. map_or ( -1 , i32:: from) ;
8883 unsafe {
89- llama_cpp_sys_2:: llama_kv_cache_seq_add (
90- self . context . as_ptr ( ) ,
91- seq_id,
92- p0. map_or ( -1 , i32:: from) ,
93- p1. map_or ( -1 , i32:: from) ,
94- delta,
95- )
84+ llama_cpp_sys_2:: llama_kv_cache_seq_add ( self . context . as_ptr ( ) , seq_id, p0, p1, delta)
9685 }
9786 }
9887
@@ -114,15 +103,10 @@ impl LlamaContext<'_> {
114103 p1 : Option < u16 > ,
115104 d : NonZeroU8 ,
116105 ) {
117- unsafe {
118- llama_cpp_sys_2:: llama_kv_cache_seq_div (
119- self . context . as_ptr ( ) ,
120- seq_id,
121- p0. map_or ( -1 , i32:: from) ,
122- p1. map_or ( -1 , i32:: from) ,
123- c_int:: from ( d. get ( ) ) ,
124- )
125- }
106+ let p0 = p0. map_or ( -1 , i32:: from) ;
107+ let p1 = p1. map_or ( -1 , i32:: from) ;
108+ let d = c_int:: from ( d. get ( ) ) ;
109+ unsafe { llama_cpp_sys_2:: llama_kv_cache_seq_div ( self . context . as_ptr ( ) , seq_id, p0, p1, d) }
126110 }
127111
128112 /// Returns the largest position present in the KV cache for the specified sequence
0 commit comments