Sha256: c5090aa5aa220fb31d9867a61d8cc004951359bf0d942ebb3f8478998b4d0a6a

Contents?: true

Size: 806 Bytes

Versions: 11

Compression:

Stored size: 806 Bytes

Contents

module Torch
  module Utils
    module Data
      module DataPipes
        class FilterIterDataPipe < IterDataPipe
          functional_datapipe :filter

          def initialize(datapipe, &block)
            @datapipe = datapipe
            @filter_fn = block
          end

          def each
            @datapipe.each do |data|
              filtered = return_if_true(data)
              if non_empty?(filtered)
                yield filtered
              else
                Iter::StreamWrapper.close_streams(data)
              end
            end
          end

          def return_if_true(data)
            condition = @filter_fn.call(data)

            data if condition
          end

          def non_empty?(data)
            !data.nil?
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
torch-rb-0.18.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.17.1 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.17.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.16.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.15.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.14.1 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.14.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.13.2 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.13.1 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.13.0 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb
torch-rb-0.12.2 lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb