Comments (10)
The problem is t = NewTriDense(n, computeKind, nil)
. The pointer itself is passed by value (copied). This doesn't modify what the pointer points to, it changes the pointer altogether. What you really want is *t = *NewTriDense
, you want to assign the value the pointer points to for the code to have the intended effect.
from matrix.
I don't understand what's being suggested. The original title is to add Exp
to Triangular. That seems fine. By "arithmetic functions" do you mean Add
etc? That would be fine too, though it would probably better to have a separate tracking issue.
Is the part about dual numbers an implementation suggestion for Exp
, or a suggestion to modify the implementation of TriDense
to support the use case of a triangle of dual numbers?
(I do have https://github.com/btracey/hyperdual if you need it)
from matrix.
The suggestion is only to add an Exp
function to TriDense. Subsequently, I think it could be interesting to add Sub
to TriDense and slightly modify Add
of TriDense to simplify the operation if the provided matrix has an even number of rows.
There will be no support for dual numbers, I'll just be using some of their properties as a tool to simplify the number of operations needed.
(P.S.: I think there's a bug in your hyperdual
implementation in the Add function. I think line 44 should be a.data[i] += v
.)
from matrix.
Sorry for the multiple comments here. I'm encountering an oddity in the implementation, and I suspect that it's due to my total misunderstanding of how reuseAs
works. Any hints would be appreciated.
It seems to me that reuseAs
prevents modifications of the underlying data, as if there was a deferred function which resets it to the original value.
Here's an output from a basic test that I'm running: the first matrix shown is printed within the new Exp
function, and the second one is printed from the main (input matrix is mat64.NewTriDense(2, matrix.Lower, []float64{0, 0, 2, 0})
).
⎡1 0⎤
⎣2 1⎦
⎡0 0⎤
⎣0 0⎦
Below is the code executed in this test:
func (t *TriDense) Exp(a Triangular) {
n, kind := a.Triangle()
t.reuseAs(a.Triangle())
if n%2 == 0 {
// Exponential is trivial. Calculation performed on lower triangular.
aP := NewTriDense(n, kind, nil)
isUpper := kind == matrix.Upper
if isUpper {
aP.Copy(a.T())
} else {
aP.Copy(a)
}
computeKind := matrix.Lower
t = NewTriDense(n, computeKind, nil)
diag := NewTriDense(n, computeKind, nil)
eye := NewTriDense(n, computeKind, nil)
nilDiag := true
for i := 0; i < n; i++ {
eye.SetTri(i, i, 1)
v := aP.At(i, i)
if v != 0 {
nilDiag = false
}
diag.SetTri(i, i, v)
aP.SetTri(i, i, 0)
}
// TODO(ChristopherRabotin): Use (*TriDense).Add(a, b) once written.
// Compute exponential which is simply diag*(eye + aP) (if diag != [0]).
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
if i >= j {
t.SetTri(i, j, eye.At(i, j)+aP.At(i, j))
}
}
}
if !nilDiag {
t.MulTri(diag, t)
}
if isUpper {
t.Copy(t.T())
}
fmt.Printf("%+v\n", Formatted(t))
} else {
// Convert to Dense then convert back to Triangle.
// The exponential of a triangular matrix is always a triangular matrix
// of the same kind.
var triExp Dense
triExp.Exp(DenseCopyOf(t))
t.Copy(&triExp) // Store result in receiver.
}
}
from matrix.
Did you figure out the internal issue (I can describe if not)?
from matrix.
reuseAs
doesn't do anything with copying and defer. reuseAs
checks the size of the receiver if it is non-zero, and makes it the correct size if it is non-zero.
I'm not exactly sure where you're printing, but t.Copy(t.T())
is wrong. Copy can't be used with itself as a receiver. This is a bug in TriDense.Copy
, it should panic like the Dense version does.
from matrix.
As a side note, you should probably working with upper triangular matrices. They're faster in gonum since we use row-major storage.
from matrix.
from matrix.
from matrix.
Closed as per #420 (comment).
from matrix.
Related Issues (20)
- Support for n-dimensional matrices HOT 5
- matrix: Repo description should not end in a "." HOT 2
- matrix/mat64: Should view follow Go slicing syntax HOT 3
- matrix/mat64: Ability to get SymDense from Dense HOT 10
- matrix/mat64: Dense.Inverse does not fail on singular matrix HOT 10
- mat64: Dense.Inverse test coverage needs improvement
- Update format documentation to include additional format verbs HOT 3
- matrix/mat64: question: re-use of memory for mat64.Vector pointers seems confusing HOT 8
- Failed io_tests HOT 5
- matrix/mat64: Question: add `mat64.Merge` helper function HOT 2
- mat64: rethink XFromY API for extracting matrices from decompositions HOT 2
- mat64: TestDet is flakey HOT 2
- mat64: Eigen returns 0 as values and left and right vectors
- mat64: add examples for GSVD and HOGSVD
- matrix/mat64: Formatted excerpt and prefix do not play nicely together
- matrix/mat64: remove outdated Jama comments
- Question: how add a new column/row to the beginning and end of a matrix? HOT 2
- matrix: implement random method HOT 1
- type Transpose is hard to use in some case ? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matrix.