Skip to content

Commit

Permalink
Add support for table types.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn committed May 27, 2022
1 parent c1dc3c2 commit 90d3104
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ShowCases = "605ecd9f-84a6-4c9e-81e2-4798472b76a3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
ChainRulesCore = "1.0"
Expand Down
1 change: 1 addition & 0 deletions src/MLUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ChainRulesCore: rrule
using ChainRulesCore: @non_differentiable, unthunk, AbstractZero,
NoTangent, ZeroTangent, ProjectTo

using Tables: istable, rows

include("observation.jl")
export numobs,
Expand Down
8 changes: 4 additions & 4 deletions src/observation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See also [`getobs`](@ref)
function numobs end

# Generic Fallbacks
numobs(data) = length(data)
numobs(data) = istable(data) ? length(rows(data)) : length(data)

"""
getobs(data, [idx])
Expand All @@ -40,13 +40,13 @@ Every author behind some custom data container can make this
decision themselves.
The output should be consistent when `idx` is a scalar vs vector.
See also [`getobs!`](@ref) and [`numobs`](@ref)
See also [`getobs!`](@ref) and [`numobs`](@ref)
"""
function getobs end

# Generic Fallbacks
getobs(data) = data
getobs(data, idx) = data[idx]
getobs(data, idx) = istable(data) ? collect(rows(data))[idx] : data[idx]

"""
getobs!(buffer, data, idx)
Expand Down Expand Up @@ -82,7 +82,7 @@ Base.lastindex(x::AbstractDataContainer) = numobs(x)
# --------------------------------------------------------------------
# Arrays
# We are very opinionated with arrays: the observation dimension
# is th last dimension. For different behavior wrap the array in
# is th last dimension. For different behavior wrap the array in
# a custom type, e.g. with Tables.table.


Expand Down

0 comments on commit 90d3104

Please sign in to comment.