DoubleArray.st
author Claus Gittinger <cg@exept.de>
Wed, 13 Feb 2019 22:10:53 +0100
changeset 23735 77363fc65861
parent 21080 ffebd509a3ae
child 21089 d50f93ca9622
child 23797 119ce5d12f09
permissions -rw-r--r--
#FEATURE by cg class: OrderedDictionary changed: #copyValuesFrom:to: class: OrderedDictionary class changed: #version_CVS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    12
"{ Package: 'stx:libbasic' }"
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    13
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
    14
"{ NameSpace: Smalltalk }"
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
    15
13825
a80eb51765c0 class definition
Claus Gittinger <cg@exept.de>
parents: 13708
diff changeset
    16
AbstractNumberVector variableDoubleSubclass:#DoubleArray
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    17
	instanceVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    18
	classVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    19
	poolDictionaries:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    20
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    23
!DoubleArray class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    24
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    27
 COPYRIGHT (c) 1993 by Claus Gittinger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
	      All Rights Reserved
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    37
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    39
documentation
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    40
"
13825
a80eb51765c0 class definition
Claus Gittinger <cg@exept.de>
parents: 13708
diff changeset
    41
    DoubleArrays store doubleFloat values (and nothing else).
16639
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    42
    They have been added to support heavy duty number crunching and
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    43
    data exchange with openGL frameworks and other mass data libraries
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
    44
    somewhat better than other smalltalks do. 
362
claus
parents: 155
diff changeset
    45
    Storing Floats & Doubles in these objects (instead of Arrays)
claus
parents: 155
diff changeset
    46
    has some benefits:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    47
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    48
    1) since the values are stored directly (instead of pointers to them)
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    49
       both access overhead and garbage collect overhead is minimized.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    50
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    51
    2) they can be much faster passed to c functions (such as graphics 
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    52
       libraries or heavy duty math packages), since the double values
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    53
       come packed and can be used in C by using a (double *) or double[].
362
claus
parents: 155
diff changeset
    54
       There is no need to loop over the array extracting doubles.      
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    55
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    56
    3) they could (in theory) be much more easily be processed by things like
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    57
       vector and array processors
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    58
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    59
    Be aware however, that Float- and DoubleArrays are not supported in other
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    60
    smalltalks - your program will thus become somewhat less portable.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    61
    (since their protocol is the same as normal arrays filled with floats,
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    62
     they can of course be easily simulated - a bit slower though)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
2820
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    64
    However, they could be simulated by a ByteArray, using doubleAt: and 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    65
    doubleAtPut: messages to access the elements, but that seems a bit
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    66
    clumsy and unelegant. Also, the stc-compiler may learn how to deal
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    67
    with Float- and DoubleArrays, making accesses very fast in the future.
2820
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    68
    Hint: if you use doubleArrays in your application and must port it
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    69
    to some other smalltalk, define a DoubleArray class there, which is derived
a128d890def3 comment
Claus Gittinger <cg@exept.de>
parents: 2145
diff changeset
    70
    from ByteArray, and add access methods.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    72
    Of course, DoubleArray can be subclassed,
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    73
    and named instance variables can be added there.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
362
claus
parents: 155
diff changeset
    75
    See example uses in the GLX interface and GLDemos.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    76
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    77
    [memory requirements:]
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    78
        OBJ-HEADER + (size * double-size)
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 2820
diff changeset
    79
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    80
    [See also:]
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
    81
        FloatArray Array
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    82
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    83
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    84
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    85
"
627
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    86
! !
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    87
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
    88
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
    89
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    90
!DoubleArray class methodsFor:'queries'!
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    91
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    92
elementByteSize
16850
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    93
    "for bit-like containers, return the number of bytes stored per element.
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    94
     Here, 8 is returned"
4011fc651793 comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents: 16639
diff changeset
    95
13708
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    96
    ^ 8
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    97
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    98
    "Created: / 15-09-2011 / 14:12:46 / cg"
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
    99
! !
079c1e1c7594 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   100
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   101
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   102
!DoubleArray methodsFor:'queries'!
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   103
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   104
defaultElement
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   105
    ^ Float zero
