Skip to content

Commit

Permalink
switch to deployed docs (#34)
Browse files Browse the repository at this point in the history
* switch to deployed docs

* finalize API
  • Loading branch information
Pietro Vertechi authored Oct 27, 2019
1 parent 0c747c0 commit 7d85f84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 156 deletions.
157 changes: 1 addition & 156 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,162 +2,7 @@

[![Build Status](https://travis-ci.org/piever/ShiftedArrays.jl.svg?branch=master)](https://travis-ci.org/piever/ShiftedArrays.jl)
[![codecov.io](http://codecov.io/github/piever/ShiftedArrays.jl/coverage.svg?branch=master)](http://codecov.io/github/piever/ShiftedArrays.jl?branch=master)
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://piever.github.io/ShiftedArrays.jl/latest/)

Implementation of shifted arrays.

## Shifted Arrays

A `ShiftedArray` is a lazy view of an Array, shifted on some or all of his indexing dimensions by some constant values.

```julia
julia> v = reshape(1:16, 4, 4)
4×4 Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16

julia> s = ShiftedArray(v, (2, 0))
4×4 ShiftedArrays.ShiftedArray{Int64,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
missing missing missing missing
missing missing missing missing
1 5 9 13
2 6 10 14
```

The parent Array as well as the amount of shifting can be recovered with `parent` and `shifts` respectively.

```julia
julia> parent(s)
4×4 Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16

julia> shifts(s)
(2, 0)
```

`shifts` returns a `Tuple`, where the n-th element corresponds to the shift on the n-th dimension of the parent `Array`.

Use `copy` to collect the shifted data into an `Array`:

```julia
julia> copy(s)
4×4 Array{Union{Int64, Missing},2}:
missing missing missing missing
missing missing missing missing
1 5 9 13
2 6 10 14
```

If you pass an integer, it will shift in the first dimension:

```julia
julia> ShiftedArray(v, 1)
4×4 ShiftedArrays.ShiftedArray{Int64,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
missing missing missing missing
1 5 9 13
2 6 10 14
3 7 11 15
```

A custom default value (other than `missing`) can be provided with the `default` keyword:

```julia
julia> ShiftedArray([1.2, 3.1, 4.5], 1, default = NaN)
3-element ShiftedArrays.ShiftedArray{Float64,Float64,1,Array{Float64,1}}:
NaN
1.2
3.1
```

### Out of bound indexes

The bound check is performed only on the parent `Array`, not on the `ShiftedArray`, so for example:

```julia
julia> ShiftedArray([1.2, 3.1, 4.5], 1, default = NaN)[-2:3]
6-element Array{Float64,1}:
NaN
NaN
NaN
NaN
1.2
3.1
```

## Shifting the data

Using the `ShiftedArray` type, this package provides two operations for lazily shifting vectors: `lag` and `lead`.

```julia
julia> v = [1, 3, 5, 4];

julia> lag(v)
4-element ShiftedArrays.ShiftedArray{Int64,1,Array{Int64,1}}:
missing
1
3
5

julia> v .- lag(v) # compute difference from previous element without unnecessary allocations
4-element Array{Any,1}:
missing
2
2
-1

julia> s = lag(v, 2) # shift by more than one element
4-element ShiftedArrays.ShiftedArray{Int64,1,Array{Int64,1}}:
missing
missing
1
3
```

`lead` is the analogous of `lag` but shifts in the opposite direction:

```julia
julia> v = [1, 3, 5, 4];

julia> lead(v)
4-element ShiftedArrays.ShiftedArray{Int64,1,Array{Int64,1}}:
3
5
4
missing
```

## Shifting the data circularly

Julia Base provides a function `circshift` to shift the data circularly. However this function
creates a copy of the vector, which may be unnecessary if the rotated vector is to be used only once.
This package provides the `CircShiftedArray` type, which is a lazy view of an array
shifted on some or all of his indexing dimensions by some constant values.

Our implementation of `circshift` relies on them to avoid copying:

```julia
julia> w = reshape(1:16, 4, 4);

julia> s = ShiftedArrays.circshift(w, (1, -1))
4×4 ShiftedArrays.CircShiftedArray{Int64,2,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
8 12 16 4
5 9 13 1
6 10 14 2
7 11 15 3
```

As usual, you can `copy` the result to have a normal `Array`:

```julia
julia> copy(s)
4×4 Array{Int64,2}:
8 12 16 4
5 9 13 1
6 10 14 2
7 11 15 3
```

1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ makedocs(
format = Documenter.HTML(),
pages = Any[
"Introduction" => "index.md",
"API" => "api.md",
]
)

Expand Down
25 changes: 25 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# API

## Array types

```@docs
ShiftedArray
ShiftedVector
CircShiftedArray
CircShiftedVector
```

## Shifting operations

```@docs
lag
lead
ShiftedArrays.circshift
```

## Accessor functions

```@docs
shifts
default
```

2 comments on commit 7d85f84

@piever
Copy link
Collaborator

@piever piever commented on 7d85f84 Oct 27, 2019

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

Release notes:

Breaking changes

  • Removed special reduce, reduce_vec, mapreduce, mapreduce_vec methods
  • Removed to_array, to_offsetarray methods
  • Removed OffsetArrays, RecursiveArrayTools dependencies

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/4781

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" 7d85f84eee179b612350a3a8280b8fbd1c0369d3
git push origin v1.0.0

Please sign in to comment.