Skip to content

Commit d44a239

Browse files
authored
Merge pull request #11 from FluxML/darsnack/register
2 parents 621c3aa + 71a56c6 commit d44a239

File tree

9 files changed

+139
-13
lines changed

9 files changed

+139
-13
lines changed

.buildkite/pipeline.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
steps:
2+
- label: "GPU integration with julia v1.6"
3+
plugins:
4+
- JuliaCI/julia#v1:
5+
# Drop default "registries" directory, so it is not persisted from execution to execution
6+
# Taken from https://github.com/JuliaLang/julia/blob/v1.7.2/.buildkite/pipelines/main/platforms/package_linux.yml#L11-L12
7+
persist_depot_dirs: packages,artifacts,compiled
8+
version: "1.6"
9+
- JuliaCI/julia-test#v1: ~
10+
agents:
11+
queue: "juliagpu"
12+
cuda: "*"
13+
timeout_in_minutes: 60
14+
15+
- label: "GPU integration with julia v1"
16+
plugins:
17+
- JuliaCI/julia#v1:
18+
version: "1"
19+
- JuliaCI/julia-test#v1: ~
20+
- JuliaCI/julia-coverage#v1:
21+
codecov: true
22+
agents:
23+
queue: "juliagpu"
24+
cuda: "*"
25+
env:
26+
JULIA_CUDA_USE_BINARYBUILDER: "true"
27+
timeout_in_minutes: 60
28+
29+
# - label: "GPU nightly"
30+
# plugins:
31+
# - JuliaCI/julia#v1:
32+
# version: "nightly"
33+
# - JuliaCI/julia-test#v1: ~
34+
# agents:
35+
# queue: "juliagpu"
36+
# cuda: "*"
37+
# timeout_in_minutes: 60
38+
39+
env:
40+
SECRET_CODECOV_TOKEN: "fAV/xwuaV0l5oaIYSAXRQIor8h7yHdlrpLUZFwNVnchn7rDk9UZoz0oORG9vlKLc1GK2HhaPRAy+fTkJ3GM/8Y0phHh3ANK8f5UsGm2DUTNsnf6u9izgnwnoRTcsWu+vSO0fyYrxBvBCoJwljL+yZbDFz3oE16DP7HPIzxfQagm+o/kMEszVuoUXhuLXXH0LxT6pXl214qjqs04HfMRmKIIiup48NB6fBLdhGlQz64MdMNHBfgDa/fafB7eNvn0X6pEOxysoy6bDQLUhKelOXgcDx1UsTo34Yiqr+QeJPAeKcO//PWurwQhPoUoHfLad2da9DN4uQk4YQLqAlcIuAA==;U2FsdGVkX1+mRXF2c9soCXT7DYymY3msM+vrpaifiTp8xA+gMpbQ0G63WY3tJ+6V/fJcVnxYoKZVXbjcg8fl4Q=="

.github/workflows/CI.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,29 @@ jobs:
4949
- uses: codecov/codecov-action@v2
5050
with:
5151
files: lcov.info
52+
53+
docs:
54+
name: Documentation
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v2
58+
- uses: julia-actions/setup-julia@v1
59+
with:
60+
version: '1.6'
61+
- run: |
62+
julia --project=docs -e '
63+
using Pkg
64+
Pkg.develop(PackageSpec(path=pwd()))
65+
Pkg.instantiate()'
66+
- run: |
67+
julia --project=docs/ -e '
68+
using OneHotArrays
69+
# using Pkg; Pkg.activate("docs")
70+
using Documenter
71+
using Documenter: doctest
72+
DocMeta.setdocmeta!(OneHotArrays, :DocTestSetup, :(using OneHotArrays); recursive=true)
73+
doctest(OneHotArrays)'
74+
- run: julia --project=docs docs/make.jl
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+
[compat]
5+
Documenter = "0.27"

docs/make.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Documenter, OneHotArrays
2+
3+
DocMeta.setdocmeta!(OneHotArrays, :DocTestSetup, :(using OneHotArrays); recursive = true)
4+
makedocs(sitename = "OneHotArrays", doctest = false,
5+
pages = ["Overview" => "index.md",
6+
"Reference" => "reference.md"])
7+
8+
deploydocs(repo = "github.com/FluxML/OneHotArrays.jl.git",
9+
target = "build",
10+
push_preview = true)

