Skip to content

Commit

Permalink
Merge pull request #79 from JuliaImages/jc/restrict
Browse files Browse the repository at this point in the history
port `restrict` from Images
  • Loading branch information
johnnychen94 authored Aug 28, 2021
2 parents 4910098 + ac35f3e commit 649149a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: CompatHelper

on:
schedule:
- cron: '00 00 * * *'
- cron: 0 0 * * *
workflow_dispatch:

jobs:
CompatHelper:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.2.0]
julia-arch: [x86]
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "2"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.TAGBOT }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
35 changes: 28 additions & 7 deletions .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,48 @@ on:
branches:
- master
pull_request:
schedule:
- cron: '20 00 1 * *'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ['1.0', '1', 'nightly']
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-latest]
arch: [x64]
include:
- os: windows-latest
julia-version: '1'
arch: x64
- os: macOS-latest
julia-version: '1'
arch: x64


steps:
- uses: actions/checkout@v1.0.0
- uses: actions/checkout@v2
- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.arch }}

- name: Cache artifacts
uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- name: "Unit Test"
uses: julia-actions/julia-runtest@master

# Unless tokenless upload is enabled, we can only submit coverage via
# environment variable. But PRs from other fork can't do that.
# See issue: https://github.com/julia-actions/julia-uploadcodecov/issues/1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "ImageMetadata"
uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49"
version = "0.9.6"
version = "0.9.7"

[deps]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
ImageAxes = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"

[compat]
AxisArrays = "0.3, 0.4"
ImageAxes = "0.5, 0.6"
ImageBase = "0.1.1"
ImageCore = "0.9"
IndirectArrays = "0.5"
julia = "1"
Expand Down
7 changes: 7 additions & 0 deletions src/ImageMetadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ImageMetadata
using ImageAxes
using ImageCore
using ImageCore.OffsetArrays
using ImageBase
import AxisArrays

import Base: +, -, *, /
Expand Down Expand Up @@ -271,6 +272,12 @@ if isdefined(OffsetArrays, :centered)
OffsetArrays.centered(a::ImageMeta) = ImageMeta(OffsetArrays.centered(arraydata(a)), properties(a))
end

ImageBase.restrict(img::ImageMeta, ::Tuple{}) = img
ImageBase.restrict(img::ImageMeta, region::Dims) = shareproperties(img, restrict(arraydata(img), region))
function ImageBase.restrict(img::ImageMetaAxis, ::Type{Ax}) where Ax
shareproperties(img, restrict(arraydata(img), Ax))
end

#### Properties ####

"""
Expand Down
24 changes: 23 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ImageCore, SimpleTraits, ImageAxes, ImageMetadata, OffsetArrays
using ImageCore, SimpleTraits, ImageAxes, ImageMetadata, OffsetArrays, ImageBase
using Test
import Dates: now
using Unitful: m
Expand Down Expand Up @@ -415,4 +415,26 @@ end
end
end

@testset "restrict" begin
imgcol = rand(RGB{Float32}, 5, 6)

for dims in [(), (1, ), (1, 2)]
imgmeta = ImageMeta(imgcol, myprop=1)

out = restrict(imgmeta, dims)
@test out isa ImageMeta
@test out.myprop == 1
@test arraydata(out) == restrict(arraydata(imgmeta), dims)
end

imgcolax = AxisArray(imgcol, :y, :x)
for ax in [Axis{:x}, Axis{:y}]
imgmetaax = ImageMeta(imgcolax, myprop=1)
out = restrict(imgmetaax, ax)
@test out isa ImageMeta
@test out.myprop == 1
@test arraydata(out) == restrict(arraydata(imgmetaax), ax)
end
end

nothing

2 comments on commit 649149a

@johnnychen94
Copy link
Member Author

Choose a reason for hiding this comment

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

@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/43718

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.7 -m "<description of version>" 649149ac85e933d88667ba8ebfe434443b42c585
git push origin v0.9.7

Please sign in to comment.