lib/libmf/model.rb in libmf-0.1.1 vs lib/libmf/model.rb in libmf-0.1.2
- old
+ new
@@ -50,15 +50,15 @@
def bias
model[:b]
end
def p_factors
- reshape(model[:p].read_array_of_float(factors * rows), [rows, factors])
+ reshape(model[:p].read_array_of_float(factors * rows), factors)
end
def q_factors
- reshape(model[:q].read_array_of_float(factors * columns), [columns, factors])
+ reshape(model[:q].read_array_of_float(factors * columns), factors)
end
private
def model
@@ -98,15 +98,10 @@
prob[:nnz] = nodes.size
prob[:r] = r
prob
end
- def reshape(arr, dims)
- rows = dims.first
- new_arr = rows.times.map { [] }
- arr.each_with_index do |v, i|
- new_arr[i % rows] << v
- end
- new_arr
+ def reshape(arr, factors)
+ arr.each_slice(factors).to_a
end
end
end