How to? DoubleArray

nicolas cellier ncellier at ifrance.com
Fri Feb 10 22:39:11 UTC 2006


Thanks Yoshiki and Andreas.

WHY I WANT DoubleArray :
--------------------------------

My aim is to interface with external library (LAPACK), this is what i call
Smallapack.

I want efficiency both in space and operation: i would not allocate these ten
thousand Float needed at each 100 by 100 matrix operation, and wouldn't
execute these many Float * or +, but LAPACK/BLAS will take major part of work
concerning operations.

FloatArray class is just fine, but some processing require double precision
arithmetic, and sorry Andreas, you cannot decide that in my place. So this is
why DoubleArray...

HOW I WOULD DO:
------------------------

I was thinking of using external heap for storing matrices and pass direct
pointers through FFI external calls. This is how i implemented in VW. No
primitive to write, no marshalling or copying, all Smalltalk solution...

For sure, direct pointer are dangerous, but operations on pointers are
protected in some low level methods, that should not be used directly (no way
to prevent someone to bypass warnings in comments and private category, so
not fully safe...).

I need at least some Smalltalk storage for surviving to snapshots. So a first
implementation of DoubleArray would just need methods for swapping bytes
(conform to current machine endianness) at startup, exchanging to/from
external heap and accessing.

Have you any objection or better ideas to suggest ?
**********************************************

Same optimized methods as FloatArray would be appreciated, but i do not need
them for now. Is it a lot more than copy/pasting FloatArray implementation ?

ABOUT BYTE SWAPPING :
------------------------------

Concerning your clue about #restoreEndianness, thank you again, it helped me
as a good starting point.

But i feel Squeak implementation is a little bit more tricky and less uniform
than VW.
In VW byte swapping service is centralized in a separate class
(UninterpretedBytes)  at which do register classes interested in endianness:
this is easier than more general startup service because you do not have to
bother with class initialization order, UninterpretedBytes do that for its
clients...
And secondly, previous endianness is stored in a single place (class var
WasBigEndian in UninterpretedBytes) instead of the LastSaveOrder trick in
ShortIntegerArray and ShortRunArray.
Will i have to repeat such a trick at each new endian-dependent class ? (i
would also have FloatComplex and DoubleComplex for instance).
By the way, i saw no startup message in MatrixTransform2x3, where is this
stuff ?
(i cannot test if swapped, only have one little endian machine).

Beside, tracking #endianness #isLittleEndian and #restoreEndianness, I did
 not manage to understand when those bytes where swapped when writing to a
 file, though i see very well how they are when reading, but i do not mind.
 However i crashed a 3.8  image trying to test some assertions. Unfortunately
 non reproducible...

out of memory

1105559676 ArrayedCollection class>newFromStream:
1105559268 [] in UndefinedObject>DoIt
1105559176 BlockContext>ensure:
1105558928 UndefinedObject>DoIt
1105552676 Compiler>evaluate:in:to:notifying:ifFail:logged:
1105552768 [] in ParagraphEditor>evaluateSelection
1105552584 BlockContext>on:do:
1105552448 ParagraphEditor>evaluateSelection
1105552356 ParagraphEditor>inspectIt
1105552264 TextMorphEditor>inspectIt:
1105552016 ParagraphEditor>dispatchOnCharacter:with:
1105551924 TextMorphEditor>dispatchOnCharacter:with:
1105551832 ParagraphEditor>readKeyboard
1105551740 TextMorphEditor>readKeyboard
1105550876 [] in TextMorph>keyStroke:
1105550784 TextMorph>handleInteraction:fromEvent:
1105550692 TextMorphForEditView>handleInteraction:fromEvent:
1105550548 TextMorph>keyStroke:
1105550456 TextMorphForEditView>keyStroke:
1105550364 TextMorph>handleKeystroke:
1105549996 KeyboardEvent>sentTo:
1105549904 Morph>handleEvent:
1105549812 Morph>handleFocusEvent:
1105550088 [] in HandMorph>sendFocusEvent:to:clear:
1105550180 [] in PasteUpMorph>becomeActiveDuring:
1105549720 BlockContext>on:do:
1105549628 PasteUpMorph>becomeActiveDuring:
1105549404 HandMorph>sendFocusEvent:to:clear:
1105549312 HandMorph>sendEvent:focus:clear:
1105549220 HandMorph>sendKeyboardEvent:
1105549128 HandMorph>handleEvent:
1105548908 HandMorph>processEvents
1105549000 [] in WorldState>doOneCycleNowFor:
1105548816 SequenceableCollection>do:
1105548724 WorldState>handsDo:
1105548632 WorldState>doOneCycleNowFor:
1105548172 WorldState>doOneCycleFor:
1105548080 PasteUpMorph>doOneCycle
1105304784 [] in Project class>spawnNewProcess
1105304968 [] in BlockContext>newProcess

Smalltalk doIt was maybe

| tmp tmp2 file |

tmp := MatrixTransform2x3 identity.
[file := (FileStream fileNamed: 'foo') binary.
tmp writeOn: file]
 ensure: [file close].

[file := (FileStream oldFileNamed: 'foo') binary.
tmp2 := MatrixTransform2x3 newFromStream: file]
 ensure: [file close].
^tmp2

or maybe the same code with

tmp :=MatrixTransform2x3 newFrom: #(1 0 3 0 0 512).

(a copy paste error form ShortRunArray test).

I do not know if it would help much., if any has an idea...

-------------------------------------------------------




More information about the Squeak-dev mailing list