0.0
No commit activity in last 3 years
No release in over 3 years
Immutable persistent matrix using Hamster that aims to copy as much of the API from Ruby's native Matrix class as possible
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
~> 3.0

Runtime

< 3.0, >= 1.0.0
 Project Readme

Build Status

Hamster Matrix

Hamster Matrix is a gem providing a persistent immutable matrix for functional programming in Ruby. It is an extension for the popular Hamster gem. It creates a matrix by using nested Hamster Vectors.

It's great for keeping the board state in 2D video games, where the state must be modified while leaving references to the old state unchanged, such as when using a time travelling debugger or implementing undo functionality. It copies the interface from Ruby's Matrix class as much as possible.

Installation

Add this line to your application's Gemfile:

gem 'hamster-matrix'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hamster-matrix

Usage

require 'hamster-matrix'
a = Hamster::Matrix[[1,0,0],[0,1,0],[0,0,1]]
b = a.set(2,2,'foo')
puts b
# [[1, 0, 0]
#  [0, 1, 0]
#  [0, 0, "foo"]]

puts a
#[[1, 0, 0]
# [0, 1, 0]
# [0, 0, 1]]

Implements the following methods replicating the behavior of Ruby's Matrix class as closely as possible

Class Methods

  • []
  • identity
  • build
  • column_vector
  • columns
  • diagonal
  • I
  • identity
  • row_vector
  • rows
  • scalar
  • unit

Instance Methods

  • ==
  • []
  • collect
  • column
  • column_count
  • column_size
  • column_vectors
  • component
  • element
  • empty?
  • get
  • hash
  • inspect
  • map
  • row
  • row_count
  • row_size
  • row_vectors
  • set
  • square?
  • to_a
  • to_matrix
  • to_s
  • zero?

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bradurani/hamster-matrix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.