class Array

Public Class Methods

pnew(size = nil, **options, &block) click to toggle source
# 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

Public Instance Methods

&(other) click to toggle source
Calls superclass method Ikra::Symbolic::ParallelOperations#&
# 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
Also aliased as: old_and
*(other) click to toggle source
Calls superclass method Ikra::Symbolic::ParallelOperations#*
# 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
Also aliased as: old_mul
+(other) click to toggle source
Calls superclass method Ikra::Symbolic::ParallelOperations#+
# 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
Also aliased as: old_plus
-(other) click to toggle source
Calls superclass method Ikra::Symbolic::ParallelOperations#-
# 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
Also aliased as: old_minus
[]=(index, element) click to toggle source
# 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
Also aliased as: old_set
all_types() click to toggle source
# File lib/type_aware_array.rb, line 29
def all_types
    type_counter.keys
end
combine(*others, &block) click to toggle source
# 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() click to toggle source

TODO: probably do not need this anymore

# 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() click to toggle source
# 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
old_and(other)
Alias for: &
old_minus(other)
Alias for: -
old_mul(other)
Alias for: *
old_or(other)
Alias for: |
old_plus(other)

Have to keep the old methods around because sometimes we want to have the original code

Alias for: +
old_push(*elements)
Alias for: push
old_set(index, element)
Alias for: []=
push(*elements) click to toggle source
# 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
Also aliased as: old_push
stencil(neighbors, out_of_range_value, use_parameter_array: true, with_index: false, &block) click to toggle source
# 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) click to toggle source
# File lib/symbolic/symbolic.rb, line 919
def to_command(dimensions: nil)
    return Ikra::Symbolic::ArrayIdentityCommand.new(self, dimensions: dimensions)
end
to_type_array_string() click to toggle source
# File lib/types/types/ruby_type.rb, line 83
def to_type_array_string
    "[" + map do |set|
        set.to_s
    end.join(", ") + "]"
end
|(other) click to toggle source
Calls superclass method Ikra::Symbolic::ParallelOperations#|
# 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
Also aliased as: old_or

Private Instance Methods

type_counter() click to toggle source
# File lib/type_aware_array.rb, line 59
def type_counter
    if @type_counter == nil
        @type_counter = {}
        @type_counter.default = 0
        
        each do |element|
            @type_counter[element.class] += 1
        end
    end
    
    @type_counter
end