Skip to content
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

Indexing into Float64 calculation #20

Closed
adinhobl opened this issue Jan 10, 2021 · 3 comments
Closed

Indexing into Float64 calculation #20

adinhobl opened this issue Jan 10, 2021 · 3 comments

Comments

@adinhobl
Copy link

In this line in Lecture 2, you calculate val = A[i,j] + B[i,j], which should come out as a Float64. In the next line, you index into val, the Float64, which somehow works without erroring.
https://github.com/mitmath/18337/blob/cdd7b2078048d83ff1180f7c8832ff2efb3ad058/lecture2/optimizing.jmd#L157

The function compiles and runs correctly, however, I don't know if this is necessary or just leftover from a previous function. In addition, at least on my machine, the @btime is faster if you take the indexing out.

@wi11dey
Copy link
Contributor

wi11dey commented Jan 10, 2021

I think the indexing into Float64 behavior is so Numbers can be used like a 0-tensor when necessary, like for linear algebra. JuliaLang/julia#1871

It works bc of https://github.com/JuliaLang/julia/blob/master/base/number.jl#L94, and might be slower because it has to check that the index is 1, though I would hope the compiler takes care of it. Fwiw it's actually a couple ms slower without the indexing on my machine, so probably just @btime error. I agree it isn't necessary in this case anyway

@ChrisRackauckas
Copy link
Member

Yes oops, we probably shouldn't index into the val. It's accidentally relying on the 0-tensor behavior. I think in the video I correct it, but I forgot to fix the notes.

@adinhobl
Copy link
Author

adinhobl commented Jan 12, 2021

Thanks @wi11dey for the color. It's nice to see some of the reasoning that went into design choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants