Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/include/array.rb

Instance Method Summary collapse

Instance Method Details

#each_coefficient(init = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/include/array.rb', line 2

def each_coefficient(init = nil)
	return Enumerator.new(self, :each_coefficient, init) unless block_given?

	init = Array.new(self.size, 0) unless init
	current = init.dup

	loop do
		yield current.dup

		# next coef
		self.size.times do |i|
			if self[i] == current[i]
				return if i == self.size - 1
				current[i] = 0
			else
				current[i] += 1
				break
			end
		end
	end
end

#to_iObject

Create integer from factorization of it



42
43
44
# File 'lib/include/array.rb', line 42

def to_i
	return self.map{|p, e| p ** e}.inject(&:*)
end

#to_m(coef_class = nil) ⇒ Object

to_matrix



36
37
38
39
# File 'lib/include/array.rb', line 36

def to_m(coef_class = nil)
	matrix = Abst::Matrix(coef_class || self[0][0].class, self.size, self[0].size)
	return matrix.new(self)
end

#to_set(sortable = true, &compare) ⇒ Object



24
25
26
27
# File 'lib/include/array.rb', line 24

def to_set(sortable = true, &compare)
	return SortableSet.new(self, &compare) if sortable
	return Set.new(self)
end

#to_v(coef_class = nil) ⇒ Object

to_vector



30
31
32
33
# File 'lib/include/array.rb', line 30

def to_v(coef_class = nil)
	vector = Abst::Vector(coef_class || self[0].class, self.size)
	return vector.new(self)
end