-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
As discussed in person, an interesting idea for things to eventually add to the package is the idea of having some kind of way of maintaining a history on how hypervectors are constructed. The following snippet enables the creation of Memory structures, which have an internal structure that contains information on how a given hypervector was constructed.
I thinks this could be added as a new data structure once we finish the first pass through of the package. LMKWYT
abstract type AbstractMemory end
struct Memory{T <: AbstractHDV} <: AbstractMemory
v::T
values::Tuple{Vararg{Union{T,AbstractMemory}}}
fun::Function
end
function Memory(fun::Function, hvs::Union{AbstractHDV,AbstractMemory}...)
@assert length(unique(typeof.(hvs))) == 1
Memory{typeof(collect(first(hvs)))}(fun(hvs...), hvs, fun)
end
Memory(hv::AbstractHDV) = Memory(hv, Tuple([hdv]), identity)
Base.show(io::IO, m::Memory) = print(io, "$(typeof(m.v))($(m.fun); $(length(m.values))x$(length(m.v)))")
Base.collect(m::Memory) = m.v
bundle(hvs::Union{AbstractMemory,AbstractHDV}...) = Memory(bundle(collect.(hvs)...), hvs, bundle)
bind(hvs::Union{AbstractHDV,AbstractMemory}...) = Memory(bind(collect.(hvs)...), hvs, bind)
shift(hv::Memory, i) = Memory(shift(collect.(hvs), i), hvs, x -> shift(x, i))
endI think we can improve this a lot, but as a first prototype it gets the job done.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels