Vectors, Matrices, and Tensors
Fixed-size numeric arrays carry dimensions in their types.
Float[#3]
Float[#3] is a vector with exactly three Float values.
vector.brp
point: Float[#3] = {1.0, 2.0, 3.0}Compile-time Bounds
Indexing a fixed-size array with a proven valid index can be checked before runtime.
bounds.brp
point: Float[#3] = {1.0, 2.0, 3.0}
z: Float = point[2]Dot Product
vector.dot requires both operands to have the same element type and dimension.
dot.brp
import:
vector: dot
score: Float = dot(a, b)Matrix Basics
Matrix helpers such as matvec preserve dimensions in their result types.
matrix.brp
m: Float[#2, #2] = {{1.0, 0.0}, {0.0, 1.0}}Example
vectors.brp
import:
float: sqrt
matrix: matvec
vector: dot
pure func distance(a: Float[#3], b: Float[#3]) -> Float:
delta: Float[#3] = a - b
sqrt(dot(delta, delta))
func main(args: List[String]) -> Void:
p: Float[#3] = {1.0, 2.0, 3.0}
q: Float[#3] = {1.0, 4.0, 3.0}
transform: Float[#2, #2] = {
{1.0, 2.0},
{3.0, 4.0},
}
point: Float[#2] = {5.0, 6.0}
moved: Float[#2] = matvec(transform, point)
print(distance(p, q).to_string())
print(moved[0].to_string())
print(moved[1].to_string())
Try It
terminal
blorp run vectors.brp