src/Util.jl

Tue, 07 Dec 2021 11:41:07 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 07 Dec 2021 11:41:07 +0200
changeset 34
22a64e826ee7
parent 33
a60d2f12ef93
permissions
-rw-r--r--

New logger and iteration interface

#########################
# Some utility functions
#########################

__precompile__()

module Util

##############
# Our exports
##############

export map_first_slice!,
       reduce_first_slice,
       ⬿

###############################
# For working with NamedTuples
###############################

⬿ = merge

######
# map
######

@inline function map_first_slice!(f!, y)
    for i in CartesianIndices(size(y)[2:end])
        @inbounds f!(@view(y[:, i]))
    end
end

@inline function map_first_slice!(x, f!, y)
    for i in CartesianIndices(size(y)[2:end])
        @inbounds f!(@view(x[:, i]), @view(y[:, i]))
    end
end

@inline function reduce_first_slice(f, y; init=0.0)
    accum=init
    for i in CartesianIndices(size(y)[2:end])
        @inbounds accum=f(accum, @view(y[:, i]))
    end
    return accum
end

end # Module

mercurial