Created
April 24, 2012 19:18
-
-
Save salzig/2482861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Matrix[T: Numeric: Manifest](val xDim:Int, val yDim:Int, private val data:Array[T]) { | |
| require(data.size == xDim*yDim, "provided data dosn't match required dimensions") | |
| val numeric = implicitly[Numeric[T]] | |
| val manifest:Manifest[T] = implicitly | |
| //... | |
| override def toString = "Matrix[%s](%s)" format (manifest, data.grouped(xDim).map( "(%s)" format _.mkString(", ") ).mkString(", ")) | |
| } | |
| object Matrix { | |
| // Matrix(dim, *values) | |
| def apply[T](dim:Int, values:T*):Matrix[T] = new Matrix(dim, dim, values) | |
| //... | |
| } | |
| object Application { | |
| def main(args:Array[String]) { | |
| println(Matrix(3)(1, 2, 3)) | |
| println(Matrix(3)(1.0, 2, 3)) | |
| println(Matrix(2)(BigDecimal(2))) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment