[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

summary real vectors



Dear self users,

Following the solutions pointed out by James "kjx" Noble and Bay Chung
I implemented a solution like the third suggestion by James though the
fourth seems to be easier but I do not understand it completely and
were not able to make it work.

My object "realVector":

	traits _AddSlotsIfAbsent: (| realVector = () |)
	traits realVector _Define: (|
		parent*			= traits clonable.
		copy			= (resend.copy contents: contents copy).
		size			= (contents size).
		copySize: n FillingWith: x	= (
			resend.copy contents: contents copySize: n FillingWith: x).
		at: index Put: value	= (contents at: index Put: value).
		at: index 		= (contents at: index).
		_ doArith: o With:op	= (| erg. oper |
			oper: op asRealVector: size.
			erg: copySize:size.
			size do:[|:i| erg at:i Put:o value:(at:i) With:(oper at:i) ].
			erg.
		).
		asRealVector: n	= (
			(size=n) ifFalse:[error:'Dimensionen sind ungleich']. self).
		+ op		= (doArith:[|:a. :b | (a+b) ] With:op ).
		- op		= (doArith:[|:a. :b | (a-b) ] With:op ).
		* op		= (doArith:[|:a. :b | (a*b) ] With:op ).
		/ op		= (doArith:[|:a. :b | (a/b) ] With:op ).
	|)
	
	prototypes _AddSlotsIfAbsent: (| realVector = () |)
	prototypes realVector _Define: (|
		parent* = traits realVector.
		contents ** <- vector.
	|)
	
	traits system float _AddSlots: (|
		_ vectorConvert*** = traits realVector.
		asRealVector: n	= (| erg |
			erg: realVector copySize:n.
			n do:[|:i| erg at:i Put:self ].
			erg.
		)
	|)
	
Perhaps realVectors should be renamed to arithVector. Something like
double dispatching should be added.

Regards							Frank Dzaak.

_______________________________________________________________________________

Deutsche Forschungsanstalt fuer Luft- und Raumfahrt e.V.
Institut fuer Flugmechanik
Frank.Dzaak@kolibri.fm.bs.dlr.de
Flughafen
3300 Braunschweig
Deutschland
_______________________________________________________________________________