wchresta / matrix-static Goto Github PK
View Code? Open in Web Editor NEWWrapper around matrix that adds matrix sizes to the type-level
License: BSD 3-Clause "New" or "Revised" License
Wrapper around matrix that adds matrix sizes to the type-level
License: BSD 3-Clause "New" or "Revised" License
Data.Matrix.prettyMatrix
produces a String that looks nice on its own, but it doesn't have some properties that a good Show instance should have.
Firstly, when embedded inside other String
s obtained from Show
, the results can be very strange. In my code, I have some datatypes that contain matrices, and I am logging the results to a file after using a general pretty-printer (http://hackage.haskell.org/package/pretty-show-1.10/docs/Text-Show-Pretty.html). When the pretty printer encounters matrices, it gets completely confused because they do not look like normal Haskell expressions.
Secondly, derived instances of Show
have the following property, according to the documentation: "The result of show
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used." Several datatypes try to mimic this property in their Show instances. For example, show
applied to a Map
gives something like fromList [(1,2), (3,4)]
.
I propose that the Show
instance for a matrix should use toLists
, so that, for example, show
-ing the 2x2 identity matrix gives either
-- This is in the same spirit as Data.Map, and gives an expression
-- that can be copied and pasted into ghci to give a matrix
fromLists [[1,0],[0,1]]
or just
-- This is in the spirit of Data.Vector. It gives an expression that cannot
-- precisely be copied into ghci, but it does follow Haskell syntax and is
-- shorter/simpler than the above
[[1,0],[0,1]]
Looks like rref
gives wrong results:
rref <$> (fromLists [[1, 2, 1], [(-2), (-3), 1], [3, 5, 0]] :: Maybe (Matrix 3 3 Double))
gives:
Just (Left "Attempt to invert a non-invertible matrix")
Although Python's sympy gives:
m = Matrix([[1,2,1], [-2,-3,1], [3,5,0]])
m.rref()
(Matrix([
[1, 0, -5],
[0, 1, 3],
[0, 0, 0]]), (0, 1))
The Applicative
instance for Data.Matrix.Static.Matrix
appears to simply inherit the Applicative
instance from Data.Matrix.Matrix
:
matrix-static/src/Data/Matrix/Static.hs
Line 126 in 2588136
However, the pure
implementation for Data.Matrix.Matrix
just creates a 1 by 1 matrix:
http://hackage.haskell.org/package/matrix-0.3.6.1/docs/src/Data-Matrix.html#line-194
This seems to be a problem. (Forgive me if I missed something -- I have just been reading the code, and I haven't tested this issue.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.