diff --git a/src/assemble.jl b/src/assemble.jl index 9d259c3..6e626f9 100644 --- a/src/assemble.jl +++ b/src/assemble.jl @@ -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. """