This repository was archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Addsym #90
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
191c887
Added NewSymmetric and Dims functions
btracey ba43817
Added symmetric At, Set, and added tests
btracey dbf0a75
merged from master
btracey 3be6cd0
Added At test on opposite side
btracey ca98a6f
Fixed incorrect comment
btracey e2bf675
Added panic test for symmetric when input data is too small
btracey 77f844a
Changed Set to SetSym and made all Symmetric matrices Upper. Updated …
btracey 625430c
Changed to SetSym in both bounds files and updated tests
btracey 8332e7a
Removed Trans check in Symmetric At
btracey 2c5ab0b
Fixed outdated comment
btracey e1e53ad
Fixed SetSym to allow internal set on either side of the matrix
btracey 7e92d51
Added newlines between function lines
btracey 4d7532a
Merge branch 'master' of http://github.com/gonum/matrix into addsym
btracey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package mat64 | ||
|
|
||
| import ( | ||
| "github.com/gonum/blas" | ||
| "github.com/gonum/blas/blas64" | ||
| ) | ||
|
|
||
| // Symmetric represents a symmetric matrix. | ||
| type Symmetric struct { | ||
| mat blas64.Symmetric | ||
| } | ||
|
|
||
| // NewSymmetric constructs an n x n symmetric matrix. If len(mat) == n * n, | ||
| // mat will be used to hold the underlying data, or if mat == nil, new data will be allocated. | ||
| // The underlying data representation is the same as a Dense matrix, except | ||
| // the values of the entries in the lower triangular portion are completely ignored. | ||
| func NewSymmetric(n int, mat []float64) *Symmetric { | ||
| if n < 0 { | ||
| panic("mat64: negative dimension") | ||
| } | ||
| if mat != nil && n*n != len(mat) { | ||
| panic(ErrShape) | ||
| } | ||
| if mat == nil { | ||
| mat = make([]float64, n*n) | ||
| } | ||
| return &Symmetric{blas64.Symmetric{ | ||
| N: n, | ||
| Stride: n, | ||
| Data: mat, | ||
| Uplo: blas.Upper, | ||
| }} | ||
| } | ||
|
|
||
| func (s *Symmetric) Dims() (r, c int) { | ||
| return s.mat.N, s.mat.N | ||
| } | ||
|
|
||
| func (s *Symmetric) RawSymmetric() blas64.Symmetric { | ||
| return s.mat | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package mat64 | ||
|
|
||
| import ( | ||
| "github.com/gonum/blas" | ||
| "github.com/gonum/blas/blas64" | ||
| "gopkg.in/check.v1" | ||
| ) | ||
|
|
||
| func (s *S) TestNewSymmetric(c *check.C) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test for a panic with ErrShape?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| for i, test := range []struct { | ||
| data []float64 | ||
| N int | ||
| mat *Symmetric | ||
| }{ | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a check for matrix equality with a Dense? |
||
| data: []float64{ | ||
| 1, 2, 3, | ||
| 4, 5, 6, | ||
| 7, 8, 9, | ||
| }, | ||
| N: 3, | ||
| mat: &Symmetric{blas64.Symmetric{ | ||
| N: 3, | ||
| Stride: 3, | ||
| Uplo: blas.Upper, | ||
| Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, | ||
| }}, | ||
| }, | ||
| } { | ||
| t := NewSymmetric(test.N, test.data) | ||
| rows, cols := t.Dims() | ||
| c.Check(rows, check.Equals, test.N, check.Commentf("Test %d", i)) | ||
| c.Check(cols, check.Equals, test.N, check.Commentf("Test %d", i)) | ||
| c.Check(t, check.DeepEquals, test.mat, check.Commentf("Test %d", i)) | ||
|
|
||
| m := NewDense(test.N, test.N, test.data) | ||
| c.Check(t.mat.Data, check.DeepEquals, m.mat.Data, check.Commentf("Test %d", i)) | ||
|
|
||
| c.Check(func() { NewSymmetric(3, []float64{1, 2}) }, check.PanicMatches, ErrShape.Error()) | ||
| } | ||
| } | ||
|
|
||
| func (s *S) TestTriAtSet(c *check.C) { | ||
| t := &Symmetric{blas64.Symmetric{ | ||
| N: 3, | ||
| Stride: 3, | ||
| Uplo: blas.Upper, | ||
| Data: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9}, | ||
| }} | ||
| rows, cols := t.Dims() | ||
| // Check At out of bounds | ||
| c.Check(func() { t.At(rows, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.At(0, cols) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
| c.Check(func() { t.At(rows+1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.At(0, cols+1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
| c.Check(func() { t.At(-1, 0) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.At(0, -1) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
|
|
||
| // Check Set out of bounds | ||
| c.Check(func() { t.SetSym(rows, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.SetSym(0, cols, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
| c.Check(func() { t.SetSym(rows+1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.SetSym(0, cols+1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
| c.Check(func() { t.SetSym(-1, 0, 1.2) }, check.PanicMatches, ErrRowAccess.Error(), check.Commentf("Test row out of bounds")) | ||
| c.Check(func() { t.SetSym(0, -1, 1.2) }, check.PanicMatches, ErrColAccess.Error(), check.Commentf("Test col out of bounds")) | ||
|
|
||
| c.Check(t.At(2, 1), check.Equals, 6.0) | ||
| c.Check(t.At(1, 2), check.Equals, 6.0) | ||
| t.SetSym(1, 2, 15) | ||
| c.Check(t.At(2, 1), check.Equals, 15.0) | ||
| c.Check(t.At(1, 2), check.Equals, 15.0) | ||
| t.SetSym(2, 1, 12) | ||
| c.Check(t.At(2, 1), check.Equals, 12.0) | ||
| c.Check(t.At(1, 2), check.Equals, 12.0) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add new line between funcs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.