matrix

Version, currently master branch1 version
  • master branchlatestMar 14, 2021

github.com/JacobUb/matrix

A Matrix class for the Crystal programming language.

29 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  matrix:
    github: JacobUb/matrix
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.29.0
Author
Exilor

Dependencies

This version declares no dependencies.

Documentation

Read the API documentation

Generated from the source of the current release. The first visit to a release that has never been documented starts its build.

README

# matrix [![Build Status](https://travis-ci.org/Exilor/matrix.svg?branch=master)](https://travis-ci.org/Exilor/matrix)


This is a Matrix class for [Crystal](https://github.com/crystal-lang/crystal).
There are a few ways to create a Matrix:
```crystal
# 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.