Class: NumRu::LinearCoordMapping

Inherits:
CoordMapping show all
Defined in:
lib/numru/gphys/coordmapping.rb

Instance Attribute Summary collapse

Attributes inherited from CoordMapping

#rank

Instance Method Summary collapse

Methods inherited from CoordMapping

#inversion_rigorous?, #map_grid

Constructor Details

#initialize(offset = nil, factor = nil) ⇒ LinearCoordMapping

Returns a new instance of LinearCoordMapping.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/numru/gphys/coordmapping.rb', line 171

def initialize(offset=nil, factor=nil)

	 #< argument check & set rank, offset, factor >

	 if !offset && !factor
	    raise ArgumentError,"One of offset and factor must be specified"
	 elsif !factor
	    raise ArgumentError,"offset is not a NVector" if !offset.is_a?(NVector)
	    @rank = offset.length
	    @factor = NMatrix.float(@rank,@rank)
	    @factor.diagonal!(1)
	 else
	    raise ArgumentError,"factor is not a NMAtrix" if !factor.is_a?(NMatrix)
	    nx,ny = factor.shape
	    raise ArgumentError,"factor must be a square matrix" if nx != ny
	    @rank = nx
	    if offset
  raise ArgumentError,"offset is not a NVector" if !offset.is_a?(NVector)
  if offset.length != @rank
		  raise ArgumentError,"inconsistent dimensionarity between "+
 "offset #{offset.length} and factor #{factor.shape}"
  end
  @offset = offset
	    else
  @offset = NVector.float(@rank)
	    end
	    @factor = factor
	 end

	 #< other parameters >

	 @inversion_rigorous = true
	 @inv_factor = nil   # deferred until needed (might not be invertible)

end

Instance Attribute Details

#factorObject (readonly)

Returns the value of attribute factor.



207
208
209
# File 'lib/numru/gphys/coordmapping.rb', line 207

def factor
  @factor
end

#offsetObject (readonly)

Returns the value of attribute offset.



207
208
209
# File 'lib/numru/gphys/coordmapping.rb', line 207

def offset
  @offset
end

Instance Method Details

#inverseObject



224
225
226
227
228
229
# File 'lib/numru/gphys/coordmapping.rb', line 224

def inverse
	 __set_inv_factor if !@inv_factor
	 LinearCoordMapping.new( -@inv_factor*@offset, @inv_factor )
	 # Here, LinearCoordMapping.new is better than class.new,
   # since the constructor may change in subclasses.
end

#inverse_map(*args) ⇒ Object



216
217
218
219
220
221
222
# File 'lib/numru/gphys/coordmapping.rb', line 216

def inverse_map(*args)
	 __check_args_m(*args)
	 p = __to_NVector(*args)
	 __set_inv_factor if !@inv_factor
	 x = @inv_factor * ( p - @offset )
	 (0...@rank).collect{|i| x[i,false]}
end

#map(*args) ⇒ Object



209
210
211
212
213
214
# File 'lib/numru/gphys/coordmapping.rb', line 209

def map(*args)
	 __check_args_m(*args)
	 x = __to_NVector(*args)
	 p = @offset + @factor*x
	 (0...@rank).collect{|i| p[i,false]}
end