Skip to content

Commit 056aae9

Browse files
authored
Fix misleading phrasing in error message (#21)
* Fix misleading phrasing in error message * Update CI workflow * Use stable RNG in tests
1 parent 92e3d32 commit 056aae9

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
version:
22-
- '1.6'
22+
- 'lts'
2323
- '1'
24-
- 'nightly'
24+
- 'pre'
2525
os:
2626
- ubuntu-latest
2727
arch:
2828
- x64
2929
steps:
30-
- uses: actions/checkout@v3
31-
- uses: julia-actions/setup-julia@v1
30+
- uses: actions/checkout@v4
31+
- uses: julia-actions/setup-julia@v2
3232
with:
3333
version: ${{ matrix.version }}
3434
arch: ${{ matrix.arch }}
@@ -38,7 +38,7 @@ jobs:
3838
- uses: julia-actions/julia-runtest@v1
3939
continue-on-error: ${{ matrix.version == 'nightly' }}
4040
- uses: julia-actions/julia-processcoverage@v1
41-
- uses: codecov/codecov-action@v3
41+
- uses: codecov/codecov-action@v5
4242
with:
4343
files: lcov.info
4444

@@ -47,7 +47,7 @@ jobs:
4747
runs-on: ubuntu-latest
4848
steps:
4949
- uses: actions/checkout@v4
50-
- uses: julia-actions/setup-julia@v1
50+
- uses: julia-actions/setup-julia@v2
5151
with:
5252
version: '1'
5353
- run: |

src/output_selection.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const BATCHDIM_MISSING = ArgumentError(
2-
"The input is a 1D vector and therefore missing the required batch dimension."
1+
const BATCHDIM_MISSING_OUTPUT = ArgumentError(
2+
"The output is a 1D vector and therefore missing the required batch dimension."
33
)
44

55
const NOTE_OUTPUT_SELECTOR = "## Note
@@ -44,7 +44,7 @@ julia> output_selector(output)
4444
"""
4545
struct MaxActivationSelector <: AbstractOutputSelector end
4646
function (::MaxActivationSelector)(out::AbstractArray{T,N}) where {T,N}
47-
N < 2 && throw(BATCHDIM_MISSING)
47+
N < 2 && throw(BATCHDIM_MISSING_OUTPUT)
4848
return vec(argmax(out; dims=1:(N - 1)))
4949
end
5050

@@ -77,12 +77,12 @@ struct IndexSelector{I} <: AbstractOutputSelector
7777
index::I
7878
end
7979
function (s::IndexSelector{<:Integer})(out::AbstractArray{T,N}) where {T,N}
80-
N < 2 && throw(BATCHDIM_MISSING)
80+
N < 2 && throw(BATCHDIM_MISSING_OUTPUT)
8181
batchsize = size(out, N)
8282
return [CartesianIndex{N}(s.index, b) for b in 1:batchsize]
8383
end
8484
function (s::IndexSelector{I})(out::AbstractArray{T,N}) where {I,T,N}
85-
N < 2 && throw(BATCHDIM_MISSING)
85+
N < 2 && throw(BATCHDIM_MISSING_OUTPUT)
8686
batchsize = size(out, N)
8787
return [CartesianIndex{N}(s.index..., b) for b in 1:batchsize]
8888
end

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
44
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
55
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
66
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
7+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
78
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/test_output_selection.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using Test
33

44
using XAIBase: MaxActivationSelector, IndexSelector
55
using Test
6+
using StableRNGs: StableRNG
67
using Random
78

89
ns_max = @inferred MaxActivationSelector()
@@ -53,16 +54,16 @@ I_idx = @inferred ns_idx(A)
5354

5455
# 4x3x2 input with Tuple IndexSelector
5556
ns_idx = @inferred IndexSelector((4, 2))
56-
A = rand(MersenneTwister(1234), Float32, 4, 3, 2)
57+
A = rand(StableRNG(1234), Float32, 4, 3, 2)
5758
R = similar(A)
5859

5960
I_max = @inferred ns_max(A)
6061
I_idx = @inferred ns_idx(A)
6162
@test I_max isa Vector{CartesianIndex{3}}
6263
@test I_idx isa Vector{CartesianIndex{3}}
6364
@test I_max == [
64-
CartesianIndex(2, 1, 1)
65-
CartesianIndex(4, 1, 2)
65+
CartesianIndex(2, 3, 1)
66+
CartesianIndex(4, 3, 2)
6667
]
6768
@test I_idx == [
6869
CartesianIndex(4, 2, 1)

0 commit comments

Comments
 (0)