Skip to content

Commit

Permalink
add copy of assemble routine in anticipation of merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcwitt committed Sep 22, 2023
1 parent 44bb956 commit c4c1aa0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/assemble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ function assemble(data::AbstractVector{<:AbstractData}, basis; do_gc = true)
return Array(A), Array(Y), assemble_weights(data)
end

"""
Assemble feature matrix and target vector for given data and basis.
"""
function assemble(data::AbstractVector{<:AbstractData}, basis; do_gc = true)
@info "Assembling linear problem."
rows = Array{UnitRange}(undef, length(data)) # row ranges for each element of data
rows[1] = 1:count_observations(data[1])
for i in 2:length(data)
rows[i] = rows[i - 1][end] .+ (1:count_observations(data[i]))
end
packets = DataPacket.(rows, data)
sort!(packets, by = length, rev = true)
(nprocs() > 1) && sendto(workers(), basis = basis)
@info " - Creating feature matrix with size ($(rows[end][end]), $(length(basis)))."
A = SharedArray(zeros(rows[end][end], length(basis)))
Y = SharedArray(zeros(size(A, 1)))
@info " - Beginning assembly with processor count: $(nprocs())."
@showprogress pmap(packets) do p
A[p.rows, :] .= feature_matrix(p.data, basis)
Y[p.rows] .= target_vector(p.data)
do_gc && GC.gc()
end
@info " - Assembly completed."
return Array(A), Array(Y), assemble_weights(data)
end

"""
Assemble full weight vector for vector of data elements.
"""
Expand Down

0 comments on commit c4c1aa0

Please sign in to comment.