MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / __getitem__

Method __getitem__

examples/low_level_api/util.py:46–75  ·  view source on GitHub ↗
(self, val)

Source from the content-addressed store, hash-verified

44 self.offset = (self.offset + 1) % self.maxsize
45
46 def __getitem__(self, val):
47 if isinstance(val, int):
48 if 0 > val or val >= self.size:
49 raise IndexError("Index out of range")
50 return (
51 self.list[val]
52 if self.size < self.maxsize
53 else self.list[(self.offset + val) % self.maxsize]
54 )
55 elif isinstance(val, slice):
56 start, stop, step = val.start, val.stop, val.step
57 if step is None:
58 step = 1
59 if start is None:
60 start = 0
61 if stop is None:
62 stop = self.size
63 if start < 0:
64 start = self.size + start
65 if stop < 0:
66 stop = self.size + stop
67
68 indices = range(start, stop, step)
69 return [
70 self.list[(self.offset + i) % self.maxsize]
71 for i in indices
72 if i < self.size
73 ]
74 else:
75 raise TypeError("Invalid argument type")
76
77
78if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected