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

ndarray: getindex/setindex! linear indexing #294

Merged
merged 4 commits into from
Nov 9, 2017

Conversation

iblislin
Copy link
Member

@iblislin iblislin commented Oct 9, 2017

x = mx.zeros(2, 5)
x[5] = 42

```julia
x = mx.zeros(2, 5)
x[5] = 42
```
@codecov-io
Copy link

codecov-io commented Oct 9, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@f839be1). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #294   +/-   ##
=========================================
  Coverage          ?   69.43%           
=========================================
  Files             ?       25           
  Lines             ?     1924           
  Branches          ?        0           
=========================================
  Hits              ?     1336           
  Misses            ?      588           
  Partials          ?        0
Impacted Files Coverage Δ
src/ndarray.jl 85.38% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f839be1...a7f28db. Read the comment docs.

idx %= offset
end

_at(handle, idx) |> MX_NDArrayHandle |> x -> NDArray(x, arr.writable)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is kinda weird to return a one element array and also not common in Julia. The problem is if we convert it to a Julia value at this point we impose a synchronisation barrier.

Copy link
Member Author

@iblislin iblislin Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the weirdness, Python provide an API nd.asscalar() for conducting reading value.
I think in Julia, we can have first for reading it.

looks like this

x[42] |> first  # do synchronisation and get the value

and keep x[42] returning an NDArray

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can send a PR for first api. If you agree with that design

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the first design. I think we should make it explicit for users that an NDArray is not some transparent array, and it could potentially be on GPU and could potentially be slow to do indexing into every single element of it.

BTW: I feel I'm pretty out-dated about the latest Julian things when I see the |> and operators. :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first implemented @ 62bd213

@iblislin iblislin mentioned this pull request Nov 1, 2017
5 tasks
@@ -26,6 +26,26 @@
2.0 4.0
```

* `NDArray` `getindex`/`setindex!` linear indexing support and `first` for extracting scalar value. (#TBD)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#TBD?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(at first I wrote this patch, the issue number was still unknown)
I will send a PR to sort them out for releasing.

@pluskid
Copy link
Member

pluskid commented Nov 8, 2017

Thanks! LGTM. Can you resolve the conflicts in NEWS.md?

@iblislin
Copy link
Member Author

iblislin commented Nov 9, 2017

resolved

@pluskid pluskid merged commit 4919273 into dmlc:master Nov 9, 2017
@iblislin iblislin deleted the nd-linear-idx branch November 9, 2017 15:12
@iblislin iblislin added this to the v0.3.0 milestone Nov 13, 2017
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

Successfully merging this pull request may close these issues.

4 participants