@@ -5,47 +5,45 @@ The `Vector` type represents a collection of elements of a specific type. All el
55
66## Usage
77
8+ The type is automatically inferred from the first item. You can also specify ` ray_type ` explicitly to cast items to a specific type.
9+
810``` python
9- >> > from rayforce import Vector, I64, Symbol
11+ >> > from rayforce import Vector, I64, F64, Symbol
1012
11- >> > int_vector = Vector(ray_type = I64, length = 3 )
13+ # Type is inferred from items
14+ >> > int_vector = Vector([1 , 2 , 3 ])
1215>> > int_vector
13- Vector(5 ) # 5 represents a type code of I64
16+ [I64(1 ), I64(2 ), I64(3 )]
17+
18+ >> > float_vector = Vector([1.5 , 2.5 , 3.5 ])
19+ >> > float_vector
20+ [F64(1.5 ), F64(2.5 ), F64(3.5 )]
1421
15- >> > symbol_vector = Vector(ray_type = Symbol, items = [" apple" , " banana" , " cherry" ])
22+ >> > symbol_vector = Vector([" apple" , " banana" , " cherry" ])
1623>> > symbol_vector
17- Vector(5 ) # 6 represents a type code of Symbol
18-
19- >> > timestamp_vector = Vector(
20- ray_type = Timestamp,
21- items = [
22- " 2025-05-10T14:30:45+00:00" ,
23- " 2025-05-10T14:30:45+00:00" ,
24- " 2025-05-10T14:30:45+00:00" ,
25- ]
26- )
27- ```
24+ [Symbol(' apple' ), Symbol(' banana' ), Symbol(' cherry' )]
2825
29- ### Accessing the values
30- ``` python
31- >> > [i for i in int_vector]
32- [I64(0 ), I64(0 ), I64(0 ), I64(0 ), I64(0 )]
26+ # Explicit ray_type for casting
27+ >> > Vector([1 , 2 , 3 ], ray_type = F64)
28+ [F64(1.0 ), F64(2.0 ), F64(3.0 )]
3329
34- >> > [i for i in symbol_vector]
35- [Symbol(' apple' ), Symbol(' banana' ), Symbol(' cherry' )]
30+ # Pre-allocate empty vector with specific type and length
31+ >> > Vector(ray_type = I64, length = 3 )
32+ [I64(0 ), I64(0 ), I64(0 )]
3633```
3734
38- ### Setting the values
35+ ### Accessing and Setting Values
3936``` python
40- >> > int_vector[ 0 ] = 999
41- [I64( 999 ), I64( 0 ), I64( 0 ), I64( 0 ), I64( 0 ) ]
42- >> > int_vector
37+ >> > v = Vector([ 10 , 20 , 30 ])
38+ >> > v[ 0 ]
39+ I64( 10 )
4340
44- >> > symbol_vector [0 ] = " pineapple "
45- >> > [i for i in symbol_vector]
46- [Symbol( ' pineapple ' ), Symbol( ' banana ' ), Symbol( ' cherry ' )]
41+ >> > v [0 ] = 999
42+ >> > v
43+ [I64( 999 ), I64( 20 ), I64( 30 )]
4744
48- # TODO : Add push object to vector outside of it's length
45+ >> > [i for i in v]
46+ [I64(999 ), I64(20 ), I64(30 )]
4947```
5048
5149## Operations
@@ -55,55 +53,55 @@ Vectors support a wide range of operations through mixins.
5553### Arithmetic Operations
5654
5755``` python
58- >> > v1 = Vector(ray_type = I64, items = [1 , 2 , 3 ])
59- >> > v2 = Vector(ray_type = I64, items = [4 , 5 , 6 ])
56+ >> > v1 = Vector([1 , 2 , 3 ])
57+ >> > v2 = Vector([4 , 5 , 6 ])
6058
6159>> > v1 + v2
62- Vector( [I64(5 ), I64(7 ), I64(9 )])
60+ [I64(5 ), I64(7 ), I64(9 )]
6361
6462>> > v1 * 2
65- Vector( [I64(2 ), I64(4 ), I64(6 )])
63+ [I64(2 ), I64(4 ), I64(6 )]
6664
6765>> > v1 - v2
68- Vector( [I64(- 3 ), I64(- 3 ), I64(- 3 )])
66+ [I64(- 3 ), I64(- 3 ), I64(- 3 )]
6967```
7068
7169### Comparison Operations
7270
7371``` python
74- >> > v1 = Vector(ray_type = I64, items = [1 , 5 , 10 ])
75- >> > v2 = Vector(ray_type = I64, items = [2 , 5 , 8 ])
72+ >> > v1 = Vector([1 , 5 , 10 ])
73+ >> > v2 = Vector([2 , 5 , 8 ])
7674
7775>> > v1 < v2
78- Vector( [B8(True ), B8(False ), B8(False )])
76+ [B8(True ), B8(False ), B8(False )]
7977
8078>> > v1 >= v2
81- Vector( [B8(False ), B8(True ), B8(True )])
79+ [B8(False ), B8(True ), B8(True )]
8280
8381>> > v1.eq(v2)
84- Vector( [B8(False ), B8(True ), B8(False )])
82+ [B8(False ), B8(True ), B8(False )]
8583```
8684
8785### Logical Operations
8886
8987``` python
90- >> > v1 = Vector(ray_type = B8, items = [True , False , True ])
91- >> > v2 = Vector(ray_type = B8, items = [True , True , False ])
88+ >> > v1 = Vector([True , False , True ])
89+ >> > v2 = Vector([True , True , False ])
9290
9391>> > v1.and_(v2)
94- Vector( [B8(True ), B8(False ), B8(False )])
92+ [B8(True ), B8(False ), B8(False )]
9593
9694>> > v1.or_(v2)
97- Vector( [B8(True ), B8(True ), B8(True )])
95+ [B8(True ), B8(True ), B8(True )]
9896
9997>> > v1.not_()
100- Vector( [B8(False ), B8(True ), B8(False )])
98+ [B8(False ), B8(True ), B8(False )]
10199```
102100
103101### Aggregation Operations
104102
105103``` python
106- >> > v = Vector(ray_type = I64, items = [1 , 2 , 3 , 4 , 5 ])
104+ >> > v = Vector([1 , 2 , 3 , 4 , 5 ])
107105
108106>> > v.sum()
109107I64(15 )
@@ -121,7 +119,7 @@ F64(3.0)
121119### Element Access
122120
123121``` python
124- >> > v = Vector(ray_type = I64, items = [10 , 20 , 30 , 40 , 50 ])
122+ >> > v = Vector([10 , 20 , 30 , 40 , 50 ])
125123
126124>> > v.first()
127125I64(10 )
@@ -130,7 +128,7 @@ I64(10)
130128I64(50 )
131129
132130>> > v.take(3 )
133- Vector( [I64(10 ), I64(20 ), I64(30 )])
131+ [I64(10 ), I64(20 ), I64(30 )]
134132
135133>> > v.at(2 )
136134I64(30 )
@@ -139,65 +137,65 @@ I64(30)
139137### Set Operations
140138
141139``` python
142- >> > v1 = Vector(ray_type = I64, items = [1 , 2 , 3 , 4 ])
143- >> > v2 = Vector(ray_type = I64, items = [3 , 4 , 5 , 6 ])
140+ >> > v1 = Vector([1 , 2 , 3 , 4 ])
141+ >> > v2 = Vector([3 , 4 , 5 , 6 ])
144142
145143>> > v1.union(v2)
146- Vector( [I64(1 ), I64(2 ), I64(3 ), I64(4 ), I64(5 ), I64(6 )])
144+ [I64(1 ), I64(2 ), I64(3 ), I64(4 ), I64(5 ), I64(6 )]
147145
148146>> > v1.sect(v2)
149- Vector( [I64(3 ), I64(4 )])
147+ [I64(3 ), I64(4 )]
150148
151149>> > v1.except_(v2)
152- Vector( [I64(1 ), I64(2 )])
150+ [I64(1 ), I64(2 )]
153151```
154152
155153### Search Operations
156154
157155``` python
158- >> > v = Vector(ray_type = I64, items = [10 , 20 , 30 , 40 ])
156+ >> > v = Vector([10 , 20 , 30 , 40 ])
159157
160158>> > v.find(30 )
161159I64(2 )
162160
163- >> > v.within(Vector(ray_type = I64, items = [15 , 35 ]))
164- Vector( [B8(False ), B8(True ), B8(True ), B8(False )])
161+ >> > v.within(Vector([15 , 35 ]))
162+ [B8(False ), B8(True ), B8(True ), B8(False )]
165163
166- >> > mask = Vector(ray_type = B8, items = [True , False , True , False ])
164+ >> > mask = Vector([True , False , True , False ])
167165>> > v.filter(mask)
168- Vector( [I64(10 ), I64(30 )])
166+ [I64(10 ), I64(30 )]
169167```
170168
171169### Sort Operations
172170
173171``` python
174- >> > v = Vector(ray_type = I64, items = [3 , 1 , 4 , 1 , 5 ])
172+ >> > v = Vector([3 , 1 , 4 , 1 , 5 ])
175173
176174>> > v.asc()
177- Vector( [I64(1 ), I64(1 ), I64(3 ), I64(4 ), I64(5 )])
175+ [I64(1 ), I64(1 ), I64(3 ), I64(4 ), I64(5 )]
178176
179177>> > v.desc()
180- Vector( [I64(5 ), I64(4 ), I64(3 ), I64(1 ), I64(1 )])
178+ [I64(5 ), I64(4 ), I64(3 ), I64(1 ), I64(1 )]
181179
182180>> > v.iasc() # indices for ascending sort
183- Vector( [I64(1 ), I64(3 ), I64(0 ), I64(2 ), I64(4 )])
181+ [I64(1 ), I64(3 ), I64(0 ), I64(2 ), I64(4 )]
184182
185183>> > v.rank()
186- Vector( [I64(2 ), I64(0 ), I64(3 ), I64(1 ), I64(4 )])
184+ [I64(2 ), I64(0 ), I64(3 ), I64(1 ), I64(4 )]
187185
188186>> > v.reverse()
189- Vector( [I64(5 ), I64(1 ), I64(4 ), I64(1 ), I64(3 )])
187+ [I64(5 ), I64(1 ), I64(4 ), I64(1 ), I64(3 )]
190188
191189>> > v.negate()
192- Vector( [I64(- 3 ), I64(- 1 ), I64(- 4 ), I64(- 1 ), I64(- 5 )])
190+ [I64(- 3 ), I64(- 1 ), I64(- 4 ), I64(- 1 ), I64(- 5 )]
193191```
194192
195193### Functional Operations
196194
197195``` python
198196>> > from rayforce import Operation
199197
200- >> > v = Vector(ray_type = I64, items = [1 , 2 , 3 ])
198+ >> > v = Vector([1 , 2 , 3 ])
201199>> > v.map(Operation.NEGATE )
202- Vector( [I64(- 1 ), I64(- 2 ), I64(- 3 )])
200+ [I64(- 1 ), I64(- 2 ), I64(- 3 )]
203201```
0 commit comments