docs/src/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# OneHotArrays.jl
2+
3+
[![CI](https://github.com/FluxML/OneHotArrays.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/FluxML/OneHotArrays.jl/actions/workflows/CI.yml)
4+
5+
Memory efficient one-hot array encodings (primarily for use in machine-learning contexts like Flux.jl).
6+
7+
## Usage
8+
9+
One-hot arrays are boolean arrays where only a single element in the first dimension is `true` (i.e. "hot"). OneHotArrays.jl stores such arrays efficiently by encoding a N-dimensional array of booleans as a (N - 1)-dimensional array of integers. For example, the one-hot vector below only uses a single `UInt32` for storage.
10+
11+
```julia
12+
julia> β = onehot(:b, (:a, :b, :c))
13+
3-element OneHotVector(::UInt32) with eltype Bool:
14+
15+
1
16+
17+
```
18+
19+
As seen above, the one-hot encoding can be useful for representing labeled data. The label `:b` is encoded into a 3-element vector where the "hot" element indicates the label from the set `(:a, :b, :c)`.
20+
21+
We can also encode a batch of one-hot vectors or reverse the encoding.
22+
23+
```julia
24+
julia> oh = onehotbatch("abracadabra", 'a':'e', 'e')
25+
5×11 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
26+
1 1 1 1 1
27+
1 1
28+
1
29+
1
30+
1 1
31+
32+
julia> Flux.onecold(β, (:a, :b, :c))
33+
:b
34+
35+
julia> Flux.onecold([0.3, 0.2, 0.5], (:a, :b, :c))
36+
:c
37+
```
38+
39+
In addition to functions for encoding and decoding data as one-hot, this package provides numerous "fast-paths" for linear algebraic operations with one-hot arrays. For example, multiplying by a matrix by a one-hot vector triggers an indexing operation instead of a matrix multiplication.

docs/src/reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reference
2+
3+
```@autodocs
4+
Modules = [OneHotArrays]
5+
Order = [:function, :type]
6+
```

src/OneHotArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ using LinearAlgebra
77
using MLUtils
88
using NNlib
99

10-
export onehot, onehotbatch, onecold, OneHotArray,
11-
OneHotVector, OneHotMatrix, OneHotLike
10+
export onehot, onehotbatch, onecold,
11+
OneHotArray, OneHotVector, OneHotMatrix, OneHotLike
1212

1313
include("array.jl")
1414
include("onehot.jl")

src/onehot.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ and [`onecold`](@ref) to reverse either of these, as well as to generalise `argm
1212
1313
# Examples
1414
```jldoctest
15-
julia> β = Flux.onehot(:b, (:a, :b, :c))
15+
julia> β = onehot(:b, (:a, :b, :c))
1616
3-element OneHotVector(::UInt32) with eltype Bool:
1717
1818
1
1919
2020
21-
julia> αβγ = (Flux.onehot(0, 0:2), β, Flux.onehot(:z, [:a, :b, :c], :c)) # uses default
21+
julia> αβγ = (onehot(0, 0:2), β, onehot(:z, [:a, :b, :c], :c)) # uses default
2222
(Bool[1, 0, 0], Bool[0, 1, 0], Bool[0, 0, 1])
2323
2424
julia> hcat(αβγ...) # preserves sparsity
@@ -66,7 +66,7 @@ for `labels` will often speed up construction, certainly for less than 32 classe
6666
6767
# Examples
6868
```jldoctest
69-
julia> oh = Flux.onehotbatch("abracadabra", 'a':'e', 'e')
69+
julia> oh = onehotbatch("abracadabra", 'a':'e', 'e')
7070
5×11 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
7171
1 ⋅ ⋅ 1 ⋅ 1 ⋅ 1 ⋅ ⋅ 1
7272
⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ ⋅
@@ -112,17 +112,17 @@ the same operation as `argmax(y, dims=1)` but sometimes a different return type.
112112
113113
# Examples
114114
```jldoctest
115-
julia> Flux.onecold([false, true, false])
115+
julia> onecold([false, true, false])
116116
2
117117
118-
julia> Flux.onecold([0.3, 0.2, 0.5], (:a, :b, :c))
118+
julia> onecold([0.3, 0.2, 0.5], (:a, :b, :c))
119119
:c
120120
121-
julia> Flux.onecold([ 1 0 0 1 0 1 0 1 0 0 1
122-
0 1 0 0 0 0 0 0 1 0 0
123-
0 0 0 0 1 0 0 0 0 0 0
124-
0 0 0 0 0 0 1 0 0 0 0
125-
0 0 1 0 0 0 0 0 0 1 0 ], 'a':'e') |> String
121+
julia> onecold([ 1 0 0 1 0 1 0 1 0 0 1
122+
0 1 0 0 0 0 0 0 1 0 0
123+
0 0 0 0 1 0 0 0 0 0 0
124+
0 0 0 0 0 0 1 0 0 0 0
125+
0 0 1 0 0 0 0 0 0 1 0 ], 'a':'e') |> String
126126
"abeacadabea"
127127
```
128128
"""

test/gpu.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
cx = cu(x)
77
@test cx isa CuArray
88

9-
@test_broken onecold(cu([1.0, 2.0, 3.0])) == 3 # scalar indexing error?
9+
@test_skip onecold(cu([1.0, 2.0, 3.0])) == 3 # passes with CuArray with Julia 1.6, but fails with JLArray
1010

1111
x = onehotbatch([1, 2, 3], 1:3)
1212
cx = cu(x)

0 commit comments

Comments
 (0)