Skip to content

Instantly share code, notes, and snippets.

@cronin101
Last active August 29, 2015 13:57
Show Gist options
  • Save cronin101/9772637 to your computer and use it in GitHub Desktop.
Save cronin101/9772637 to your computer and use it in GitHub Desktop.
Hints possibly required for user evaluation task.

##Initiating a RubiCL computation pipeline To start a pipeline, annotate the dataset with the corresponding C-type. This is done using the square bracket notation shown below. All questions in the evaluation will use integers.

# Array support
big_array_of_numbers = [1, 2, 3, 4]
big_array_of_numbers[Int].further.method.calls.go.here

# Range support
big_range_of_numbers = (1..4)
big_range_of_numbers[Int].further.method.calls.go.here

# File support
big_file_of_numbers = File.open('./numbers.txt')
big_file_of_numbers[Int].further.method.calls.go.here

Things you might need to know

###Source: (http://www.ruby-doc.org/) ####Enumerable#count()

  • Returns the number of items in enum through enumeration.
  • If an argument is given, the number of items in enum that are equal to item are counted.
ary = [1, 2, 4, 2]
ary.count
#=> 4
ary.count(2)
#=> 2

####Enumerable#select(&block)

  • Returns an array containing all elements of enum for which the given block returns a true value.
(1..10).select { |i|  i % 3 == 0 }
#=> [3, 6, 9]

####Enumerable#zip(*args)

  • Takes one element from enum and merges corresponding elements from each args.
  • This generates a sequence of n-element arrays, where n is one more than the count of arguments. The length of the resulting sequence will be enum#size.
a = [ 4, 5, 6 ]
b = [ 7, 8, 9 ]
a.zip(b)
#=> [[4, 7], [5, 8], [6, 9]]
  • NOTE: When using #zip with RubiCL, the second dataset should not be type-annotated. This is because it is assumed to be type-identical to the first.

####Integer#even?

  • Returns true if int is an even number.
1.even?
#=> false
2.even?
#=> true

###Source: (Misc information)

  • Variable unpacking can be used within anonymous functions to access elements of a zipped list.
(1..10).zip(11..20).select { |x, y| x + y == 12 }
#=> [[1, 11]]
  • The % operator performs the modulo operation. A % B returns the remainder when dividing A by B.
1 % 2
#=> 1
2 % 2
#=> 0

###Source: (RubiCL API)

####Device#sum

  • Given a device containing a data buffer, returns the total given when all elements are reduced by addition.
(1..3)[Int].sum
#=> 6

####Device#fsts ####Device#snds

  • Given a device containing a tuple buffer (resulting from #zip) 'unzips' the dataset into just the first or second items of each tuple.
(1..3)[Int].zip(4..6).fsts[Fixnum]
#=> [1, 2, 3]
(1..3)[Int].zip(4..6).snds[Fixnum]
#=> [4, 5, 6]

####Device#braid(&block)

  • Given a device containing a tuple buffer (resulting from #zip) convert the buffer into an integer buffer using the provided combination function.
(1..3)[Int].zip(4..6).braid { |f, s| s - f }[Fixnum]
#=> [3, 3, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment