Class: Array
Class Method Summary
collapse
Instance Method Summary
collapse
#/, #<, #<=, #>, #>=, #^, #pcombine, #pmap, #preduce, #pstencil, #pzip
Class Method Details
.pnew(size = nil, **options, &block) ⇒ Object
857
858
859
860
861
862
863
864
865
866
867
868
869
|
# File 'lib/symbolic/symbolic.rb', line 857
def pnew(size = nil, **options, &block)
if size != nil
dimensions = [size]
else
dimensions = options[:dimensions]
end
map_options = options.dup
map_options.delete(:dimensions)
return Ikra::Symbolic::ArrayIndexCommand.new(
dimensions: dimensions, block_size: options[:block_size]).pmap(**map_options, &block)
end
|
Instance Method Details
911
912
913
914
915
916
917
|
# File 'lib/symbolic/symbolic.rb', line 911
def &(other)
if other.is_a?(Ikra::Symbolic::ArrayCommand)
super(other)
else
return self.old_and(other)
end
end
|
895
896
897
898
899
900
901
|
# File 'lib/symbolic/symbolic.rb', line 895
def *(other)
if other.is_a?(Ikra::Symbolic::ArrayCommand)
super(other)
else
return self.old_mul(other)
end
end
|
879
880
881
882
883
884
885
|
# File 'lib/symbolic/symbolic.rb', line 879
def +(other)
if other.is_a?(Ikra::Symbolic::ArrayCommand)
super(other)
else
return self.old_plus(other)
end
end
|
887
888
889
890
891
892
893
|
# File 'lib/symbolic/symbolic.rb', line 887
def -(other)
if other.is_a?(Ikra::Symbolic::ArrayCommand)
super(other)
else
return self.old_minus(other)
end
end
|
#[]=(index, element) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/type_aware_array.rb', line 47
def []=(index, element)
type_counter[self[index].class] -= 1
if type_counter[self[index].class] == 0
type_counter.delete(self[index].class)
end
old_set(index, element)
type_counter[element.class] += 1
end
|
#all_types ⇒ Object
29
30
31
|
# File 'lib/type_aware_array.rb', line 29
def all_types
type_counter.keys
end
|
#combine(*others, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/cpu/cpu_implementation.rb', line 30
def combine(*others, &block)
return Array.new(self.size) do |index|
other_elements = others.map do |other|
other[index]
end
block.call(self[index], *other_elements)
end
end
|
#common_superclass ⇒ Object
TODO: probably do not need this anymore
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/type_aware_array.rb', line 4
def common_superclass
class_counter = {}
class_counter.default = 0
index = 0
each do |cls|
while (cls != BasicObject) do
class_counter[cls] += 1
cls = cls.superclass
end
index += 1
end
smallest = Object
class_counter.each do |cls, counter|
if counter == size
if cls < smallest
smallest = cls
end
end
end
smallest
end
|
#ikra_type ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/types/types/array_type.rb', line 128
def ikra_type
inner_type = Ikra::Types::UnionType.new
self.each do |element|
inner_type.add(element.ikra_type)
end
return Ikra::Types::ArrayType.new(inner_type)
end
|
877
|
# File 'lib/symbolic/symbolic.rb', line 877
alias_method :old_and, :&
|
#old_minus ⇒ Object
874
|
# File 'lib/symbolic/symbolic.rb', line 874
alias_method :old_minus, :-
|
875
|
# File 'lib/symbolic/symbolic.rb', line 875
alias_method :old_mul, :*
|
876
|
# File 'lib/symbolic/symbolic.rb', line 876
alias_method :old_or, :|
|
Have to keep the old methods around because sometimes we want to have the original code
873
|
# File 'lib/symbolic/symbolic.rb', line 873
alias_method :old_plus, :+
|
33
|
# File 'lib/type_aware_array.rb', line 33
alias :old_push :push
|
45
|
# File 'lib/type_aware_array.rb', line 45
alias :old_set :[]=
|
#push(*elements) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/type_aware_array.rb', line 35
def push(*elements)
old_push(*elements)
for element in elements
type_counter[element.class] += 1
end
self
end
|
#stencil(neighbors, out_of_range_value, use_parameter_array: true, with_index: false, &block) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/cpu/cpu_implementation.rb', line 2
def stencil(neighbors, out_of_range_value, use_parameter_array: true, with_index: false, &block)
copy = self.dup
return Array.new(size) do |index|
if neighbors.min + index < 0 || neighbors.max + index > size - 1
out_of_range_value
else
values = neighbors.map do |offset|
copy[index + offset]
end
if use_parameter_array
if with_index
block.call(values, index)
else
block.call(values)
end
else
if with_index
block.call(*values, index)
else
block.call(*values)
end
end
end
end
end
|
#to_command(dimensions: nil) ⇒ Object
#to_type_array_string ⇒ Object
83
84
85
86
87
|
# File 'lib/types/types/ruby_type.rb', line 83
def to_type_array_string
"[" + map do |set|
set.to_s
end.join(", ") + "]"
end
|
903
904
905
906
907
908
909
|
# File 'lib/symbolic/symbolic.rb', line 903
def |(other)
if other.is_a?(Ikra::Symbolic::ArrayCommand)
super(other)
else
return self.old_or(other)
end
end
|