20301
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   106
!
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   107
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   108
isValidElement:anObject
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   109
    "return true, if I can hold this kind of object"
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   110
af76baeacf78 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 19031
diff changeset
   111
    ^ anObject isNumber
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   112
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   113
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   114
max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   115
    "return the largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   116
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   117
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   118
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   119
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   120
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   121
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   122
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   123
            double _max;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   124
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   125
            _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   126
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   127
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   128
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   129
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   130
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   131
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   132
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   133
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   134
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   135
                    if (_prev > _max) _max = _prev;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   136
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   137
                if (_this > _max) _max = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   138
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   139
            RETURN (__MKFLOAT(_max));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   140
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   141
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   142
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   143
    ^ super max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   144
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   145
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   146
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   147
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   148
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   149
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   150
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   151
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   152
     |a1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   153
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   154
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   155
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 max ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   156
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   157
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   158
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   159
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   160
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   161
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   162
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   163
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   164
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   165
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   166
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   167
     f1 max
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   168
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   169
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   170
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   171
min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   172
    "return the smallest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   173
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   174
%{  /* NOCONTEXT */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   175
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   176
        INT _sz = __doubleArraySize(self);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   177
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   178
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   179
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   180
            double _min;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   181
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   182
            _min = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   183
            if (_sz > 1) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   184
                INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   185
                double _prev, _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   186
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   187
                /* how about inline-mmx-asm for this ... */
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   188
                _this = _p[1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   189
                for (_i=2; _i<_sz; _i++) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   190
                    _prev = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   191
                    _this = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   192
                    if (_prev < _min) _min = _prev;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   193
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   194
                if (_this < _min) _min = _this;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   195
            }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   196
            RETURN (__MKFLOAT(_min));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   197
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   198
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   199
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   200
    ^ super min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   201
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   202
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   203
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   204
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   205
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   206
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   207
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   208
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   209
     |a1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   210
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   211
     a1 := (1 to:10000) asArray collect:#asFloat.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   212
     Time millisecondsToRun:[ 1000 timesRepeat:[ a1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   213
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   214
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   215
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   216
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   217
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   218
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   219
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   220
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   221
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   222
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   223
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   224
     f1 min
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   225
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   226
!
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   227
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   228
minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   229
    "return a Tuple holding the smallest and largest element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   230
     redefined for speed"
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   231
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   232
    |min max empty|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   233
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   234
%{  
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   235
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   236
        INT _sz = __doubleArraySize(self);
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   237
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   238
        if (_sz > 0) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   239
            INT _i;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   240
            double *_p = __DoubleArrayInstPtr(self)->d_element;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   241
            double _min, _max;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   242
            OBJ ret;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   243
            
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   244
            _min = _max = _p[0];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   245
            for (_i=_sz-1; _i>0; _i-=2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   246
                double _v1 = _p[_i];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   247
                double _v2 = _p[_i-1];
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   248
                if (_v1 < _v2) {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   249
                    if (_v1 < _min) _min = _v1;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   250
                    if (_v2 > _max) _max = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   251
                } else {
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   252
                    if (_v2 < _min) _min = _v2;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   253
                    if (_v1 > _max) _max = _v1;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   254
                }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   255
            }
21080
ffebd509a3ae #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20314
diff changeset
   256
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   257
            min = __MKFLOAT(_min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   258
            __PROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   259
            max = __MKFLOAT(_max);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   260
            __UNPROTECT__(min);
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   261
            RETURN (__ARRAY_WITH2(min, max));
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   262
        }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   263
        empty = true;
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   264
    }
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   265
%}.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   266
    empty == true ifTrue:[
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   267
        ^ self emptyCollectionError.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   268
    ].
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   269
    "/ fallback if no primitive code
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   270
    ^ super minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   271
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   272
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   273
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   274
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   275
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   276
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   277
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   278
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   279
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   280
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   281
     f1 := (1 to:10000) asDoubleArray.
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   282
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   283
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   284
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   285
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   286
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   287
     f1 := DoubleArray withAll:#(1 2 3 4 5).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   288
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   289
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   290
    "
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   291
     |f1|
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   292
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   293
     f1 := DoubleArray withAll:#(5 4 3 2 1).
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   294
     f1 minMax
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   295
    "
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   296
! !
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   297
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   298
!DoubleArray methodsFor:'vector arithmetic'!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   299
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   300
dot: aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   301
    "Return the dot product of the receiver and the argument.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   302
     Raises an error, if the argument is not of the same size as the receiver."
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   303
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   304
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   305
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   306
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   307
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   308
     && (__ClassInstPtr(__qClass(aFloatVector))->c_ninstvars == __mkSmallInteger(0))) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   309
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   310
        double __result = 0.0;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   311
        double *__p1 = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   312
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   313
        if (__mySize > 0) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   314
            if (__isFloats(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   315
                INT __otherSize = __floatArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   316
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   317
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   318
                    float *__p2 = __FloatArrayInstPtr(aFloatVector)->f_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   319
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   320
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   321
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   322
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   323
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   324
                    RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   325
                }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   326
            } else if (__isDoubles(aFloatVector)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   327
                INT __otherSize = __doubleArraySize(aFloatVector);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   328
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   329
                if (__mySize == __otherSize) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   330
                    double *__p2 = __DoubleArrayInstPtr(aFloatVector)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   331
                    INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   332
                    /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   333
                    for (__i=0; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   334
                        __result += (__p1[__i] * __p2[__i]);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   335
                    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   336
                    RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   337
                }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   338
            }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   339
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   340
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   341
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   342
    ^ super dot:aFloatVector
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   343
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   344
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   345
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   346
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   347
     v := #(2.0 2.0 1.0) asFloatArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   348
     v dot:v.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   349
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   350
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   351
     |v1 v2|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   352
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   353
     v1 := FloatArray new:10000 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   354
     v2 := FloatArray new:10000 withAll:3.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   355
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   356
        10000 timesRepeat:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   357
          v1 dot:v2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   358
        ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   359
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   360
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   361
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   362
    "Created: / 29-05-2007 / 13:13:39 / cg"
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   363
!
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   364
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   365
hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   366
    "primitive support for horner's-method computation of polynomials.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   367
     The vector is interpreted as providing the factors for a polynomial,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   368
        an*x^n + (an-1)*x^(n-1) + ... + a2(x) + a1
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   369
     where the ai are the elements of the Array.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   370
     The highest rank factor is at the first position, the 0-rank constant at last.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   371
     This is inlined c-code, which may get compiled to fast machine code,
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   372
     using multiply-and-add or vector instructions, if the CPU/Compiler support them."
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   373
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   374
    | mySize result |
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   375
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   376
%{
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   377
    double __x;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   378
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   379
    if (__isFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   380
        __x = __floatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   381
    } else if (__isShortFloat(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   382
        __x = (double)__shortFloatVal(x);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   383
    } else if (__isSmallInteger(x)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   384
        __x = (double)(__intVal(x));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   385
    } else {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   386
        goto getOutOfHere;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   387
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   388
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   389
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   390
        INT __mySize = __doubleArraySize(self);
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   391
        double *__elements = __DoubleArrayInstPtr(self)->d_element;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   392
        double __result = __elements[0];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   393
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   394
        if (__mySize > 1) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   395
            INT __i;
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   396
            /* how about inline-mmx-asm for this ... */
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   397
            for (__i=1; __i<__mySize; __i++) {
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   398
                __result = (__result * __x) + __elements[__i];
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   399
            }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   400
        }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   401
        RETURN (__MKFLOAT(__result));
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   402
    }
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   403
getOutOfHere: ;    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   404
%}.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   405
    ^ super hornerMultiplyAndAdd:x
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   406
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   407
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   408
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   409
     v := #(2.0 3.0 4.0) asDoubleArray.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   410
     v  hornerMultiplyAndAdd:10.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   411
    
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   412
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   413
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   414
     v hornerMultiplyAndAdd:10
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   415
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   416
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   417
     v := Array new:100 withAll:2.0.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   418
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   419
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   420
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   421
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   422
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   423
     v := FloatArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   424
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   425
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   426
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   427
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   428
     |v|
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   429
     v := DoubleArray new:100 withAll:2.
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   430
     Time millisecondsToRun:[
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   431
        10000 timesRepeat:[ v hornerMultiplyAndAdd:10]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   432
     ]
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   433
    "
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   434
! !
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   435
20314
7545d09005ca #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20301
diff changeset
   436
627
0a9e18feab08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
   437
!DoubleArray class methodsFor:'documentation'!
565
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   438
4f64b1faa6e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   439
version
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   440
    ^ '$Header$'
16853
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   441
!
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   442
e3e062d68503 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 16850
diff changeset
   443
version_CVS
19031
b8bbe1983d3a #FEATURE
Claus Gittinger <cg@exept.de>
parents: 16853
diff changeset
   444
    ^ '$Header$'
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
   445
! !
16639
d9417b0b93a1 class: DoubleArray
Claus Gittinger <cg@exept.de>
parents: 13825
diff changeset
   446