Sha256: d045f480eabf1e79a541047f5c209a355522acd09d28d3812758a3de093dc6a5
Contents?: true
Size: 1.46 KB
Versions: 3
Compression:
Stored size: 1.46 KB
Contents
module TensorStream # module that contains helper functions useful for ops module OpHelper def op(code, t_a, t_b = nil, options = {}) Operation.new(code.to_sym, t_a, t_b, options) end # same as op but with a marker that it was internal generated def i_op(code, t_a, t_b = nil, options = {}) Operation.new(code.to_sym, t_a, t_b, options.merge(internal: true)) end def cons(value, options = {}) TensorStream.constant(value, options) end def i_cons(value, options = {}) TensorStream.constant(value, options.merge(internal: true)) end def shape_eval(input, output_type = :int32) return [] unless input.is_a?(Array) arr = [] arr_ptr = input Kernel.loop do arr << (TensorStream::Ops::FLOATING_POINT_TYPES.include?(output_type) ? arr_ptr.size.to_f : arr_ptr.size) arr_ptr = arr_ptr[0] break unless arr_ptr.is_a?(Array) end arr end def dtype_eval(rank, value) dtype = Tensor.detect_type(value[0]) rank += 1 if dtype == :array [dtype, rank, value[0], value.size] end def val_to_dtype(value) if value.is_a?(String) :string elsif value.is_a?(Float) :float32 elsif value.is_a?(Integer) :int32 elsif value.is_a?(Array) :array else :float32 end end def fp_type?(type) TensorStream::Ops::FLOATING_POINT_TYPES.include?(type) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tensor_stream-0.1.4 | lib/tensor_stream/helpers/op_helper.rb |
tensor_stream-0.1.3 | lib/tensor_stream/helpers/op_helper.rb |
tensor_stream-0.1.2 | lib/tensor_stream/helpers/op_helper.rb |