-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More types for nodes #26
Conversation
Wouldn't this make all of the indexing not type-stable (if used)? It could be useful but it would be much slower. |
Accessing the parametric fields with haskell-style head/tail recursive function application is type-stable in this version. But you're right - array access is now unstable! creating a big problem to solve a small one. I'll have a look, but I imagine it would require making everything recursive to fix it. It's also possible 0.7 union types will be fast enough to fix this for small problems. |
That's fine if broadcast is defined appropriately. And I think it's parametrically-unstable: for the standard vector types it's still type-stable, but only when you put something odd in there it will not be.
Yeah, that should be fine. This needs passing tests though. |
I think it will still be a net gain for me because I'll have unstable types everywhere using an union vector anyway, my problem is basically the same as discussed in #5. And yes I hoped this change just makes it easier to do something slow, but should work as usual if you just use a typed Vector. I'll get the tests passing, was saving time in case this was just a bad idea. |
Seems this is failing on master as well - but not the same commit on tag v.0.6? Master fails locally for me on 0.6.2. |
Interesting. I'll have to find time to take a look at it. The code you have looks fine. |
@@ -25,7 +58,7 @@ end | |||
|
|||
@inline function getindex(m::AbstractMultiScaleArray, i, I...) | |||
if isempty(m.values) || i < length(m.end_idxs) | |||
length(I) == 1 ? m.nodes[i].nodes[I[1]] : m.nodes[i][I...] |
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.
I'm not sure what this line does? Seems like it can error in a couple of ways... The tuple version is not type stable currently
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.
It handles the case where I
is a scalar since then it cannot splat I think.
getindex for parametric typed tuples seems to be pretty much type stable now, except for the line mentioned above. I'll do some more comprehensive tests of type stability and some general tests and push them in the next few days. Maybe it could be optimised more too, I'm not that clear on when Also there's probably a much more julian way of doing this. It looks pretty weird. |
Indexing type stability turned out to be easier than I thought. But the real problem turns out to be that running an ODE triggers |
One of the tests is about resizing. Resizing and mutability is one of the possible behaviors. However, it's only done if the user makes an event that triggers it. It shouldn't be triggered on its own. |
test/tuple_nodes.jl
Outdated
@@ -89,7 +89,7 @@ growing_cb = DiscreteCallback(condition, affect!) | |||
|
|||
println("ODE with tuple nodes") | |||
|
|||
prob = ODEProblem(f, scenario, (0.0, 1.0)) | |||
prob = ODEProblem(f, dscenario, scenario, (0.0, 1.0)) |
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.
This syntax doesn't make sense. The previous one was correct.
The test problem you're using has an event: tstop = [0.5]
condition = function (u, t, integrator)
t ∈ tstop
end
affect! = function (integrator)
add_node!(integrator, integrator.u[1, 1, 1], 1, 1)
end
growing_cb = DiscreteCallback(condition, affect!) that tries to add a new |
@@ -7,7 +10,7 @@ Base.IndexStyle(::Type{<:AbstractMultiScaleArray}) = IndexLinear() | |||
@inline function getindex(m::AbstractMultiScaleArray, i::Int) | |||
idx = bisect_search(m.end_idxs, i) | |||
idx > 1 && (i -= m.end_idxs[idx-1]) # also works with values | |||
(isempty(m.values) || idx < length(m.end_idxs)) ? m.nodes[idx][i] : m.values[i] | |||
(isempty(m.values) || idx < length(m.end_idxs)) ? nodeselect(m.nodes, idx, i) : m.values[i] |
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.
this is no different?
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.
Sorry turned out that wasn't even needed after all, something else fixed the type stability. I'm still scratching my head...
Ok that makes sense with the event, I just copied some of your tests for arrays. But it's good to know where using tuples will break. I will look at writing an add_node! method that replaces the whole tuple so you can use events if you use a mutable type. |
I think my tests are all passing, the test that failing is line 67 of dinamic_diffeq.jl:
And that's also failing on master. |
Rebased. |
Passing. Can this get docs? |
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
=======================================
Coverage 80.23% 80.23%
=======================================
Files 7 7
Lines 167 167
=======================================
Hits 134 134
Misses 33 33 Continue to review full report at Codecov.
|
Yes that's a good idea. It might not be for a week or so with my current workload. |
I went ahead and added the docs. Cheers! |
thanks!
…On Tue, May 8, 2018 at 10:58 PM, Christopher Rackauckas < ***@***.***> wrote:
Merged #26 <#26>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACaqeendQqVfL7yKQtNAusxPa-kc94j9ks5twZZygaJpZM4TjutX>
.
|
I needed parametric types on nodes, with different type parameters on each node. With Vectors that gives Union types.
Not for merging yet - I'll follow up with some tests. Just checking this is a reasonable idea.