Skip to content
/ matrix Public

A Matrix class for the Crystal programming language.

License

Notifications You must be signed in to change notification settings

JacobUb/matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matrix Build Status

This is a Matrix class for Crystal. There are a few ways to create a Matrix:

# Creates a Matrix of Int32 with 3 rows and 2 columns. A Tuple of rows can also 
# be used instead of an array. Each row must have the same number of elements.
Matrix.rows([[1, 2], [3, 4], [5, 6]]) 
# 1, 2
# 3, 4
# 5, 6

# Creates a Matrix with 2 rows and 3 columns. Like with Matrix.rows, the columns 
# must have the same number of elements.
Matrix.columns([[1, 2], [3, 4], [5, 6]])
# 1, 3, 5
# 2, 4, 6

# A Matrix can also be created by giving its number of columns and rows, just 
# like an Array can be created by giving it a starting size. This constructor 
# will yield the linear index, the current row and the current column.
Matrix.new(2, 2) { |idx, row, col| idx  }
# 0, 1
# 2, 3
Matrix.new(2, 2) { |idx, row, col| row  }
# 0, 0
# 1, 1
Matrix.new(2, 2) { |idx, row, col| col  }
 # 0, 1
 # 0, 1

Most methods are documented in the matrix.cr file itself.

About

A Matrix class for the Crystal programming language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published