Context
TolveraContext
is a shared context or environment for Tolvera
instances.
It is created automatically when a Tolvera
instance is created, if one
does not already exist. It manages the integration of packages for graphics,
computer vision, communications protocols, and more. If multiple Tolvera
instances are created, they must share the same TolveraContext
.
Example
TolveraContext
can be created manually, and shared with multiple Tolvera
instances. Note that only one render
function can be used at a time.
Example
TolveraContext
can also be created automatically, and still shared.
CONSTS
Dict of CONSTS that can be used in Taichi scope
Source code in src/tolvera/utils.py
MPFace
Source code in src/tolvera/mp/face.py
config = {'min_detection_confidence': kwargs.get('detection_con', 0.5), 'model_selection': kwargs.get('model_selection', 0)}
instance-attribute
add bbox as separate tv.s.faces_bbox?
format: RELATIVE_BOUNDING_BOX relative_bounding_box { xmin: 0.482601523 ymin: 0.402242899 width: 0.162447035 height: 0.2887941 }
Pixels
Pixels class for drawing pixels to the screen.
This class is used to draw pixels to the screen. It contains methods for drawing points, lines, rectangles, circles, triangles, and polygons. It also contains methods for blending pixels together, flipping pixels, inverting pixels, and diffusing, decaying and clearing pixels.
It tries to follow a similar API to the Processing library.
Source code in src/tolvera/pixels.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
__call__()
__init__(tolvera, **kwargs)
Initialise Pixels
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolvera
|
Tolvera
|
Tölvera instance. |
required |
**kwargs
|
Keyword arguments. polygon_mode (str): Polygon mode. Defaults to "crossing". brightness (float): Brightness. Defaults to 1.0. |
{}
|
Source code in src/tolvera/pixels.py
_blend_add(rgba)
Blend by adding pixels together (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
Source code in src/tolvera/pixels.py
_blend_diff(rgba)
Blend by taking the difference of each pixel (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
Source code in src/tolvera/pixels.py
_blend_diff_inv(rgba)
Blend by taking the inverse difference of each pixel (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
Source code in src/tolvera/pixels.py
_blend_div(rgba)
Blend by dividing pixels (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
_blend_max(rgba)
Blend by taking the maximum of each pixel (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
Source code in src/tolvera/pixels.py
_blend_min(rgba)
Blend by taking the minimum of each pixel (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
Source code in src/tolvera/pixels.py
_blend_mix(rgba, amount)
Blend by mixing pixels (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
amount
|
f32
|
Amount to mix. |
required |
Source code in src/tolvera/pixels.py
_blend_mul(rgba)
Blend by multiplying pixels (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
_blend_sub(rgba)
Blend by subtracting pixels (Taichi scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rgba
|
template
|
Pixels to blend with. |
required |
_is_inside(p, x, y, l)
Check if point is inside polygon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
vec2
|
Point. |
required |
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
l
|
i32
|
Number of points. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
1 if inside, 0 if outside. |
Source code in src/tolvera/pixels.py
_is_inside_crossing(p, x, y, l)
Check if point is inside polygon using crossing number algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
vec2
|
Point. |
required |
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
l
|
i32
|
Number of points. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
1 if inside, 0 if outside. |
Source code in src/tolvera/pixels.py
_is_inside_winding(p, x, y, l)
Check if point is inside polygon using winding number algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p
|
vec2
|
Point. |
required |
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
l
|
i32
|
Number of points. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
1 if inside, 0 if outside. |
Source code in src/tolvera/pixels.py
_particles(particles, species, shape)
Draw particles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles
|
template
|
Particles. |
required |
species
|
template
|
Species. |
required |
shape
|
int
|
Shape enum value. |
required |
Source code in src/tolvera/pixels.py
background(r, g, b)
Set background colour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r
|
f32
|
Red. |
required |
g
|
f32
|
Green. |
required |
b
|
f32
|
Blue. |
required |
Source code in src/tolvera/pixels.py
blend_add(px)
Blend by adding pixels together (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_diff(px)
Blend by taking the difference of each pixel (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_diff_inv(px)
Blend by taking the inverse difference of each pixel (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_div(px)
Blend by dividing pixels (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_max(px)
Blend by taking the maximum of each pixel (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_min(px)
Blend by taking the minimum of each pixel (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_mix(px, amount)
Blend by mixing pixels (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
amount
|
f32
|
Amount to mix. |
required |
blend_mul(px)
Blend by multiplying pixels (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blend_sub(px)
Blend by subtracting pixels (Python scope).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
template
|
Pixels to blend with. |
required |
blur(radius)
Blur pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
radius
|
i32
|
Blur radius. |
required |
Source code in src/tolvera/pixels.py
circle(x, y, r, rgba)
Draw a filled circle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
i32
|
X position. |
required |
y
|
i32
|
Y position. |
required |
r
|
i32
|
Radius. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
circles(x, y, r, rgba)
Draw circles with the same colour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
r
|
template
|
Radii. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
clear()
decay(rate)
Decay pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rate
|
f32
|
decay rate. |
required |
diffuse(evaporate)
Diffuse pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
evaporate
|
float
|
Evaporation rate. |
required |
Source code in src/tolvera/pixels.py
flip_x()
flip_y()
get()
invert()
line(x0, y0, x1, y1, rgba)
Draw an anti-aliased line using Xiaolin Wu's algorithm.
Source code in src/tolvera/pixels.py
lines(points, rgba)
Draw lines with the same colour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
template
|
Points. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
particles(particles, species, shape='circle')
Draw particles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles
|
template
|
Particles. |
required |
species
|
template
|
Species. |
required |
shape
|
str
|
Shape. Defaults to "circle". |
'circle'
|
Source code in src/tolvera/pixels.py
plot(x, y, c, rgba)
point(x, y, rgba)
Draw point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
i32
|
X position. |
required |
y
|
i32
|
Y position. |
required |
rgba
|
vec4
|
Colour. |
required |
points(x, y, rgba)
Draw points with the same colour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
polygon(x, y, rgba)
Draw a filled polygon.
Polygons are drawn according to the polygon mode, which can be "crossing" (default) or "winding". First, the bounding box of the polygon is calculated. Then, we check if each pixel in the bounding box is inside the polygon. If it is, we draw it (along with each neighbour pixel).
Reference for point in polygon inclusion testing: http://www.dgp.toronto.edu/~mac/e-stuff/point_in_polygon.py
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
template
|
X positions. |
required |
y
|
template
|
Y positions. |
required |
rgba
|
vec4
|
Colour. |
required |
TODO: fill arg
Source code in src/tolvera/pixels.py
rect(x, y, w, h, rgba)
Draw a filled rectangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
i32
|
X position. |
required |
y
|
i32
|
Y position. |
required |
w
|
i32
|
Width. |
required |
h
|
i32
|
Height. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
rgba_from_px(px)
Get rgba from pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
Any
|
Pixels to get rgba from. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If pixel field cannot be found. |
Returns:
Name | Type | Description |
---|---|---|
MatrixField |
RGBA matrix field. |
Source code in src/tolvera/pixels.py
set(px)
Set pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
px
|
Any
|
Pixels to set. Can be Pixels, StructField, MatrixField, etc (see rgba_from_px). |
required |
stamp(x, y, px)
Stamp pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
i32
|
X position. |
required |
y
|
i32
|
Y position. |
required |
px
|
template
|
Pixels to stamp. |
required |
stamp_f(x, y, px)
Stamp pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
i32
|
X position. |
required |
y
|
i32
|
Y position. |
required |
px
|
template
|
Pixels to stamp. |
required |
Source code in src/tolvera/pixels.py
triangle(a, b, c, rgba)
Draw a filled triangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
vec2
|
Point A. |
required |
b
|
vec2
|
Point B. |
required |
c
|
vec2
|
Point C. |
required |
rgba
|
vec4
|
Colour. |
required |
Source code in src/tolvera/pixels.py
TolveraContext
Context for sharing between multiple Tölvera instances. Context includes Taichi, OSC, IML and CV. All Tölvera instances share the same context and are managed as a dict.
Attributes:
Name | Type | Description |
---|---|---|
kwargs |
dict
|
Keyword arguments for context. |
name |
str
|
Name of context. |
name_clean |
str
|
'Cleaned' name of context. |
i |
int
|
Frame counter. |
x |
int
|
Width of canvas. |
y |
int
|
Height of canvas. |
ti |
Taichi
|
Taichi instance. |
canvas |
Pixels
|
Pixels instance. |
osc |
OSC
|
OSC instance. |
iml |
IML
|
IML instance. |
cv |
CV
|
CV instance. |
_cleanup_fns |
list
|
List of cleanup functions. |
tolveras |
dict
|
Dict of Tölvera instances. |
Source code in src/tolvera/context.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
__init__(**kwargs)
add(tolvera)
Add Tölvera to context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolvera
|
Tolvera
|
Tölvera to add. |
required |
cleanup(f=None)
Decorator for cleanup functions based on iipyper. Make functions run on KeyBoardInterrupt (before exit). Cleanup functions must be defined before render is called!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Function to cleanup. |
None
|
Returns:
Type | Description |
---|---|
Decorator function if f is None, else decorated function. |
Source code in src/tolvera/context.py
get_by_name(name)
Get Tölvera by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of Tölvera to get. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tölvera |
Tölvera with given name. |
get_names()
Get names of all Tölveras in context.
Returns:
Name | Type | Description |
---|---|---|
list |
List of Tölvera names. |
init(**kwargs)
Initialise wrapped external packages with given keyword arguments. This only happens once when Tölvera is first initialised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
int
|
Width of canvas. Default: 1920. |
required |
y
|
int
|
Height of canvas. Default: 1080. |
required |
osc
|
bool
|
Enable OSC. Default: False. |
required |
iml
|
bool
|
Enable IML. Default: False. |
required |
cv
|
bool
|
Enable CV. Default: False. |
required |
Source code in src/tolvera/context.py
remove(name)
Remove Tölvera by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of Tölvera to delete. |
required |
render(f=None, **kwargs)
Render Tölvera with given function and keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
function
|
Function to run. Defaults to None. |
None
|
Source code in src/tolvera/context.py
run(f=None, **kwargs)
Run Tölvera with given render function and keyword arguments. This function will run inside a locked thread until KeyboardInterrupt/exit. It runs the render function, updates the OSC map (if enabled), and shows the pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Function to run. |
None
|
|
**kwargs
|
Keyword arguments for function. |
{}
|
Source code in src/tolvera/context.py
stop()
Run cleanup functions and exit.
Source code in src/tolvera/context.py
dotdict
create_and_validate_slice(arg, target_array)
Creates and validates a slice object based on the target array.
Source code in src/tolvera/utils.py
create_ndslices(dims)
Create a multi-dimensional slice from a list of tuples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dims
|
list[tuple]
|
A list of tuples containing the slice parameters for each dimension. |
required |
Returns:
Type | Description |
---|---|
s_
|
np.s_: A multi-dimensional slice object. |
Source code in src/tolvera/utils.py
create_safe_slice(arg)
Creates a slice object based on the input argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg
|
(int, tuple, slice)
|
The argument for creating the slice. It can be an integer, a tuple with slice parameters, or a slice object itself. |
required |
Returns:
Name | Type | Description |
---|---|---|
slice |
slice
|
A slice object created based on the provided argument. |
Source code in src/tolvera/utils.py
findsource(object)
Return the entire source file and starting line number for an object. For interactively-defined objects, the 'file' is the interpreter's history.
The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An IOError is raised if the source code cannot be retrieved, while a TypeError is raised for objects where the source code is unavailable (e.g. builtins).
Source code in src/tolvera/patches.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
flatten(lst)
Flatten a nested list or return a non-nested list as is.
generic_slice(array, slice_params)
Slices a NumPy array based on a tuple of slice parameters for each dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
ndarray
|
The array to be sliced. |
required |
slice_params
|
tuple
|
A tuple where each item is either an integer, a tuple with slice parameters, or a slice object. |
required |
Returns:
Name | Type | Description |
---|---|---|
ndarray |
ndarray
|
The sliced array. |
Source code in src/tolvera/utils.py
time_function(func, *args, **kwargs)
Time how long it takes to run a function and print the result
Source code in src/tolvera/utils.py
validate_json_path(path)
Validate a JSON file path. It uses validate_path for initial validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The JSON file path to be validated. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the path is a valid JSON file path, raises an exception otherwise. |
Raises:
Type | Description |
---|---|
ValueError
|
If the path does not end with '.json'. |
Source code in src/tolvera/utils.py
validate_path(path)
Validate a path using os.path and pathlib.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path to be validated. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the path is valid, raises an exception otherwise. |
Raises:
Type | Description |
---|---|
TypeError
|
If the input is not a string. |
FileNotFoundError
|
If the path does not exist. |
PermissionError
|
If the path is not accessible. |
Source code in src/tolvera/utils.py
validate_slice(slice_obj, target_array)
Validates if the given slice object is applicable to the target ndarray.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slice_obj
|
tuple[slice]
|
A tuple containing slice objects for each dimension. |
required |
target_array
|
ndarray
|
The array to be sliced. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the slice is valid for the given array, False otherwise. |