Method: SparseTensor#scalar_binary

Defined in:
lib/graphkit.rb

#scalar_binary(other, &block) ⇒ Object

Raises:

  • (ArgumentError)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/graphkit.rb', line 120

def scalar_binary(other, &block)
	raise ArgumentError unless other.class == self.class
	raise RankError.new("Different ranks: #@rank, #{other.rank}") unless other.rank == @rank

	new = self.class.new(@rank)
	self.keys.each do |key|
		if other[key]
			new[key] = yield(self[key], other[key])
		else
			new[key] = self[key]
		end
	end
	(other.keys - self.keys).each{|key| new[key] = other[key]}
	new
end