Sha256: 87133e36be294eac4daa73c2cafd76ab4cf41f6d994848fc404551977bd4c10a
Contents?: true
Size: 976 Bytes
Versions: 2
Compression:
Stored size: 976 Bytes
Contents
module SVMKit # Module for utility methods. module Utils class << self # Dump an NMatrix object converted to a Ruby Hash. # # @param mat [NMatrix] An NMatrix object converted to a Ruby Hash. # @return [Hash] A Ruby Hash containing matrix information. 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 # Return the results of converting the dumped data into an NMatrix object. # # @param dmp [Hash] A Ruby Hash about NMatrix object created with SVMKit::Utils.dump_nmatrix method. # @return [NMatrix] An NMatrix object restored from the given Hash. 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
svmkit-0.1.3 | lib/svmkit/utils.rb |
svmkit-0.1.2 | lib/svmkit/utils.rb |