source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
grosser/i18n_data
https://github.com/grosser/i18n_data
lib/i18n_data.rb
Ruby
mit
226
master
2,660
# frozen_string_literal: true require 'i18n_data/version' module I18nData class BaseException < StandardError def to_s "#{self.class} -- #{super}" end end class NoTranslationAvailable < BaseException; end class AccessDenied < BaseException; end class Unknown < BaseException; end class << se...
github
grosser/i18n_data
https://github.com/grosser/i18n_data
lib/i18n_data/file_data_provider.rb
Ruby
mit
226
master
1,703
# frozen_string_literal: true module I18nData module FileDataProvider require 'fileutils' DATA_SEPARATOR = ";;" extend self def codes(type, language_code) unless (data = read_from_file(cache_file_for(type, language_code))) raise NoTranslationAvailable, "#{type}-#{language_code}" ...
github
grosser/i18n_data
https://github.com/grosser/i18n_data
lib/i18n_data/live_data_provider.rb
Ruby
mit
226
master
4,904
# frozen_string_literal: true require 'json' require 'simple_po_parser' module I18nData # fetches data online from debian git module LiveDataProvider extend self JSON_CODES = { countries: 'data/iso_3166-1.json', languages: 'data/iso_639-2.json' }.freeze TRANSLATIONS = { countrie...
github
grosser/i18n_data
https://github.com/grosser/i18n_data
spec/i18n_data_spec.rb
Ruby
mit
226
master
6,901
# frozen_string_literal: true require "spec_helper" NUM_2_LETTER_LANGUAGES = 184 NUM_COUNTRIES = 249 describe I18nData do require "i18n_data/live_data_provider" require "i18n_data/file_data_provider" def blank_keys_or_values(hash) hash.detect { |k, v| k.to_s.empty? or v.to_s.empty? } end around do |t|...
github
grosser/i18n_data
https://github.com/grosser/i18n_data
spec/benchmark.rb
Ruby
mit
226
master
723
# frozen_string_literal: true # Benchmark performance by looking up every available language's country and # language translations multiple times. require 'benchmark' require 'i18n_data' types = [:countries, :languages] type_codes = {} types.each do |type| type_codes[type] = [] Dir.glob("./cache/file_data_provid...
github
grosser/i18n_data
https://github.com/grosser/i18n_data
spec/i18n_data/live_data_provider_spec.rb
Ruby
mit
226
master
210
# frozen_string_literal: true require "spec_helper" require "i18n_data/live_data_provider" # fetching is tested via spec/i18n_data_spec.rb, these are just unit-tests describe I18nData::LiveDataProvider do end
github
grosser/i18n_data
https://github.com/grosser/i18n_data
spec/i18n_data/file_data_provider_spec.rb
Ruby
mit
226
master
1,432
# frozen_string_literal: true require "spec_helper" require 'i18n_data/file_data_provider' describe I18nData::FileDataProvider do let(:cache_file) { I18nData::FileDataProvider.send(:cache_file_for, "XX", "YY") } around do |test| `rm -f #{cache_file}` test.call `rm -f #{cache_file}` end def read(x...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
Gemfile
Ruby
mit
226
master
956
source 'https://rubygems.org' gemspec gem 'sourcify', '0.6.0.rc4' gem 'method_source' gem 'commander' gem 'pry' gem 'nio4r' gem 'distribution' platform :mri do gem 'rjb' gem 'msgpack' gem 'oj' gem 'narray' end platform :jruby do gem 'msgpack-jruby', require: 'msgpack' # NameError: no constructorfor arg...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
Rakefile
Ruby
mit
226
master
623
#-*- mode: ruby -*- require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new task default: :spec task test: :spec def java? RUBY_PLATFORM =~ /java/ end if java? require "rake/javaextensiontask" Rake::JavaExtensionTask.new("ruby_java") do |ext| ext.name = "ruby_spark_ext" ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
ruby-spark.gemspec
Ruby
mit
226
master
1,331
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'spark/version' Gem::Specification.new do |spec| spec.name = 'ruby-spark' spec.version = Spark::VERSION spec.authors = ['Ondřej Moravčík'] spec.email = ['mor...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
example/pi.rb
Ruby
mit
226
master
482
#!/usr/bin/env ruby lib = File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'ruby-spark' Spark.logger.disable Spark.start slices = 3 n = 100000 * slices def map(_) x = rand * 2 - 1 y = rand * 2 - 1 if x**2 + y**2 < 1 ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
example/website_search.rb
Ruby
mit
226
master
1,655
#!/usr/bin/env ruby # Parse sitemap and search word on every page require 'optparse' require 'open-uri' require 'nokogiri' require 'ruby-spark' options = { sitemap: 'http://fit.cvut.cz/sitemap.xml', query: 'cvut', workers: 2 } opt_parser = OptionParser.new do |opts| opts.banner = 'Usage: website_search.rb [...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/digest.rb
Ruby
mit
226
master
3,210
lib = File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) def java? RUBY_PLATFORM =~ /java/ end unless java? require 'murmurhash3' end require 'digest' require 'benchmark' require 'ruby-spark' TEST = 5_000_000 WORDS = ["wefwefwef", "r...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/serializer.rb
Ruby
mit
226
master
1,978
require "benchmark" require "yaml" require "msgpack" require "oj" # require "thrift" puts "Simple" data = (0..100000).to_a Benchmark.bmbm do |x| x.report("YAML") do serialized = YAML.dump(data) deserialized = YAML.load(serialized) puts "Size: #{serialized.size}, Equal: #{deserialized == data}" end ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/sort.rb
Ruby
mit
226
master
1,356
require "benchmark" array = [] 1000.times { array << {:bar => rand(1000)} } n = 500 Benchmark.bm(20) do |x| x.report("sort") { n.times { array.sort{ |a,b| b[:bar] <=> a[:bar] } } } x.report("sort reverse") { n.times { array.sort{ |a,b| a[:bar] <=> b[:bar] }.reverse } } x.report("sort_by ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/bisect.rb
Ruby
mit
226
master
1,541
require "benchmark" def bisect_left1(a, x, opts={}) return nil if a.nil? return 0 if a.empty? lo = (opts[:lo] || opts[:low]).to_i hi = opts[:hi] || opts[:high] || a.length while lo < hi mid = (lo + hi) / 2 v = a[mid] if v < x lo = mid + 1 else hi = mid end end return lo ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/enumerator.rb
Ruby
mit
226
master
1,424
require "benchmark" class Enumerator def defer(&blk) self.class.new do |y| each do |*input| blk.call(y, *input) end end end end ARRAY_SIZE = 50_000_000 def type_yield return to_enum(__callee__) unless block_given? ARRAY_SIZE.times { |i| yield i } end def yield_map_x2(enum)...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/custom_marshal.rb
Ruby
mit
226
master
1,519
require 'benchmark' require 'benchmark/ips' def pack_int(data) [data].pack('l>') end def pack_long(data) [data].pack('q>') end def pack_doubles(data) data.pack('G*') end module Standard class LabeledPoint def initialize(label, features) @label = label @features = Standard::Vector.new(feature...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/aggregate.rb
Ruby
mit
226
master
550
require 'benchmark' require 'benchmark/ips' data = 0..1_000_000 zero_value = rand(100_000) function = Proc.new{|sum, n| sum+n} Benchmark.ips do |r| r.report('each') do sum = zero_value data.each do |n| sum += n end end r.report('reduce') do data.reduce(zero_value){|sum, n| sum+n} end ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/take.rb
Ruby
mit
226
master
445
require "benchmark" SIZE = 100_000_000 @array1 = (0..SIZE).to_a; @array2 = (0..SIZE).to_a; @array3 = (0..SIZE).to_a; TAKE = 100_000 Benchmark.bm(15) do |x| # Fastest x.report("take"){ a=@array1.take(TAKE) } # Slowest and take most memory x.report("reverse drop"){ @array2.reverse! @array2.drop...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/sort2.rb
Ruby
mit
226
master
3,591
require "benchmark" require "algorithms" NUMBER_OF_SORTING = 1 NUMBER_OF_ARRAY = 10 WORDS_IN_ARRAY = 100000 MAX_WORD_SIZE = 10 EVAL_N_VALUES = 10 puts "NUMBER_OF_SORTING: #{NUMBER_OF_SORTING}" puts "NUMBER_OF_ARRAY: #{NUMBER_OF_ARRAY}" puts "WORDS_IN_ARRAY: #{WORDS_IN_ARRAY}" puts "MAX_WORD_SIZE: #{MAX_W...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
benchmark/comparison/ruby.rb
Ruby
mit
226
master
3,150
#!/usr/bin/env ruby lib = File.expand_path(File.dirname(__FILE__) + '/../../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'ruby-spark' require 'benchmark' Spark.start sc = Spark.context $log_file = File.open(ENV['RUBY_LOG'], 'w') def log(*values) $log_file.puts(values...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark.rb
Ruby
mit
226
master
6,566
# Gems and libraries require 'method_source' require 'securerandom' require 'forwardable' require 'sourcify' require 'socket' require 'tempfile' require 'tmpdir' require 'json' module Spark autoload :Context, 'spark/context' autoload :Config, 'spark/config' autoload :RDD, 'spark/rdd' ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/storage_level.rb
Ruby
mit
226
master
1,237
# Necessary libraries Spark.load_lib module Spark class StorageLevel def self.reload return if @reloaded reload! @reloaded = true end def self.reload! self.const_set(:NONE, JStorageLevel.NONE) self.const_set(:DISK_ONLY, JStorageLevel.DISK_ONLY)...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/java_bridge.rb
Ruby
mit
226
master
355
module Spark module JavaBridge autoload :Base, 'spark/java_bridge/base' autoload :JRuby, 'spark/java_bridge/jruby' autoload :RJB, 'spark/java_bridge/rjb' include Spark::Helper::System def self.init(*args) if jruby? klass = JRuby else klass = RJB end k...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper.rb
Ruby
mit
226
master
330
module Spark module Helper autoload :System, "spark/helper/system" autoload :Logger, "spark/helper/logger" autoload :Statistic, "spark/helper/statistic" autoload :Serialize, "spark/helper/serialize" autoload :Partition, "spark/helper/partition" autoload :Parser, "spark/helper/parser" ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/library.rb
Ruby
mit
226
master
450
module Spark module Library def autoload(klass, location, import=true) if import @for_importing ||= [] @for_importing << klass end super(klass, location) end def autoload_without_import(klass, location) autoload(klass, location, false) end def import(to=...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sampler.rb
Ruby
mit
226
master
1,761
require 'distribution' # Random Generators module Spark module RandomGenerator class Poisson def initialize(mean, seed) generator = Random.new(seed) @exp_rng = Distribution::Exponential.rng(1.0/mean, random: generator) end def rand t = 0.0 number = 0 l...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/rdd.rb
Ruby
mit
226
master
42,715
module Spark ## # A Resilient Distributed Dataset (RDD), the basic abstraction in Spark. Represents an immutable, # partitioned collection of elements that can be operated on in parallel. This class contains the # basic operations available on all RDDs, such as `map`, `filter`, and `persist`. # class RDD ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/accumulator.rb
Ruby
mit
226
master
6,087
module Spark ## # A shared variable that can be accumulated, i.e., has a commutative and associative "add" # operation. Worker tasks on a Spark cluster can add values to an Accumulator with the `+=` # operator, but only the driver program is allowed to access its value, using value. # Updates from the workers...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib.rb
Ruby
mit
226
master
3,302
module Spark # MLlib is Spark’s scalable machine learning library consisting of common learning algorithms and utilities, # including classification, regression, clustering, collaborative filtering, dimensionality reduction, # as well as underlying optimization primitives. module Mllib extend Spark::Library...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command_builder.rb
Ruby
mit
226
master
3,742
require 'spark/command_validator' module Spark ## # Builder for building correct {Spark::Command} # class CommandBuilder extend Forwardable include Spark::Helper::Serialize include Spark::Helper::System include Spark::CommandValidator attr_reader :command def_delegators :@command, :...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sort.rb
Ruby
mit
226
master
4,802
module Spark module InternalSorter class Base def initialize(key_function) @key_function = key_function end end class Ascending < Base def sort(data) data.sort_by!(&@key_function) end end class Descending < Ascending def sort(data) super ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/broadcast.rb
Ruby
mit
226
master
2,505
module Spark ## # Broadcast a read-only variable to the cluster, returning a Spark::Broadcast # object for reading it in distributed functions. The variable will # be sent to each cluster only once. # # == Example: # # broadcast1 = $sc.broadcast('a') # broadcast2 = $sc.broadcast('b') # broadca...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/config.rb
Ruby
mit
226
master
5,537
# Necessary libraries Spark.load_lib module Spark # Common configuration for RubySpark and Spark class Config include Spark::Helper::System TYPES = { 'spark.shuffle.spill' => :boolean, 'spark.ruby.serializer.compress' => :boolean } # Initialize java SparkConf and load default configu...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command.rb
Ruby
mit
226
master
2,147
module Spark ## # Container which includes all commands and other things for worker # Every RDD have own copy of Command # class Command attr_accessor :serializer, :deserializer, :commands, :libraries, :bound_objects def initialize @serializer = nil @deserializer = nil @commands = ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/stat_counter.rb
Ruby
mit
226
master
2,853
module Spark class StatCounter attr_reader :n # count of our values attr_reader :mu # mean of our values attr_reader :m2 # variance numerator (sum of (x - mean)^2) attr_reader :max # max of our values attr_reader :min # min of our values def initialize(iterator) @n = 0 @mu = ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/logger.rb
Ruby
mit
226
master
1,268
# Necessary libraries Spark.load_lib module Spark class Logger attr_reader :jlogger def initialize @jlogger = JLogger.getLogger('Ruby') end def level_off JLevel.toLevel('OFF') end # Disable all Spark log def disable jlogger.setLevel(level_off) JLogger.getLogger...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/error.rb
Ruby
mit
226
master
1,000
module Spark # Extension cannot be built class BuildError < StandardError end # Proc.to_source # Java object cannot be converted class SerializeError < StandardError end # Serializer method # Non-existing serializer class NotImplemented < StandardError end # Missison app_name or master clas...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/cli.rb
Ruby
mit
226
master
5,488
require 'commander' module Commander module UI # Disable paging # for 'classic' help def self.enable_paging end end end module Spark class CLI include Commander::Methods # IRB_HISTORY_FILE = File.join(Dir.home, '.irb_spark_history') # IRB_HISTORY_SIZE = 100 def run progra...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command_validator.rb
Ruby
mit
226
master
707
module Spark module CommandValidator def validate(value, options) validate_type(value, options[:type]) end def valid?(value, options) begin validate(value, options) return true rescue return false end end def validate_type(value, types) type...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer.rb
Ruby
mit
226
master
1,773
module Spark ## # Serializer # module Serializer DEFAULT_COMPRESS = false DEFAULT_BATCH_SIZE = 1024 DEFAULT_SERIALIZER_NAME = 'marshal' @@registered = {} # Register class and create method for quick access. # Class will be available also as __name__ for using # in build method (Pr...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/build.rb
Ruby
mit
226
master
1,339
module Spark module Build DEFAULT_SCALA_VERSION = '2.10.4' DEFAULT_CORE_VERSION = '2.10' DEFAULT_SPARK_VERSION = '1.6.0' DEFAULT_HADOOP_VERSION = '1.0.4' SBT = 'sbt/sbt' SBT_DEPS = 'assemblyPackageDependency' SBT_EXT = 'package' SBT_CLEAN = 'clean' def self.build(op...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql.rb
Ruby
mit
226
master
821
module Spark module SQL extend Spark::Library autoload_without_import :Context, 'spark/sql/context' autoload_without_import :DataType, 'spark/sql/data_type' autoload_without_import :DataFrame, 'spark/sql/data_frame' autoload_without_import :DataFrameReader, 'spark/sql/data_fr...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/constant.rb
Ruby
mit
226
master
293
module Spark # Commond constant for Ruby and Spark module Constant DATA_EOF = -2 WORKER_ERROR = -1 WORKER_DONE = 0 CREATE_WORKER = 1 KILL_WORKER = 2 KILL_WORKER_AND_WAIT = 3 SUCCESSFULLY_KILLED = 4 UNSUCCESSFUL_KILLING = 5 ACCUMULATOR_ACK = 6 end end
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/context.rb
Ruby
mit
226
master
10,104
# Necessary libraries Spark.load_lib module Spark ## # Main entry point for Spark functionality. A SparkContext represents the connection to a Spark # cluster, and can be used to create RDDs, accumulators and broadcast variables on that cluster. # class Context include Spark::Helper::System include ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/batched.rb
Ruby
mit
226
master
1,651
module Spark module Serializer class Batched < Base attr_writer :serializer def initialize(serializer, batch_size=nil) batch_size ||= Spark::Serializer::DEFAULT_BATCH_SIZE @serializer = serializer @batch_size = batch_size.to_i error('Batch size must be greater than ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/compressed.rb
Ruby
mit
226
master
503
module Spark module Serializer class Compressed < Base def initialize(serializer) @serializer = serializer end def dump(data) Zlib::Deflate.deflate(@serializer.dump(data)) end def load(data) @serializer.load(Zlib::Inflate.inflate(data)) end end ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/text.rb
Ruby
mit
226
master
483
module Spark module Serializer class Text < Base attr_reader :encoding def initialize(encoding=Encoding::UTF_8) error('Encoding must be an instance of Encoding') unless encoding.is_a?(Encoding) @encoding = encoding end def load(data) data.to_s.force_encoding(@en...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/pair.rb
Ruby
mit
226
master
928
module Spark module Serializer class Pair < Base def initialize(serializer1, serializer2) @serializer1 = serializer1 @serializer2 = serializer2 end def to_s "#{name}(#{@serializer1}, #{@serializer2})" end def aggregate(item1, item2) item1.zip(item2)...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/message_pack.rb
Ruby
mit
226
master
417
module Spark module Serializer class MessagePack < Base def dump(data) ::MessagePack.dump(data) end def load(data) ::MessagePack.load(data) end end end end begin # TODO: require only if it is necessary require 'msgpack' Spark::Serializer.register('messagepa...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/cartesian.rb
Ruby
mit
226
master
224
module Spark module Serializer class Cartesian < Pair def aggregate(item1, item2) item1.product(item2) end end end end Spark::Serializer.register('cartesian', Spark::Serializer::Cartesian)
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/oj.rb
Ruby
mit
226
master
328
module Spark module Serializer class Oj < Base def dump(data) ::Oj.dump(data) end def load(data) ::Oj.load(data) end end end end begin # TODO: require only if it is necessary require 'oj' Spark::Serializer.register('oj', Spark::Serializer::Oj) rescue LoadEr...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/auto_batched.rb
Ruby
mit
226
master
1,314
module Spark module Serializer ## # AutoBatched serializator # # Batch size is computed automatically. Simillar to Python's AutoBatchedSerializer. # class AutoBatched < Batched MAX_RATIO = 10 def initialize(serializer, best_size=65536) @serializer = serializer @be...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/marshal.rb
Ruby
mit
226
master
266
module Spark module Serializer class Marshal < Base def dump(data) ::Marshal.dump(data) end def load(data) ::Marshal.load(data) end end end end Spark::Serializer.register('marshal', Spark::Serializer::Marshal)
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/serializer/base.rb
Ruby
mit
226
master
1,144
module Spark module Serializer # @abstract Parent for all serializers class Base def load_from_io(io) return to_enum(__callee__, io) unless block_given? loop do size = io.read_int_or_eof break if size == Spark::Constant::DATA_EOF yield load(io.read(size))...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/matrix.rb
Ruby
mit
226
master
2,422
module Spark module Mllib module Matrices def self.dense(*args) DenseMatrix.new(*args) end def self.sparse(*args) SparseMatrix.new(*args) end def self.to_matrix(data) if data.is_a?(SparseMatrix) || data.is_a?(DenseMatrix) data elsif data.i...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/vector.rb
Ruby
mit
226
master
4,035
module Spark module Mllib module Vectors def self.dense(*args) DenseVector.new(*args) end def self.sparse(*args) SparseVector.new(*args) end def self.parse(data) if data.start_with?('[') && data.end_with?(']') DenseVector.parse(data) elsif...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/stat/distribution.rb
Ruby
mit
226
master
460
## # MultivariateGaussian # # This class provides basic functionality for a Multivariate Gaussian (Normal) Distribution. In # the event that the covariance matrix is singular, the density will be computed in a # reduced dimensional subspace under which the distribution is supported. # # == Arguments: # mu:: The mean ve...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/regression/labeled_point.rb
Ruby
mit
226
master
767
module Spark module Mllib ## # LabeledPoint # # The features and labels of a data point. # # == Parameters: # label:: # Label for this data point. # # features:: # Vector of features for this point # class LabeledPoint attr_reader :label, :features ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/regression/linear.rb
Ruby
mit
226
master
4,268
## # LinearRegressionModel # # Train a linear regression model with no regularization using Stochastic Gradient Descent. # This solves the least squares regression formulation # f(weights) = 1/n ||A weights-y||^2^ # (which is the mean squared error). # Here the data matrix has n rows, and the input RDD holds the set ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/regression/lasso.rb
Ruby
mit
226
master
3,706
## # LassoModel # # Train a regression model with L1-regularization using Stochastic Gradient Descent. # This solves the l1-regularized least squares regression formulation # f(weights) = 1/2n ||A weights-y||^2^ + regParam ||weights||_1 # Here the data matrix has n rows, and the input RDD holds the set of rows of A,...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/regression/common.rb
Ruby
mit
226
master
1,769
module Spark module Mllib ## # RegressionModel # # A linear model that has a vector of coefficients and an intercept. # class RegressionModel attr_reader :weights, :intercept def initialize(weights, intercept) @weights = Spark::Mllib::Vectors.to_vector(weights) @i...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/regression/ridge.rb
Ruby
mit
226
master
3,716
## # RidgeRegressionModel # # Train a regression model with L2-regularization using Stochastic Gradient Descent. # This solves the l1-regularized least squares regression formulation # f(weights) = 1/2n ||A weights-y||^2^ + regParam/2 ||weights||^2^ # Here the data matrix has n rows, and the input RDD holds the set ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/clustering/gaussian_mixture.rb
Ruby
mit
226
master
2,205
module Spark module Mllib ## # GaussianMixtureModel # # A clustering model derived from the Gaussian Mixture Model method. # # == Examples: # # Spark::Mllib.import # # data = [ # DenseVector.new([-0.1, -0.05]), # DenseVector.new([-0.01, -0.1]), # Den...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/clustering/kmeans.rb
Ruby
mit
226
master
3,394
module Spark module Mllib ## # KMeansModel # # A clustering model derived from the k-means method. # # == Examples: # # Spark::Mllib.import # # # Dense vectors # data = [ # DenseVector.new([0.0,0.0]), # DenseVector.new([1.0,1.0]), # DenseVector...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/ruby_matrix/matrix_adapter.rb
Ruby
mit
226
master
1,139
require 'matrix' module Spark module Mllib class MatrixAdapter < ::Matrix def self.new(*args) object = self.allocate if args.size == 2 # Matrix is initialized from Matrix # Arguments: rows, column count object.__send__(:original_initialize, *args) els...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/ruby_matrix/vector_adapter.rb
Ruby
mit
226
master
1,027
require 'matrix' # Based on ruby 2.1 class Vector def self.elements(array, copy=true) DenseVector.new(convert_to_array(array, copy)) end end module Spark module Mllib class VectorAdapter < ::Vector def self.new(*args) object = self.allocate object.__send__(:initialize, *args) ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/classification/common.rb
Ruby
mit
226
master
541
module Spark module Mllib class ClassificationModel attr_reader :weights, :intercept, :threshold def initialize(weights, intercept) @weights = Spark::Mllib::Vectors.to_vector(weights) @intercept = intercept.to_f @threshold = nil end def threshold=(value) ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/classification/naive_bayes.rb
Ruby
mit
226
master
2,777
module Spark module Mllib ## # NaiveBayesModel # # Model for Naive Bayes classifiers. # # Contains two parameters: # pi:: vector of logs of class priors (dimension C) # theta:: matrix of logs of class conditional probabilities (CxD) # # == Examples: # # Spark::Mllib.i...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/classification/svm.rb
Ruby
mit
226
master
4,150
module Spark module Mllib ## # SVMModel # # A support vector machine. # # == Examples: # # Spark::Mllib.import # # # Dense vectors # data = [ # LabeledPoint.new(0.0, [0.0]), # LabeledPoint.new(1.0, [1.0]), # LabeledPoint.new(1.0, [2.0]), ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/mllib/classification/logistic_regression.rb
Ruby
mit
226
master
6,916
module Spark module Mllib ## # LogisticRegressionModel # # A linear binary classification model derived from logistic regression. # # == Examples: # # Spark::Mllib.import # # # Dense vectors # data = [ # LabeledPoint.new(0.0, [0.0, 1.0]), # LabeledPoin...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command/pair.rb
Ruby
mit
226
master
2,602
_Base = Spark::Command::Base # ------------------------------------------------------------------------------------------------- # CombineByKey class Spark::Command::CombineByKey # --------------- class Base < Spark::Command::Base def run(iterator, *) _run(iterator).to_a end def lazy_run(iter...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command/base.rb
Ruby
mit
226
master
3,561
## # Spark::Command::Base # # Parent for all commands (Map, FlatMap, Sort, ...) # class Spark::Command::Base DEFAULT_VARIABLE_OPTIONS = { type: Hash, function: true } def initialize(*args) settings.variables.each do |name, options| instance_variable_set("@#{name}", args.shift) end end ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command/statistic.rb
Ruby
mit
226
master
3,154
_Base = Spark::Command::Base # ------------------------------------------------------------------------------------------------- # Sample class Spark::Command::Sample < _Base variable :with_replacement, function: false, type: [TrueClass, FalseClass] variable :fraction, function: false, type: Numeric var...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command/basic.rb
Ruby
mit
226
master
7,381
_Base = Spark::Command::Base # ------------------------------------------------------------------------------------------------- # Map class Spark::Command::Map < _Base variable :map_function def run(iterator, *) iterator.map! do |item| @map_function.call(item) end iterator end def lazy_ru...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/command/sort.rb
Ruby
mit
226
master
1,230
_Base = Spark::Command::Base # ------------------------------------------------------------------------------------------------- # Sort class Spark::Command::SortByKey < _Base variable :key_function variable :ascending, function: false, type: [TrueClass, FalseClass] variable :spilling, function: false, type:...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/worker/spark_files.rb
Ruby
mit
226
master
224
class SparkFiles class << self attr_accessor :root_directory end def self.get(file_name) File.join(root_directory, file_name) end def self.get_content(file_name) File.read(get(file_name)) end end
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/worker/master.rb
Ruby
mit
226
master
2,871
#!/usr/bin/env ruby $PROGRAM_NAME = 'RubySparkMaster' require 'socket' require 'io/wait' require 'nio' require_relative 'worker' # New process group # Otherwise master can be killed from pry console Process.setsid # ================================================================================================= #...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/worker/worker.rb
Ruby
mit
226
master
4,264
#!/usr/bin/env ruby # Load root of the gem lib = File.expand_path(File.join('..', '..'), File.dirname(__FILE__)) $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'ruby-spark.rb' require 'socket' require_relative 'spark_files' # ===================================================...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/io.rb
Ruby
mit
226
master
1,321
module Spark module CoreExtension module IO module ClassMethods end module InstanceMethods # Reading def read_int unpack_int(read(4)) end def read_int_or_eof bytes = read(4) return Spark::Constant::DATA_EOF if bytes.nil? ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/module.rb
Ruby
mit
226
master
1,362
module Spark module CoreExtension module Module # Patch method to class unless already exist # # == Example: # # class Hash # def a # 1 # end # end # # module HashExtension # module InstanceMethods # def a...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/integer.rb
Ruby
mit
226
master
594
module Spark module CoreExtension module Integer module ClassMethods end module InstanceMethods end def self.included(base) base.extend(ClassMethods) base.send(:include, InstanceMethods) base.class_eval do const_set :MAX_WITH_SPARK, 1 << (1.size * ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/string.rb
Ruby
mit
226
master
539
module Spark module CoreExtension module String module ClassMethods end module InstanceMethods def camelize_with_spark self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end end def self.included(base) base.extend(ClassMethod...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/ip_socket.rb
Ruby
mit
226
master
495
module Spark module CoreExtension module IPSocket module ClassMethods end module InstanceMethods def port addr[1] end def hostname addr(true)[2] end def numeric_address addr[3] end end def self.included...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/object.rb
Ruby
mit
226
master
1,996
module Spark module CoreExtension module Object module ClassMethods end module InstanceMethods def deep_copy_with_spark Marshal.load(Marshal.dump(self)) end def silence_warnings old_verbose, $VERBOSE = $VERBOSE, nil yield ensure ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/ext/hash.rb
Ruby
mit
226
master
1,130
module Spark module CoreExtension module Hash module ClassMethods end module InstanceMethods # Destructively convert all keys to strings. def stringify_keys_with_spark! transform_keys!{ |key| key.to_s } end # Destructively convert all keys to symbols, ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper/parser.rb
Ruby
mit
226
master
2,061
module Spark module Helper module Parser def self.included(base) base.send :extend, Methods base.send :include, Methods end module Methods def to_java_hash(hash) hash_map = HashMap.new hash.each_pair do |key, value| begin ...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper/serialize.rb
Ruby
mit
226
master
1,536
module Spark module Helper module Serialize DIRECTIVE_INTEGER_BIG_ENDIAN = 'l>' DIRECTIVE_INTEGERS_BIG_ENDIAN = 'l>*' DIRECTIVE_LONG_BIG_ENDIAN = 'q>' DIRECTIVE_LONGS_BIG_ENDIAN = 'q>*' DIRECTIVE_DOUBLE_BIG_ENDIAN = 'G' DIRECTIVE_DOUBLES_BIG_ENDIAN = 'G*' DIRECTIVE_UNSIG...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper/statistic.rb
Ruby
mit
226
master
3,005
module Spark module Helper module Statistic # Returns a sampling rate that guarantees a sample of size >= sampleSizeLowerBound 99.99% of the time. # # == How the sampling rate is determined: # Let p = num / total, where num is the sample size and total is the total number of # datap...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper/logger.rb
Ruby
mit
226
master
885
module Spark module Helper module Logger def self.included(base) base.send :extend, Methods base.send :include, Methods end module Methods def log_info(message) Spark.logger.info(message) end def log_debug(message) Spark.logger.debu...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/helper/system.rb
Ruby
mit
226
master
909
module Spark module Helper module System def self.included(base) base.send :extend, Methods base.send :include, Methods end module Methods def windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ end def mri? RbConfig::CONFIG[...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/java_bridge/rjb.rb
Ruby
mit
226
master
702
if !ENV.has_key?('JAVA_HOME') raise Spark::ConfigurationError, 'Environment variable JAVA_HOME is not set' end require 'rjb' module Spark module JavaBridge class RJB < Base def initialize(*args) super Rjb.load(jars) Rjb.primitive_conversion = true end def import(nam...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/java_bridge/base.rb
Ruby
mit
226
master
6,399
## # Spark::JavaBridge::Base # # Parent for all adapter (ruby - java) # module Spark module JavaBridge class Base include Spark::Helper::System JAVA_OBJECTS = [ 'java.util.ArrayList', 'scala.collection.mutable.HashMap', 'org.apache.spark.SparkConf', 'org.apache.spark....
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/java_bridge/jruby.rb
Ruby
mit
226
master
432
require 'java' module Spark module JavaBridge class JRuby < Base def initialize(*args) super jars.each {|jar| require jar} end def import(name, klass) klass = "Java::#{klass}" Object.const_set(name, eval(klass)) rescue NameError raise_missing_clas...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql/row.rb
Ruby
mit
226
master
1,097
module Spark module SQL ## # Spark::SQL::Row # class Row attr_reader :data def self.from_java(object, with_schema=true) if with_schema fields = object.schema.fieldNames else # Create virtual schema (t0, t1, t2, ...) raise Spark::NotImplemented...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql/data_frame_reader.rb
Ruby
mit
226
master
2,943
module Spark module SQL class DataFrameReader attr_reader :sql_context, :jreader def initialize(sql_context) @sql_context = sql_context @jreader = sql_context.jsql_context.read end def df(jdf) DataFrame.new(jdf, sql_context) end # Specifies the input...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql/column.rb
Ruby
mit
226
master
9,904
module Spark module SQL class Column # ============================================================================= # Creating def self.to_java(col) if col.is_a?(Column) col.jcolumn else from_name(col) end end def self.from_literal(lite...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql/data_type.rb
Ruby
mit
226
master
4,685
module Spark module SQL ## # Spark::SQL::DataType # class DataType cattr_accessor :atomic_types self.atomic_types = {} cattr_accessor :complex_types self.complex_types = {} def self.parse(data) if data.is_a?(Hash) type = data['type'] if comp...
github
ondra-m/ruby-spark
https://github.com/ondra-m/ruby-spark
lib/spark/sql/data_frame.rb
Ruby
mit
226
master
6,695
module Spark module SQL ## # Spark::SQL::DataFrame # # All example are base on people.json # class DataFrame attr_reader :jdf, :sql_context def initialize(jdf, sql_context) @jdf = jdf @sql_context = sql_context end # Returns the column as a {Column}. ...