GithubHelp home page GithubHelp logo

arrayviews.jl's Introduction

ArrayViews.jl

Build Status Coverage Status

ArrayViews

A Julia package to explore a new system of array views.


For users of julia 0.4 or higher

By and large, this package is no longer necessary: base julia now has efficient SubArrays (i.e., sub and slice). In choosing whether to use SubArrays or the ArrayViews package, here are some considerations:

Reasons to prefer SubArrays:

  • ArrayViews can only make a view of an Array, whereas SubArrays can create a view of any AbstractArray.

  • The views created by ArrayViews are most efficient for ContiguousViews such as column slices. In contrast, the views created by SubArrays are efficient for any type of view (e.g., also row slices), in some cases resulting in a 3- to 10-fold advantage. In either case, it's generally recommended to write functions using cartesian indexing rather than linear indexing (e.g., for I in eachindex(S) rather than for i = 1:length(S)), although in both cases there are some view types that are also efficient under linear indexing.

  • SubArrays allow more general slicing behavior, e.g., you can make a view with S = sub(A, [1,3,17], :).

  • By default, SubArrays check bounds upon construction whereas ArrayViews do not: V = view(A, -5:10, :) does not generate an error, and if V is used in a function with an @inbounds declaration you are likely to get a segfault. (You can bypass bounds checking with Base._sub and Base._slice, in cases where you want out-of-bounds construction for SubArrays.)

Reasons to prefer ArrayViews:

  • Construction of SubArrays is frequently (but not always) 2-4 times slower than construction of views. If you are constructing many column views, ArrayViews may still be the better choice.

Main Features

  • An efficient aview function that implements array views
  • Support of arrays of arbitrary dimension and arbitrary combinations of indexers
  • Support aview composition (i.e. construct views over views)
  • Special attention to ensure type stability in most cases
  • Efficient indexing (both cartesian and linear)
  • Light weight array view construction
  • A systematic approach to detect contiguous views (statically)
  • Views work with linear algebra functions

Overview

The key function in this package is aview. This function is similar to sub in Julia Base, except that it returns an aview instance with more efficient representation:

a = rand(4, 5, 6)

aview(a, :)
aview(a, :, 2)
aview(a, 1:2, 1:2:5, 4)
aview(a, 2, :, 3:6)

The aview function returns an array view of type ArrayView. Here, ArrayView is an abstract type with two derived types (ContiguousView and StridedView), defined as:

abstract type ArrayView{T,N,M} <: DenseArray{T,N} end

We can see that each view type has three static properties: element type T, the number of dimensions N, and the contiguous rank M.

Contiguous Rank

The contiguous rank plays an important role in determining (statically) the contiguousness of a subview. Below are illustrations of 2D views respective with contiguous rank 0, 1, and 2.

2D View with contiguous rank 0

* * * * * *
. . . . . .
* * * * * *
. . . . . .
* * * * * *
. . . . . .

Here, * indicates a position covered by the array view, and . otherwise. We can see that the columns are not contiguous.

2D View with contiguous rank 1

* * * * * *
* * * * * *
* * * * * *
* * * * * *
. . . . . .
. . . . . .

We can see that each column is contiguous, while the entire array view is not.

2D View with contiguous rank 2

* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *

The entire 2D array view is contiguous.

Formally, when v is an array view with contiguous rank M, then aview(v, :, :, ..., :, 1) must be contiguous when the number of colons is less than or equal to M.

View Types

The package provide a hierarchy of array view types (defined as follows):

# T: the element type
# N: the number of dimensions
# M: the contiguous rank

abstract StridedArrayView{T,N,M} <: DenseArray{T,N}
abstract ArrayView{T,N,M} <: StridedArrayView{T,N,M}
abstract UnsafeArrayView{T,N,M} <: StridedArrayView{T,N,M}

immutable ContiguousView{T,N,Arr<:Array} <: ArrayView{T,N,N}
immutable StridedView{T,N,M,Arr<:Array} <: ArrayView{T,N,M}

immutable UnsafeContiguousView{T,N} <: UnsafeArrayView{T,N,N}
immutable UnsafeStridedView{T,N,M} <: UnsafeArrayView{T,N,M}

Here, an instance of ArrayView maintains a reference to the underlying array, and is generally safe to use in most cases. An instance of UnsafeArrayView maintains a raw pointer, and should only be used within a local scope (as it does not guarantee that the source array remains valid if it is passed out of a function).

View Types in Action

The following example illustrates how contiguous rank is used to determine aview types in practice.

a = rand(m, n)

# safe views

v0 = aview(a, :)         # of type ContiguousView{Float64, 1}

u1 = aview(a, a:b, :)    # of type StridedView{Float64, 2, 1}
u2 = aview(u1, :, i)     # of type ContiguousView{Float64, 1}

v1 = aview(a, a:2:b, :)  # of type StridedView{Float64, 2, 0}
v2 = aview(v1, :, i)     # of type StridedView{Float64, 1, 0}

# unsafe views

v0 = unsafe_aview(a, :)         # of type UnsafeContiguousView{Float64, 1}

u1 = unsafe_aview(a, a:b, :)    # of type UnsafeStridedView{Float64, 2, 1}
u2 = unsafe_aview(u1, :, i)     # of type UnsafeContiguousView{Float64, 1}

v1 = unsafe_aview(a, a:2:b, :)  # of type UnsafeStridedView{Float64, 2, 0}
v2 = unsafe_aview(v1, :, i)     # of type UnsafeStridedView{Float64, 1, 0}

Four kinds of indexers are supported, integer, range (e.g. a:b), stepped range (e.g. a:b:c), and colon (i.e., :).

View Construction

The procedure of constructing a aview consists of several steps:

  1. Compute the shape of an array view. This is done by an internal function vshape.

  2. Compute the offset of an array view. This is done by an internal function aoffset. The computation is based on the following formula:

    offset(v(I1, I2, ..., Im)) = (first(I1) - 1) * stride(v, 1)
                               + (first(I2) - 1) * stride(v, 2)
                               + ...
                               + (first(Im) - 1) * stride(v, m)
    
  3. Compute the contiguous rank, based on both view shape and the combination of indexer types. A type ContRank{M} is introduced for static computation of contiguous rank (please refer to src/contrank.jl for details).

  4. Construct a aview, where the array view type is determined by both the number of dimensions and the value of contiguous rank (which is determined statically).

For runtime efficiency, specialized methods of these functions are implemented for views of 1D, 2D, and 3D. These methods are extensively tested.

Convenience Functions

The ArrayViews package provides several functions to make it more convenient to constructing certain views:

diagview(a)   # make a strided view of the diagonal elements, the length is `min(size(a)...)`
              # `a` needs to be a matrix here (contiguous or strided)

flatten_view(a)   # make a contiguous view of `a` as a vector
                  # `a` needs to be contiguous here

reshape_view(a, shp)   # make a contiguous view of `a` of shape `shp`
                       # `a` needs to be contiguous here.

rowvec_view(a, i)   # make a view of `a[i,:]` as a strided vector.
                    # `a` needs to be a matrix here (contiguous or strided)

ellipview(a, i)     # make a view of the i-th slice of a
                    # e.g. `a` is a matrix => this is equiv. to `aview(a, :, i)`
                    #      `a` is a cube => this is equiv. to `aview(a, :, :, i)`, etc.

arrayviews.jl's People

Contributors

ahwillia avatar amontoison avatar andreasnoack avatar goretkin avatar iainnz avatar jakebolewski avatar jaredcrean2 avatar keno avatar lindahua avatar ranocha avatar rened avatar simonbyrne avatar simonster avatar timholy avatar tkelman avatar yuyichao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arrayviews.jl's Issues

Requires Julia 0.3

ArrayViews does not work on Julia 0.2, since it needs the DenseArray type. Please add the correct dependency in the REQUIRE file.

reshape_view with slices

This is not so much an issue as a question. You mention in the README that slices now provide the same features as this package. I'm a big fan of reshape_view -- can the behaviour of this function be obtained with slices?

Deepcopy Behavior

Deepcopying an ArrayView gives another ArrayView, so the underlying data is still shared. Would it be more consistent with the idea of deepcopying to return a new, fully independent array with the values copied?

Here is a simple test case:

using ArrayViews

A = rand(3,3)
b = view(A, :, 1)
c = deepcopy(b)
println("typeof(c) = ", typeof(c))

gives output typeof(c) = ArrayViews.ContiguousView{Float64,1,Array{Float64,2}}

ERROR: DenseArray not defined

Hi there,

I'm getting an error when trying to import/use ArrayViews.

julia> using ArrayViews
ERROR: DenseArray not defined
in include at boot.jl:238
in include_from_node1 at loading.jl:114
in reload_path at loading.jl:140
in _require at loading.jl:58
in require at loading.jl:43
at /Users/haroldsoh/.julia/ArrayViews/src/ArrayViews.jl:31

Help would be appreciated! Thanks!

P.S. I'm using Julia 0.2.0 on Mac OSX Mavericks.

Can't install ArrayViews

After Pkg.add("ArrayViews") I got the following error:

The following package names could not be resolved:
 * ArrayViews (not found in project, manifest or registry)
Please specify by known `name=uuid`.

Can anyone help me with this issue? Thanks!

Missing bounds checking in view - intentional?

Is it intentional (eg for speed reasons) that this does not throw an error?

view(rand(2),2:3)
2-element ContiguousView{Float64,1,Array{Float64,1}}:
   0.198847
 #undef 

If intentional, I would suggest adding a little note/example to the readme.

thanks!

Is there a maximum number of dimensions? what is it?

I realize there is a maximum number of dimensions you support:

A = rand(2,2,2,2,2)
maximum(A,5)
ERROR: no method contrank(Colon, Colon, Colon, Colon, Int64)

are there plans to increase the maximum number of dimensions? (if that's what's going on here).

Row Vector Dimension

I am using ArrayViews to loop over a big array and operate on little slices of it. It works extremely well and is very convenient, but I noticed that if I am extracting a row vector from a high dimensional array (N > 2), the result is a 2 dimensional array view.
For example

big_array = randn(2,2, 3, 4)
view1 = view(big_array, 1, :, 1, 1)

gives a 1x2 ArrayViews.StridedView{Float64,2,0,Array{Float64,4}}:
I would have expected this to give a 1 dimensional strided view, rather than a 2 dimensional view. Is this the expected behavior?

[PackageEvaluator.jl] Your package ArrayViews may have a testing issue.

This issue is being filed by a script, but if you reply, I will see it.

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their test (if available) on both the stable version of Julia (0.2) and the nightly build of the unstable version (0.3).

The results of this script are used to generate a package listing enhanced with testing results.

The status of this package, ArrayViews, on...

  • Julia 0.2 is 'Package doesn't load.' PackageEvaluator.jl
  • Julia 0.3 is 'Tests fail, but package loads.' PackageEvaluator.jl

'No tests, but package loads.' can be due to their being no tests (you should write some if you can!) but can also be due to PackageEvaluator not being able to find your tests. Consider adding a test/runtests.jl file.

'Package doesn't load.' is the worst-case scenario. Sometimes this arises because your package doesn't have BinDeps support, or needs something that can't be installed with BinDeps. If this is the case for your package, please file an issue and an exception can be made so your package will not be tested.

This automatically filed issue is a one-off message. Starting soon, issues will only be filed when the testing status of your package changes in a negative direction (gets worse). If you'd like to opt-out of these status-change messages, reply to this message.

Performance Regression with release-0.4

I did some benchmarks here and found a factor of 2 slowdown using the release-0.4 compared to an older version of 0.4 (both using --check-bounds=no)

with the old version:

warming up
 183.968 milliseconds
double loop @time printed above
 146.824 milliseconds
ArrayView @time printed above
 146.653 milliseconds
callable object @time printed above
Final testing: 

 196.033 milliseconds
double loop @time printed above
 147.843 milliseconds
ArrayView @time printed above
 146.399 milliseconds
callable object @time printed above

with release-0.4

warming up
  0.184568 seconds
double loop @time printed above
  0.289675 seconds
ArrayView @time printed above
  0.298988 seconds
callable object @time printed above
Final testing: 

  0.183772 seconds
double loop @time printed above
  0.299504 seconds
ArrayView @time printed above
  0.312451 seconds
callable object @time printed above

The old version info

Julia Version 0.4.0-dev+5149
Commit 317a4d1* (2015-06-01 18:58 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7 CPU       Q 820  @ 1.73GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

The new version info

Julia Version 0.4.3-pre+6
Commit adffe19* (2015-12-11 00:38 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7 CPU       Q 820  @ 1.73GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

The slowdown occurs when using ArrayViews, which is also used for the callable object test.

Tag Versions for `aview` change

Could you tag versions before and after the view -> aview change? This would make it easier to specify the right version in the REQUIRE file.

Using view() with map()

Is there a way to apply map() to an ArrayView in Julia?

using ArrayViews
A = rand(10,10);
sum(map(x->x>0.5,A[1,:])); # works, gives something reasonable, e.g. 5
sum(map(x->x>0.5,view(A,1,:)))

Using the ArrayView produces the following error

ERROR: `similar` has no method matching similar(::StridedView{Float64,2,0,Array{Float64,2}}, ::Type{Bool}, ::(Int64,Int64))
in similar at abstractarray.jl:116
in map at abstractarray.jl:1329

I also posted this question on stack overflow, but wasn't sure if I should post here as well. Feel free to close this if this isn't the appropriate venue.

Update README?

There seems to have been renewed interest in updating this package. I note the README seems out of date.

This package might also be a good place to keep more detailed track of any remaining advantages this package has over SubArray. The README currently lists only one advantage, construction time. Would be helpful to document this and see whether, e.g., improvements in 0.7 have closed the gap.

not working in Julia 0.2?

I'm running 0.3pre myself, but per http://pkg.julialang.org/, the 0.2 check gives:

INFO: Cloning cache of ArrayViews from git://github.com/lindahua/ArrayViews.jl.git
INFO: Installing ArrayViews v0.2.4
INFO: REQUIRE updated.
ERROR: DenseArray not defined
 in include at boot.jl:238
at /home/idunning/pkgtest/.julia/v0.2/ArrayViews/src/ArrayViews.jl:31
at /home/idunning/pkgtest/.julia/v0.2/ArrayViews/testusing.jl:1
INFO: REQUIRE updated.

Testing fails on Julia 1.0

Just to bring this out in limelight

(v1.0) pkg> test ArrayViews
   Testing ArrayViews
    Status `/var/folders/j5/12tsmc_s7xs31bmt68r6z0xh4m4bb6/T/tmpoCm6qH/Manifest.toml`
  [a5c3d3bf] ArrayViews v0.7.0
  [34da2185] Compat v1.0.1
  [2a0f44e3] Base64  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Base64`]
  [ade2ca70] Dates  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Dates`]
  [8bb1440f] DelimitedFiles  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/DelimitedFiles`]
  [8ba89e20] Distributed  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Distributed`]
  [b77e0a4c] InteractiveUtils  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/InteractiveUtils`]
  [76f85450] LibGit2  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/LibGit2`]
  [8f399da3] Libdl  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Libdl`]
  [37e2e46d] LinearAlgebra  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/LinearAlgebra`]
  [56ddb016] Logging  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Logging`]
  [d6f4376e] Markdown  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Markdown`]
  [a63ad114] Mmap  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Mmap`]
  [44cfe95a] Pkg  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Pkg`]
  [de0858da] Printf  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Printf`]
  [3fa0cd96] REPL  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/REPL`]
  [9a3f8284] Random  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Random`]
  [ea8e919c] SHA  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/SHA`]
  [9e88b42a] Serialization  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Serialization`]
  [1a1011a3] SharedArrays  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/SharedArrays`]
  [6462fe0b] Sockets  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Sockets`]
  [2f01184e] SparseArrays  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/SparseArrays`]
  [10745b16] Statistics  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Statistics`]
  [8dfed614] Test  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Test`]
  [cf7118a7] UUIDs  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/UUIDs`]
  [4ec0a83e] Unicode  [`~/src/julia/usr/bin/../share/julia/stdlib/v1.0/Unicode`]
* running arrviews.jl ...
ERROR: LoadError: LoadError: UndefVarError: Range not defined
Stacktrace:
 [1] top-level scope at none:0
 [2] include at ./boot.jl:317 [inlined]
 [3] include_relative(::Module, ::String) at ./loading.jl:1038
 [4] include at ./sysimg.jl:29 [inlined]
 [5] include(::String) at /Users/arora/.julia/packages/ArrayViews/SM75b/src/ArrayViews.jl:3
 [6] top-level scope at none:0
 [7] include at ./boot.jl:317 [inlined]
 [8] include_relative(::Module, ::String) at ./loading.jl:1038
 [9] include(::Module, ::String) at ./sysimg.jl:29
 [10] top-level scope at none:2
 [11] eval at ./boot.jl:319 [inlined]
 [12] eval(::Expr) at ./client.jl:389
 [13] top-level scope at ./none:3
in expression starting at /Users/arora/.julia/packages/ArrayViews/SM75b/src/common.jl:30
in expression starting at /Users/arora/.julia/packages/ArrayViews/SM75b/src/ArrayViews.jl:39
ERROR: LoadError: LoadError: Failed to precompile ArrayViews [a5c3d3bf-5697-5ba7-841a-c26aed266c5b] to /Users/arora/.julia/compiled/v1.0/ArrayViews/djLEy.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] macro expansion at ./logging.jl:313 [inlined]
 [3] compilecache(::Base.PkgId, ::String) at ./loading.jl:1184
 [4] _require(::Base.PkgId) at ./logging.jl:311
 [5] require(::Base.PkgId) at ./loading.jl:852
 [6] macro expansion at ./logging.jl:311 [inlined]
 [7] require(::Module, ::Symbol) at ./loading.jl:834
 [8] include at ./boot.jl:317 [inlined]
 [9] include_relative(::Module, ::String) at ./loading.jl:1038
 [10] include(::Module, ::String) at ./sysimg.jl:29
 [11] include(::String) at ./client.jl:388
 [12] top-level scope at /Users/arora/.julia/packages/ArrayViews/SM75b/test/runtests.jl:10 [inlined]
 [13] top-level scope at ./none:0
 [14] include at ./boot.jl:317 [inlined]
 [15] include_relative(::Module, ::String) at ./loading.jl:1038
 [16] include(::Module, ::String) at ./sysimg.jl:29
 [17] include(::String) at ./client.jl:388
 [18] top-level scope at none:0
in expression starting at /Users/arora/.julia/packages/ArrayViews/SM75b/test/arrviews.jl:1
in expression starting at /Users/arora/.julia/packages/ArrayViews/SM75b/test/runtests.jl:7
ERROR: Package ArrayViews errored during testing

Info about upcoming removal of packages in the General registry

As described in https://discourse.julialang.org/t/ann-plans-for-removing-packages-that-do-not-yet-support-1-0-from-the-general-registry/ we are planning on removing packages that do not support 1.0 from the General registry. This package has been detected to not support 1.0 and is thus slated to be removed. The removal of packages from the registry will happen approximately a month after this issue is open.

To transition to the new Pkg system using Project.toml, see https://github.com/JuliaRegistries/Registrator.jl#transitioning-from-require-to-projecttoml.
To then tag a new version of the package, see https://github.com/JuliaRegistries/Registrator.jl#via-the-github-app.

If you believe this package has erroneously been detected as not supporting 1.0 or have any other questions, don't hesitate to discuss it here or in the thread linked at the top of this post.

`unsafe_aview` is allocating

Or I'm measuring allocations incorrectly...

(On Julia 0.6.0 and after #53 and #51)

julia> using ArrayViews

julia> function doit(P)
                @allocated sum(unsafe_aview(P, 1, :))
              end
doit (generic function with 1 method)

julia> P = eye(10);

julia> doit(P)
548582

julia> doit(P)
224

julia> doit(P)
224

julia> function doit(P)
                @allocated sum(unsafe_aview(P, 1, :))
              end
doit (generic function with 1 method)

julia> doit(P)
160

Transfer the ownership to JuliaLang

Recently, I was completely occupied with a grant proposal and setting up a new lab, and consequently I got no chance to contribute to Julia.

It seems that there's some breakage of this package due to recent update of Julia Base.

Now, I can now resume my contribution to a limited extent. But in a long run, it is advisable to transfer some of the key packages under my ownership to JuliaLang or a proper organization.

Can somebody grant me temporary permission to transfer this package to JuliaLang? Thanks a lot.

I will also try to fix the breakage as soon as possible.

cc: @StefanKarpinski @ViralBShah

workaround for ContiguousView for linear indices - proper solution?

First of all, a big thanks for this great package, Dahua!


I would like to ask you for your input - with the current code from master I get the following behavior:

using ArrayViews
a = [1, 2, 3]
view(a,1) 
0-dimensional ContiguousView{Int64,0,Array{Int64,1}}:
#undef

As well as:

a = [1, 2, 3]
copy(view(a,1))
no method getindex(ContiguousView{Int64,0,Array{Int64,1}})
while loading In[3], in expression starting on line 2
 in _F_ at multidimensional.jl:145
 in copy! at cartesian.jl:109
 in copy at abstractarray.jl:222

Defining

getindex(a::ContiguousView) = a[1]

works for me as a workaround, but I am not sure whether this would really solve the underlying issue.

With the workaround the output becomes:

a = [1, 2, 3]
view(a,1)
0-dimensional ContiguousView{Int64,0,Array{Int64,1}}:
1

and

a = [1, 2, 3]
copy(view(a,1))
0-dimensional Array{Int64,0}:
1

Thanks!

ArrayViews - "T not defined" - Julia 0.4

Hey there,

When loading ArrayViews on Julia 0.4.0-dev+1719, I get the following error:

ERROR: T not defined
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:54
 in require at /Users/rje/julia04/usr/lib/julia/sys.dylib
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:54
 in require at /Users/rje/julia04/usr/lib/julia/sys.dylib
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
 in require at /Users/rje/julia04/usr/lib/julia/sys.dylib
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in try_include at ./client.jl:172
 in load_juliarc at ./client.jl:335
 in _start at ./client.jl:390
 in _start at /Users/rje/julia04/usr/lib/julia/sys.dylib
while loading /Users/rje/.julia/v0.4/ArrayViews/src/ArrayViews.jl, in expression starting on line 44
while loading /Users/rje/.julia/v0.4/Distributions/src/Distributions.jl, in expression starting on line 3
while loading /Users/rje/.julia/v0.4/LsqFit/src/LsqFit.jl, in expression starting on line 9
while loading /Users/rje/.juliarc.jl, in expression starting on line 1

I have to run off, but I will try to see if I can fix this a bit later today.

Thanks and best,
Rob

Indexing with integer array

julia> a = rand(5,5);
julia> view(a, :, [1,3,4])
ERROR: `view` has no method matching view(::Array{Float64,2}, ::Colon, ::Array{Int64,1})

Is this expected?

Thanks.

Support for reshape

Currently reshape on a view falls back to the method for AbstractArray, which performs a copy.

For ContiguousView at least, it seems like you'd just need a call to contiguous_view(v::ContiguousView, shp::Dims). This seemed to work for me:

 Base.reshape(v::ContiguousView, dims::Int...) = contiguous_view(v, dims)

but if doesn't throw an error if prod(dims)!=prod(v.shp) and I'm not sure what the behavior should be.

Immutable Views

I think there are a lot of situations where it would be nice to have an immutable view. I find it very useful to return ArrayViews when "querying" a larger Array, however, I'd like to make those views read-only. This is mostly for my own sanity for now, but I could see this being more important once threading gets worked into base julia.

I've started an initial attempt at this here using a simple mutable keyword.

Example:

julia> using ArrayViews

julia> a = rand(10)
10-element Array{Float64,1}:
 0.890665
 0.842478
 0.324603
 0.670892
 0.288664
 0.310353
 0.593505
 0.440294
 0.7016
 0.922143

julia> v = view(a, 1:5)
5-element ArrayViews.ContiguousView{Float64,1,Array{Float64,1}}:
 0.890665
 0.842478
 0.324603
 0.670892
 0.288664

julia> v[1] = 0.0
0.0

julia> a
10-element Array{Float64,1}:
 0.0
 0.842478
 0.324603
 0.670892
 0.288664
 0.310353
 0.593505
 0.440294
 0.7016

or

julia> a = rand(10)
10-element Array{Float64,1}:
 0.607706
 0.397484
 0.451087
 0.717503
 0.469827
 0.204694
 0.0758664
 0.486908
 0.0546228
 0.910502

julia> v = view(a, 1:5; mutable=false)
5-element ArrayViews.ContiguousView{Float64,1,Array{Float64,1}}:
 0.607706
 0.397484
 0.451087
 0.717503
 0.469827

julia> v[1] = 0.0
ERROR: Setting elements of an immutable ArrayView is not allowed.
 in uset! at /Users/rory/repos/ArrayViews.jl/src/arrviews.jl:107
 in setindex! at /Users/rory/repos/ArrayViews.jl/src/indexing.jl:122

I'm not sure if this is the best way to do this in the long run, but for now it avoids manipulating the type hierarchy or breaking any existing functionality.

Pkg.test fails on Julia 0.5

I am having trouble with testing ArrayViews on Julia 0.5.

julia> versioninfo()
Julia Version 0.5.0-rc2+0
Commit 0350e57 (2016-08-12 11:25 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.0.0)
  CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

See below:

julia> Pkg.test("ArrayViews")
INFO: Testing ArrayViews
* running arrviews.jl ...
    -- testing ContiguousView{T,1}
    -- testing ContiguousView{T,2}
    -- testing ContiguousView{T,3}
    -- testing ContiguousView{T,4}
    -- testing ContiguousView{T,5}
    -- testing UnsafeContiguousView{T,1}
    -- testing UnsafeContiguousView{T,2}
    -- testing UnsafeContiguousView{T,3}
    -- testing UnsafeContiguousView{T,4}
    -- testing UnsafeContiguousView{T,5}
    -- testing StridedView{T,1,0}
    -- testing StridedView{T,2,0}
    -- testing StridedView{T,2,1}
    -- testing StridedView{T,3,0}
    -- testing StridedView{T,3,1}
    -- testing StridedView{T,3,2}
    -- testing StridedView{T,4,0}
    -- testing StridedView{T,4,1}
    -- testing StridedView{T,4,2}
    -- testing StridedView{T,4,3}
    -- testing StridedView{T,5,0}
    -- testing StridedView{T,5,1}
    -- testing StridedView{T,5,2}
    -- testing StridedView{T,5,3}
    -- testing StridedView{T,5,4}
    -- testing UnsafeStridedView{T,1,0}
    -- testing UnsafeStridedView{T,2,0}
    -- testing UnsafeStridedView{T,2,1}
    -- testing UnsafeStridedView{T,3,0}
    -- testing UnsafeStridedView{T,3,1}
    -- testing UnsafeStridedView{T,3,2}
    -- testing UnsafeStridedView{T,4,0}
    -- testing UnsafeStridedView{T,4,1}
    -- testing UnsafeStridedView{T,4,2}
    -- testing UnsafeStridedView{T,4,3}
    -- testing UnsafeStridedView{T,5,0}
    -- testing UnsafeStridedView{T,5,1}
    -- testing UnsafeStridedView{T,5,2}
    -- testing UnsafeStridedView{T,5,3}
    -- testing UnsafeStridedView{T,5,4}
* running contrank.jl ...
* running subviews.jl ...
WARNING: both ArrayViews and Base export "view"; uses of it in module Main must be qualified
ERROR: LoadError: LoadError: UndefVarError: view not defined
 in _test_arrview(::Base.ReshapedArray{Float64,4,FloatRange{Float64},Tuple{}}, ::Float64, ::Int64, ::Vararg{Int64,N}) at /Users/arora/.julia/v0.5/ArrayViews/test/subviews.jl:29
 in include_from_node1(::String) at ./loading.jl:426
 in macro expansion; at /Users/arora/.julia/v0.5/ArrayViews/test/runtests.jl:10 [inlined]
 in anonymous at ./<missing>:?
 in include_from_node1(::String) at ./loading.jl:426
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
while loading /Users/arora/.julia/v0.5/ArrayViews/test/subviews.jl, in expression starting on line 42
while loading /Users/arora/.julia/v0.5/ArrayViews/test/runtests.jl, in expression starting on line 7
========================================================[ ERROR: ArrayViews ]=========================================================

failed process: Process(`/Users/arora/src/julia_v5/julia/usr/bin/julia -Cnative -J/Users/arora/src/julia_v5/julia/usr/lib/julia/sys.dylib --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /Users/arora/.julia/v0.5/ArrayViews/test/runtests.jl`, ProcessExited(1)) [1]

======================================================================================================================================
ERROR: ArrayViews had test errors
 in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:740
 in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
 in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
 in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
 in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258

Missing contrank method for 5D arrays

julia> a = zeros(1, 1, 1, 1);

julia> ellipview(a, 2);

julia> a = zeros(1, 1, 1, 1, 1);

julia> ellipview(a, 2);
ERROR: no method contrank(Colon, Colon, Colon, Colon, Int64)
 in view at /home/simon/.julia/ArrayViews/src/ArrayViews.jl:617
 in ellipview at /home/simon/.julia/ArrayViews/src/ArrayViews.jl:627

Pkg.test fails on Julia 0.6 (stable)

Just making sure this doesn't get lost.

 running contrank.jl ...
ERROR: LoadError: LoadError: MethodError: ArrayViews.contrank(::Colon, ::Colon, ::Colon) is ambiguous. Candidates:
  contrank(i1::Colon, i2::Colon, i3::Colon, I::Union{Colon, Range, Real}...) in ArrayViews at /home/arora/.julia/v0.6/ArrayViews/src/contrank.jl:54
  contrank(i1::Colon, i2::Colon, i3::Union{Colon, UnitRange}) in ArrayViews at /home/arora/.julia/v0.6/ArrayViews/src/contrank.jl:46
Possible fix, define
  contrank(::Colon, ::Colon, ::Colon)
Stacktrace:
 [1] crank(::Colon, ::Colon, ::Vararg{Colon,N} where N) at /home/arora/.julia/v0.6/ArrayViews/test/contrank.jl:15
 [2] test_crank(::Colon, ::Vararg{Colon,N} where N) at /home/arora/.julia/v0.6/ArrayViews/test/contrank.jl:33
 [3] macro expansion at /home/arora/.julia/v0.6/ArrayViews/test/contrank.jl:55 [inlined]
 [4] anonymous at ./<missing>:?
 [5] include_from_node1(::String) at ./loading.jl:569
 [6] include(::String) at ./sysimg.jl:14
 [7] macro expansion at /home/arora/.julia/v0.6/ArrayViews/test/runtests.jl:10 [inlined]
 [8] anonymous at ./<missing>:?
 [9] include_from_node1(::String) at ./loading.jl:569
 [10] include(::String) at ./sysimg.jl:14
 [11] process_options(::Base.JLOptions) at ./client.jl:305
 [12] _start() at ./client.jl:371

Improper View Error

I stumbled upon this behavior today:

julia> a = rand(5)
5-element Array{Float64,1}:
 0.123137
 0.370571
 0.740451
 0.857524
 0.143512

julia> view(a, :, 2)
5-element ArrayViews.ContiguousView{Float64,1,Array{Float64,1}}:
 #undef
 #undef
 #undef
 #undef
 #undef

Should this be an error?

method ambiguity on julia 0.6.0

On julia 0.5.2

const Subs = Union{Real,Colon,Range}
contrank(i1::Colon, i2::Colon, i3::Union{Colon,UnitRange}) = "3d"
contrank(i1::Colon, i2::Colon, i3::Colon, I::Subs...) = "nd"

contrank(:, :, :)

produces "nd"

on julia 0.6.0 there's a method ambiguity error (which seems more correct than chosing the nd method, but also the first method I think is strictly more specific.)

UnsafeStridedView Type Problem

I switched from manually inlining code within a for loop to using ArrayViews, and I discovered that when the array used to create the view is the field of a type, then there is a significant slowdown, and @code_warntype show an abstract type. Here is a minimal example

using ArrayViews

type mytype{T}
  arr::Array{T, 4}
end

function func1(q::AbstractArray)
# do some work
  tmp = q.*q
  return nothing
end



function runtest(obj)
(tmp, tmp, nnodes, numel) = size(obj.arr)

for i=1:numel
  for j=1:nnodes
    for k=1:2
      q_vals = unsafe_view(obj.arr, k, :, j, i)
      func1(q_vals)
     end
  end
end

end

function runtest2(obj)
(tmp, tmp, nnodes, numel) = size(obj.arr)

q_vals = zeros(2)
for i=1:numel
  for j=1:nnodes
    for k=1:2
      q_vals[1] = obj.arr[k, 1, j, i]
      q_vals[2] = obj.arr[k, 2, j, i]
      func1(q_vals)
     end
  end
end

end

# run the test
big_array = rand(2,2, 3, 50000)
obj = mytype{Float64}(big_array)

runtest(obj)
@time runtest(obj)

runtest2(obj)
@time runtest2(obj)

The output is

   1.083 seconds      (9291 k allocations: 407 MB, 4.21% gc time)
   312.813 milliseconds (3000 k allocations: 110 MB, 3.02% gc time)

The concerning line from @code_warntype runtest(obj) is:

      q_vals = call(UnsafeStridedView,GenSym(13),(GlobalRef(ArrayViews,:roffset))(GenSym(13),k::Int64,GenSym(12),j::Int64,i::Int64)::Int64,##shp#1550::Tuple{Int64,Int64},ArrayViews.ContRank{0},(GlobalRef(ArrayViews,:_vstrides))(strides(GenSym(13))::Tuple{Vararg{Int64}},1,k::Int64,GenSym(12),j::Int64,i::Int64)::Tuple{Int64,Int64})::ArrayViews.UnsafeStridedView{Float64,2,0} # line 22:

Something gets turned into a ::Tuple{Vararg{Int64}}, although I can't tell exactly what (I'm new to looking at partially compiled code). Do you think this could be the cause of the performance loss?

I'm using ArrayViews version 0.6.2 and Julia Version 0.4.0-dev+5149, Commit 317a4d1* (2015-06-01 18:58 UTC).

Thanks in advance,
Jared Crean

[PkgEval] ArrayViews may have a testing issue on Julia 0.4 (2014-10-23)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2014-10-22 the testing status was Tests pass.
  • On 2014-10-23 the testing status changed to Package doesn't load.

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

Special message from @IainNZ: This change may be due to JuliaLang/julia#8712.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("ArrayViews")' log
INFO: Installing ArrayViews v0.4.6
INFO: Package database updated

>>> 'using ArrayViews' log
ERROR: T not defined
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
 in require_3B_3948 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
 in include at ./boot.jl:242
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:293
 in _start at ./client.jl:362
 in _start_3B_3776 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/ArrayViews/src/ArrayViews.jl, in expression starting on line 44
while loading /home/idunning/pkgtest/.julia/v0.4/ArrayViews/testusing.jl, in expression starting on line 2
Julia Version 0.4.0-dev+1249
Commit 23a9373 (2014-10-23 04:46 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3


>>> test log
no tests to run
>>> end of log

Support for DArray

It would be nice if DArray would be supported by ArrayViews even if it is only a fallback to sub.

getindex with UnitRange

x = reshape(1:25, 5, 5)
v = view(x, 1:2:5, 1:2:5)
v[:,1]

produces

ERROR: `getindex` has no method matching getindex(::StridedView{Int64,2,0,Array{Int64,2}}, ::UnitRange{Int64}, ::Int64)

Selecting by range is very common and I believe should be supported. Is there a reason why it is not?

Maybe Retag?

(v1.0) pkg> add ArrayViews
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package ArrayViews [a5c3d3bf]:
ArrayViews [a5c3d3bf] log:
├─possible versions are: [0.1.0-0.1.1, 0.2.0-0.2.5, 0.3.0, 0.4.0-0.4.12, 0.5.0, 0.6.0-0.6.4, 0.7.0] or uninstalled
├─restricted to versions * by an explicit requirement, leaving only versions [0.1.0-0.1.1, 0.2.0-0.2.5, 0.3.0, 0.4.0-0.4.12, 0.5.0, 0.6.0-0.6.4, 0.7.0]
└─restricted by julia compatibility requirements to versions: uninstalled — no versions left

However, if I use: add ArrayViews#696a741
it works

Julia v0.7 seems to be fine with no errors/warnings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.