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

Subarray of an array with undefined members. #3868

Closed
amitmurthy opened this issue Jul 29, 2013 · 3 comments
Closed

Subarray of an array with undefined members. #3868

amitmurthy opened this issue Jul 29, 2013 · 3 comments

Comments

@amitmurthy
Copy link
Contributor

It ought to be possible to get a sub array of an array with undefined members - for cases where you want to allocate an array once and then use different functions to populate different parts of the array.

foo = cell(10)
init1(foo[1:4])
init2(foo[5:end])

Currently

julia> foo=cell(3)
3-element Any Array:
 #undef
 #undef
 #undef

julia> bar=foo[2:end]
ERROR: access to undefined reference
 in unsafe_copy! at array.jl:51
 in copy! at array.jl:61
 in getindex at array.jl:295

I understand why the above is happening but is it possible just to leave the same fields as undefined in the subarray?

@kmsquire
Copy link
Member

You said you understood, but just to clear things up for anyone else that might be reading, f[2:end] is a copy of the values from 2:end, and isnt' a SubArray:

julia> foo = cell(3)
3-element Any Array:
 #undef
 #undef
 #undef

julia> bar = sub(foo, 2:3)
2-element SubArray of 3-element Any Array:
 #undef
 #undef

So you're asking that undefined references be copied when you create a new array from a reference to part of that array? How is that useful?

@amitmurthy
Copy link
Contributor Author

Sorry, I was using the term "sub array" to mean "part of the original array" and not in the Julian sense. I understand now that the part range of an array will always results in a copy.

@kmsquire
Copy link
Member

No worries. There's actually been a lot of recent discussion on making f[2:end] an actual SubArray, but there are some sticking points.

IanButterworth pushed a commit that referenced this issue Apr 11, 2024
…626b0 (#54049)

Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: release-1.10
Julia branch: backports-release-1.10
Old commit: 70525539d
New commit: f487626b0
Julia version: 1.10.2
Pkg version: 1.10.0(Does not match)
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@7052553...f487626

```
$ git log --oneline 70525539d..f487626b0
f487626b0 Merge pull request #3868 from JuliaLang/backports-release-1.10
e4a6078a2 prune manifest after the set of some deps have been "demoted" to weakdeps (#3864)
72ba57759 Report failures to download artifacts as failures (#3860)
4ee732f1b why: show more when package is both a direct and indirect dep (#3771)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
IanButterworth pushed a commit that referenced this issue Apr 12, 2024
…626b0 (#54049)

Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: release-1.10
Julia branch: backports-release-1.10
Old commit: 70525539d
New commit: f487626b0
Julia version: 1.10.2
Pkg version: 1.10.0(Does not match)
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@7052553...f487626

```
$ git log --oneline 70525539d..f487626b0
f487626b0 Merge pull request #3868 from JuliaLang/backports-release-1.10
e4a6078a2 prune manifest after the set of some deps have been "demoted" to weakdeps (#3864)
72ba57759 Report failures to download artifacts as failures (#3860)
4ee732f1b why: show more when package is both a direct and indirect dep (#3771)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Drvi pushed a commit to RelationalAI/julia that referenced this issue Jun 7, 2024
…626b0 (JuliaLang#54049)

Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: release-1.10
Julia branch: backports-release-1.10
Old commit: 70525539d
New commit: f487626b0
Julia version: 1.10.2
Pkg version: 1.10.0(Does not match)
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@7052553...f487626

```
$ git log --oneline 70525539d..f487626b0
f487626b0 Merge pull request JuliaLang#3868 from JuliaLang/backports-release-1.10
e4a6078a2 prune manifest after the set of some deps have been "demoted" to weakdeps (#3864)
72ba57759 Report failures to download artifacts as failures (JuliaLang#3860)
4ee732f1b why: show more when package is both a direct and indirect dep (JuliaLang#3771)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
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

2 participants