Module: SVMKit::Utils
- Defined in:
- lib/svmkit/utils.rb
Overview
Module for utility methods.
Class Method Summary collapse
-
.dump_nmatrix(mat) ⇒ Hash
Dump an NMatrix object converted to a Ruby Hash.
-
.restore_nmatrix(dmp = {}) ⇒ NMatrix
Return the results of converting the dumped data into an NMatrix object.
Class Method Details
.dump_nmatrix(mat) ⇒ Hash
Dump an NMatrix object converted to a Ruby Hash.
9 10 11 12 |
# File 'lib/svmkit/utils.rb', line 9 def dump_nmatrix(mat) return nil if mat.class != NMatrix { shape: mat.shape, array: mat.to_flat_a, dtype: mat.dtype, stype: mat.stype } end |
.restore_nmatrix(dmp = {}) ⇒ NMatrix
Return the results of converting the dumped data into an NMatrix object.
18 19 20 21 |
# File 'lib/svmkit/utils.rb', line 18 def restore_nmatrix(dmp = {}) return nil unless dmp.class == Hash && %i[shape array dtype stype].all?(&dmp.method(:has_key?)) NMatrix.new(dmp[:shape], dmp[:array], dtype: dmp[:dtype], stype: dmp[:stype]) end |