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