Class: Kwyjibo::DenseMatrix

Inherits:
Matrix
  • Object
show all
Defined in:
lib/kwyjibo.rb

Instance Attribute Summary collapse

Attributes inherited from Matrix

#cols, #rows

Instance Method Summary collapse

Methods inherited from Matrix

#*, #+, #-, #max, #min

Constructor Details

#initialize(rows, cols) ⇒ DenseMatrix

Returns a new instance of DenseMatrix.



126
127
128
129
# File 'lib/kwyjibo.rb', line 126

def initialize(rows,cols)
    @data = Array.new(rows) {Array.new(cols)}
    super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



124
125
126
# File 'lib/kwyjibo.rb', line 124

def data
  @data
end

Instance Method Details

#[](i) ⇒ Object



131
132
133
# File 'lib/kwyjibo.rb', line 131

def [](i)
    @data[i]
end

#[]=(i, value) ⇒ Object



135
136
137
# File 'lib/kwyjibo.rb', line 135

def []=(i,value)
    @data[i] = value
end

#trasObject



139
140
141
142
143
144
145
146
147
# File 'lib/kwyjibo.rb', line 139

def tras()
    c = DenseMatrix.new(@cols, @rows)
    c.rows.times do |i|
        c.cols.times do |j|
            c[i][j] = self[j][i]
        end
    end
    c
end

#x(value) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/kwyjibo.rb', line 149

def x(value)
    self.rows.times do |i|
        self.cols.times do |j|
            self[i][j] *= 2
        end
    end
end