FloatArray.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 18 Jul 2011 16:22:09 +0100
branchjv
changeset 17846 24edc476ac18
parent 17845 7e0cfaac936d
child 17862 8a8ae3107950
permissions -rw-r--r--
Merged with /trunk
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
"
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    12
"{ Package: 'stx:libbasic' }"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
ArrayedCollection variableFloatSubclass:#FloatArray
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    15
	instanceVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    16
	classVariableNames:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    17
	poolDictionaries:''
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    18
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    21
!FloatArray class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    22
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    25
 COPYRIGHT (c) 1993 by Claus Gittinger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
	      All Rights Reserved
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    35
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    37
documentation
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    39
    FloatArrays store floats (and nothing else).
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    40
    See documentation in DoubleArray for more information.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    41
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    42
    [memory requirements:]
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    43
        OBJ-HEADER + (size * float-size)
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    44
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    45
    [See also:]
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
    46
        DoubleArray Array
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    47
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    48
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    49
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 3
diff changeset
    50
"
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    51
! !
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
    52
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    53
!FloatArray methodsFor:'arithmetic'!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    54
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    55
* anObject
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    56
    "return the product of the receiver and the argument.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    57
     The argument may either be a scalar or another vector"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    58
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    59
    ^ self clone *= anObject
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    60
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    61
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    62
     #(1 2 3 4) asFloatArray * 3  
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    63
     #(1 2 3 4) asFloatArray * #(1 2 3 4) asFloatArray
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    64
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    65
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    66
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    67
+ anObject
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    68
    "return the sum of the receiver and the argument.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    69
     The argument may either be a scalar or another vector"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    70
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    71
    ^ self clone += anObject
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    72
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    73
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    74
     #(1 2 3 4) asFloatArray + 3      
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    75
     #(1 2 3 4) asFloatArray + #(1 2 3 4) asFloatArray  
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    76
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    77
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
    78
10578
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    79
- anObject
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    80
    "return the difference of the receiver and the argument.
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    81
     The argument may either be a scalar or another vector"
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    82
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    83
    ^ self clone -= anObject
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    84
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    85
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    86
     #(1 2 3 4) asFloatArray - 3      
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    87
     #(1 2 3 4) asFloatArray - #(1 2 3 4) asFloatArray  
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    88
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    89
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    90
    "Created: / 30-05-2007 / 17:41:46 / cg"
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    91
!
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
    92
10579
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    93
/ anObject
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    94
    "return the division of the receiver and the argument.
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    95
     The argument may either be a scalar or another vector"
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    96
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    97
    ^ self clone /= anObject
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    98
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
    99
    "
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   100
     #(1 2 3 4) asFloatArray / 3      
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   101
     #(1 2 3 4) asFloatArray / #(1 2 3 4) asFloatArray  
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   102
    "
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   103
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   104
    "Created: / 30-05-2007 / 17:46:05 / cg"
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   105
!
Claus Gittinger <cg@exept.de>
parents: 10578
diff changeset
   106
10580
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   107
abs
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   108
    ^ self clone primAbs
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   109
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   110
    "Created: / 30-05-2007 / 17:47:50 / cg"
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   111
!
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   112
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   113
negated
10580
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   114
    ^ self clone primNegated
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   115
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   116
    "Modified: / 30-05-2007 / 17:51:47 / cg"
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   117
!
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   118
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   119
primAbs
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   120
    "destructive absolute value of each element"
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   121
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   122
%{
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   123
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   124
        int _sz = __floatArraySize(self);
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   125
        int i;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   126
        float *_p = __FloatArrayInstPtr(self)->f_element;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   127
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   128
        /* how about inline-mmx-asm for this ... */
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   129
        for (i=0; i<_sz; i++) {
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   130
            float f = _p[i];
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   131
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   132
            if (f < 0) {
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   133
                _p[i] = -f;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   134
            }
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   135
        }
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   136
        RETURN (self);
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   137
    }
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   138
%}. 
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   139
    1 to: self size do:[:i| self at: i put: (self at: i) abs].
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   140
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   141
    "
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   142
     |f|
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   143
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   144
     f := FloatArray withAll:#(-1 2 -3 4 -5).
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   145
     f abs.   
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   146
     f
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   147
    "
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   148
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   149
    "Created: / 30-05-2007 / 17:50:17 / cg"
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   150
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   151
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   152
primAddArray: floatArray
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   153
    "add the vector argument into the receiver (destructive).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   154
     The argument must be another vector"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   155
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   156
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   157
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   158
     && __isFloats(floatArray)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   159
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   160
        int _sz1 = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   161
        int _sz2 = __floatArraySize(floatArray);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   162
        int i;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   163
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   164
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   165
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   166
        if (_sz2 >= _sz1) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   167
            /* how about inline-mmx-asm for this ... */
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   168
            for (i=0; i<_sz1; i++) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   169
                _p1[i] += _p2[i];
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   170
            }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   171
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   172
        RETURN (self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   173
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   174
%}. 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   175
    1 to: self size do:[:i| self at: i put: (self at: i) + (floatArray at: i)].
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   176
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   177
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   178
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   179
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   180
     f1 := FloatArray withAll:#(1 2 3 4 5).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   181
     f2 := FloatArray withAll:#(2 2 2 3 3).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   182
     f1 += f2.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   183
     f1         
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   184
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   185
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   186
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   187
primAddScalar: aScalar
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   188
    "add the scalar argument into the receiver (destructive)."
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   189
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   190
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   191
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   192
        int _sz1 = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   193
        int i;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   194
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   195
        float v;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   196
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   197
        if (__isFloat(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   198
            v = (float)(__floatVal(aScalar));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   199
        } else  if (__isShortFloat(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   200
            v = __shortFloatVal(aScalar);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   201
        } else if (__isSmallInteger(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   202
            v = (float)(__intVal(aScalar));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   203
        } else 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   204
            goto badArg;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   205
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   206
        /* how about inline-mmx-asm for this ... */
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   207
        for (i=0; i<_sz1; i++) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   208
            _p1[i] += v;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   209
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   210
        RETURN (self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   211
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   212
    badArg: ;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   213
%}.   
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   214
    1 to: self size do:[:i| self at: i put: (self at: i) + aScalar].
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   215
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   216
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   217
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   218
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   219
     f1 := FloatArray withAll:#(1 2 3 4 5).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   220
     f1 += 2.0.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   221
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   222
     f1 += 2.0 asShortFloat.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   223
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   224
     f1 += 2.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   225
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   226
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   227
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   228
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   229
primDivArray: floatArray
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   230
    "divide the vector argument into the receiver (destructive).
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   231
     The argument must be another vector"
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   232
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   233
%{
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   234
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   235
     && __isFloats(floatArray)
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   236
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   237
        int _sz1 = __floatArraySize(self);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   238
        int _sz2 = __floatArraySize(floatArray);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   239
        int i;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   240
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   241
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   242
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   243
        if (_sz2 >= _sz1) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   244
            /* how about inline-mmx-asm for this ... */
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   245
            for (i=0; i<_sz1; i++) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   246
                _p1[i] /= _p2[i];
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   247
            }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   248
        }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   249
        RETURN (self);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   250
    }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   251
%}.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   252
    1 to: self size do:[:i| self at: i put: (self at: i) / (floatArray at: i)].
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   253
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   254
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   255
     |f1 f2|
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   256
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   257
     f1 := FloatArray withAll:#(1 2 3 4 5).
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   258
     f2 := FloatArray withAll:#(2 2 2 3 3).
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   259
     f1 /= f2.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   260
     f1         
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   261
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   262
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   263
    "Modified: / 29-05-2007 / 16:01:34 / cg"
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   264
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   265
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   266
primDivScalar: aScalar
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   267
    "divide the scalar argument into the receiver (destructive)."
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   268
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   269
%{
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   270
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   271
        int _sz1 = __floatArraySize(self);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   272
        int i;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   273
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   274
        float v;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   275
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   276
        if (__isFloat(aScalar)) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   277
            v = (float)(__floatVal(aScalar));
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   278
        } else  if (__isShortFloat(aScalar)) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   279
            v = __shortFloatVal(aScalar);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   280
        } else if (__isSmallInteger(aScalar)) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   281
            v = (float)(__intVal(aScalar));
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   282
        } else 
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   283
            goto badArg;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   284
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   285
        /* how about inline-mmx-asm for this ... */
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   286
        for (i=0; i<_sz1; i++) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   287
            _p1[i] /= v;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   288
        }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   289
        RETURN (self);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   290
    }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   291
    badArg: ;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   292
%}.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   293
    1 to: self size do:[:i| self at: i put: (self at: i) / aScalar].
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   294
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   295
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   296
     |f1 f2|
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   297
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   298
     f1 := FloatArray withAll:#(1 2 3 4 5).
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   299
     f1 /= 2.0.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   300
     Transcript showCR:f1.              
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   301
     f1 /= 2.0 asShortFloat.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   302
     Transcript showCR:f1.              
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   303
     f1 /= 2.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   304
     Transcript showCR:f1.              
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   305
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   306
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   307
    "Modified: / 29-05-2007 / 16:01:39 / cg"
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   308
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   309
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   310
primMulArray: floatArray
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   311
    "multiply the vector argument into the receiver (destructive).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   312
     The argument must be another vector"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   313
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   314
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   315
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   316
     && __isFloats(floatArray)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   317
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   318
        int _sz1 = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   319
        int _sz2 = __floatArraySize(floatArray);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   320
        int i;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   321
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   322
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   323
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   324
        if (_sz2 >= _sz1) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   325
            /* how about inline-mmx-asm for this ... */
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   326
            for (i=0; i<_sz1; i++) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   327
                _p1[i] *= _p2[i];
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   328
            }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   329
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   330
        RETURN (self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   331
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   332
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   333
    1 to: self size do:[:i| self at: i put: (self at: i) * (floatArray at: i)].
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   334
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   335
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   336
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   337
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   338
     f1 := FloatArray withAll:#(1 2 3 4 5).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   339
     f2 := FloatArray withAll:#(2 2 2 3 3).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   340
     f1 *= f2.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   341
     f1         
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   342
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   343
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   344
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   345
primMulScalar: aScalar
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   346
    "multiply the scalar argument into the receiver (destructive)."
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   347
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   348
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   349
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   350
        int _sz1 = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   351
        int i;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   352
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   353
        float v;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   354
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   355
        if (__isFloat(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   356
            v = (float)(__floatVal(aScalar));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   357
        } else  if (__isShortFloat(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   358
            v = __shortFloatVal(aScalar);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   359
        } else if (__isSmallInteger(aScalar)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   360
            v = (float)(__intVal(aScalar));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   361
        } else 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   362
            goto badArg;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   363
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   364
        /* how about inline-mmx-asm for this ... */
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   365
        for (i=0; i<_sz1; i++) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   366
            _p1[i] *= v;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   367
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   368
        RETURN (self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   369
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   370
    badArg: ;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   371
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   372
    1 to: self size do:[:i| self at: i put: (self at: i) * aScalar].
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   373
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   374
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   375
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   376
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   377
     f1 := FloatArray withAll:#(1 2 3 4 5).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   378
     f1 *= 2.0.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   379
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   380
     f1 *= 2.0 asShortFloat.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   381
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   382
     f1 *= 2.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   383
     Transcript showCR:f1.              
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   384
    "
10578
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   385
!
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   386
10580
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   387
primNegated
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   388
    "destructive negative value of each element"
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   389
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   390
%{
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   391
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   392
        int _sz = __floatArraySize(self);
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   393
        int i;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   394
        float *_p = __FloatArrayInstPtr(self)->f_element;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   395
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   396
        /* how about inline-mmx-asm for this ... */
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   397
        for (i=0; i<_sz; i++) {
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   398
            float f = _p[i];
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   399
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   400
            _p[i] = -f;
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   401
        }
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   402
        RETURN (self);
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   403
    }
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   404
%}. 
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   405
    1 to: self size do:[:i| self at: i put: (self at: i) negated].
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   406
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   407
    "
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   408
     |f|
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   409
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   410
     f := FloatArray withAll:#(-1 2 -3 4 -5).
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   411
     f negated.   
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   412
     f    
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   413
    "
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   414
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   415
    "Created: / 30-05-2007 / 17:51:29 / cg"
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   416
!
Claus Gittinger <cg@exept.de>
parents: 10579
diff changeset
   417
10578
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   418
primSubtractArray: floatArray
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   419
    "subtract the vector argument from the receiver (destructive).
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   420
     The argument must be another vector"
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   421
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   422
%{
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   423
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   424
     && __isFloats(floatArray)
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   425
     && (__ClassInstPtr(__qClass(floatArray))->c_ninstvars == __mkSmallInteger(0))) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   426
        int _sz1 = __floatArraySize(self);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   427
        int _sz2 = __floatArraySize(floatArray);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   428
        int i;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   429
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   430
        float *_p2 = __FloatArrayInstPtr(floatArray)->f_element;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   431
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   432
        if (_sz2 >= _sz1) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   433
            /* how about inline-mmx-asm for this ... */
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   434
            for (i=0; i<_sz1; i++) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   435
                _p1[i] -= _p2[i];
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   436
            }
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   437
        }
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   438
        RETURN (self);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   439
    }
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   440
%}. 
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   441
    1 to: self size do:[:i| self at: i put: (self at: i) - (floatArray at: i)].
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   442
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   443
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   444
     |f1 f2|
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   445
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   446
     f1 := FloatArray withAll:#(1 2 3 4 5).
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   447
     f2 := FloatArray withAll:#(2 2 2 3 3).
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   448
     f1 -= f2.
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   449
     f1         
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   450
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   451
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   452
    "Created: / 30-05-2007 / 17:42:41 / cg"
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   453
!
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   454
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   455
primSubtractScalar: aScalar
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   456
    "subtract the scalar argument from the receiver (destructive)."
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   457
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   458
%{
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   459
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   460
        int _sz1 = __floatArraySize(self);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   461
        int i;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   462
        float *_p1 = __FloatArrayInstPtr(self)->f_element;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   463
        float v;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   464
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   465
        if (__isFloat(aScalar)) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   466
            v = (float)(__floatVal(aScalar));
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   467
        } else  if (__isShortFloat(aScalar)) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   468
            v = __shortFloatVal(aScalar);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   469
        } else if (__isSmallInteger(aScalar)) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   470
            v = (float)(__intVal(aScalar));
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   471
        } else 
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   472
            goto badArg;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   473
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   474
        /* how about inline-mmx-asm for this ... */
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   475
        for (i=0; i<_sz1; i++) {
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   476
            _p1[i] -= v;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   477
        }
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   478
        RETURN (self);
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   479
    }
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   480
    badArg: ;
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   481
%}.   
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   482
    1 to: self size do:[:i| self at: i put: (self at: i) - aScalar].
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   483
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   484
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   485
     |f1 f2|
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   486
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   487
     f1 := FloatArray withAll:#(1 2 3 4 5).
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   488
     f1 -= 2.0.
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   489
     Transcript showCR:f1.              
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   490
     f1 -= 2.0 asShortFloat.
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   491
     Transcript showCR:f1.              
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   492
     f1 -= 2.
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   493
     Transcript showCR:f1.              
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   494
    "
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   495
Claus Gittinger <cg@exept.de>
parents: 10561
diff changeset
   496
    "Created: / 30-05-2007 / 17:43:06 / cg"
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   497
! !
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   498
17736
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   499
!FloatArray methodsFor:'arithmetic destructive'!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   500
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   501
*= anObject
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   502
    "multiply the argument into the receiver (destructive).
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   503
     The argument may either be a scalar or another vector"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   504
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   505
    ^ anObject isNumber
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   506
            ifTrue:[self primMulScalar: anObject asFloat]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   507
            ifFalse:[self primMulArray: anObject]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   508
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   509
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   510
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   511
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   512
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   513
     f *= 3.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   514
     f         
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   515
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   516
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   517
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   518
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   519
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   520
     f *= #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   521
     f     
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   522
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   523
!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   524
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   525
+= anObject
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   526
    "add the argument into the receiver (destructive).
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   527
     The argument may either be a scalar or another vector"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   528
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   529
    ^ anObject isNumber
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   530
            ifTrue:[self primAddScalar: anObject asFloat]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   531
            ifFalse:[self primAddArray: anObject]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   532
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   533
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   534
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   535
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   536
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   537
     f += 3.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   538
     f         
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   539
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   540
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   541
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   542
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   543
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   544
     f += #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   545
     f      
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   546
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   547
!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   548
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   549
-= anObject
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   550
    "subtract the argument from the receiver (destructive).
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   551
     The argument may either be a scalar or another vector"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   552
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   553
    ^ anObject isNumber
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   554
            ifTrue:[self primSubtractScalar: anObject asFloat]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   555
            ifFalse:[self primSubtractArray: anObject]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   556
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   557
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   558
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   559
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   560
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   561
     f -= 3.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   562
     f         
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   563
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   564
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   565
     |f|
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   566
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   567
     f := #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   568
     f += #(1 2 3 4) asFloatArray.
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   569
     f      
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   570
    "
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   571
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   572
    "Created: / 30-05-2007 / 17:42:13 / cg"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   573
!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   574
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   575
/= anObject
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   576
    "divide the argument into the receiver (destructive).
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   577
     The argument may either be a scalar or another vector"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   578
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   579
    ^ anObject isNumber
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   580
            ifTrue:[self primDivScalar: anObject asFloat]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   581
            ifFalse:[self primDivArray: anObject]
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   582
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   583
    "Modified: / 30-05-2007 / 17:45:46 / cg"
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   584
! !
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   585
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   586
!FloatArray methodsFor:'copying'!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   587
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   588
clone
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   589
    "return a copy of the receiver"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   590
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   591
    |newArr|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   592
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   593
    newArr := self class new:(self size).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   594
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   595
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   596
        int _sz = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   597
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   598
        bcopy(__FloatArrayInstPtr(self)->f_element,
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   599
              __FloatArrayInstPtr(newArr)->f_element,
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   600
              sizeof(float) * _sz);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   601
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   602
        RETURN (newArr);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   603
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   604
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   605
    newArr replaceFrom:1 to:self size with:self startingAt:1.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   606
    ^ newArr
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   607
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   608
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   609
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   610
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   611
     f1 := FloatArray withAll:#(1 2 3 4 5).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   612
     f1 clone         
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   613
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   614
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   615
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   616
copyFrom:start to:stop
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   617
    "return a partial copy of the receiver"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   618
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   619
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   620
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   621
        if (__bothSmallInteger(start, stop)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   622
            int __start = __intVal(start) - 1;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   623
            int __stop = __intVal(stop) - 1 ;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   624
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   625
            if (__stop >= __start) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   626
                int __sz = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   627
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   628
                if (((unsigned)__start < __sz) 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   629
                 && ((unsigned)__stop < __sz)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   630
                    int __n = __stop - __start + 1;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   631
                    OBJ __nObj;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   632
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   633
                    __nObj = __STX___new(sizeof(struct __FloatArray) + (__n - 1) * sizeof(float));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   634
                    if (__nObj != nil) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   635
                        __objPtr(__nObj)->o_class = __qClass(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   636
                        __STORE(__nObj, __qClass(self));
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   637
                        bcopy(__FloatArrayInstPtr(self)->f_element + __start,
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   638
                              __FloatArrayInstPtr(__nObj)->f_element,
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   639
                              sizeof(float) * __n);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   640
                        RETURN(__nObj);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   641
                    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   642
                }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   643
            }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   644
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   645
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   646
%}. 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   647
    ^ super copyFrom:start to:stop
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   648
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   649
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   650
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   651
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   652
     f1 := FloatArray withAll:#(1 2 3 4 5 6).
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   653
     f2 := f1 copyFrom:2 to:4.         
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   654
     f2        
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   655
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   656
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   657
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   658
replaceFrom:start to:stop with:aCollection startingAt:replStart
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   659
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   660
    if ((__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   661
     && __isFloats(aCollection)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   662
     && (__ClassInstPtr(__qClass(aCollection))->c_ninstvars == __mkSmallInteger(0))) {
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   663
        if (__bothSmallInteger(start, stop)
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   664
         && __isSmallInteger(replStart)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   665
            int __start = __intVal(start) - 1;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   666
            int __stop = __intVal(stop) - 1 ;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   667
            int __replStart = __intVal(replStart) - 1 ;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   668
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   669
            if (__stop >= __start) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   670
                int __sz = __floatArraySize(self);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   671
                int __otherSz = __floatArraySize(aCollection);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   672
                int __replStop = __replStart + (__stop-__start);
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   673
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   674
                if (((unsigned)__start < __sz) 
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   675
                 && ((unsigned)__stop < __sz)
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   676
                 && ((unsigned)__replStart < __otherSz)
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   677
                 && ((unsigned)__replStop < __otherSz)) {
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   678
                    int __n = __stop - __start + 1;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   679
5773
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   680
                    if (aCollection != self) {
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   681
                        bcopy(&(__FloatArrayInstPtr(aCollection)->f_element[__replStart]),
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   682
                              &(__FloatArrayInstPtr(self)->f_element[__start]),
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   683
                              sizeof(float) * __n);
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   684
                        RETURN(self);
86e1a2543de7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5768
diff changeset
   685
                    }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   686
                }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   687
            }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   688
        }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   689
    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   690
%}.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   691
    ^ super replaceFrom:start to:stop with:aCollection startingAt:replStart
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   692
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   693
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   694
     |f1 f2|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   695
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   696
     f1 := (1 to:5) asFloatArray.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   697
     f2 := #(10 9 8 7 6) asFloatArray.
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   698
     f1 replaceFrom:1 to:3 with:f2 startingAt:3       
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   699
    "
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   700
! !
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   701
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   702
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
   703
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   704
!FloatArray methodsFor:'queries'!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   705
5768
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   706
absMax
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   707
    "return the largest absolute value"
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   708
5816
ce15ce5294b4 Cleanup unused method vars
Stefan Vogel <sv@exept.de>
parents: 5773
diff changeset
   709
    |mm|
5768
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   710
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   711
    mm := self minMax.
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   712
    ^ (mm at:1) abs max:(mm at:2) abs
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   713
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   714
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   715
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   716
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   717
     f1 := (1 to:1000) asFloatArray.
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   718
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 absMax ] ]
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   719
    "
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   720
5768
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   721
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   722
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   723
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   724
     f1 := FloatArray withAll:#(1 2 3 4 5).
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   725
     f1 absMax             
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   726
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   727
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   728
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   729
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   730
     f1 := FloatArray withAll:#(5 4 3 2 1).
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   731
     f1 absMax             
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   732
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   733
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   734
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   735
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   736
     f1 := FloatArray withAll:#(5 -4 3 2 1).
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   737
     f1 absMax             
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   738
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   739
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   740
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   741
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   742
     f1 := FloatArray withAll:#(5 -5 3 2 1).
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   743
     f1 absMax             
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   744
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   745
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   746
     |f1|
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   747
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   748
     f1 := FloatArray withAll:#(5 -6 3 2 1).
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   749
     f1 absMax             
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   750
    "
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   751
!
b994c4024f4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5737
diff changeset
   752
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   753
defaultElement
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   754
    ^ ShortFloat zero
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   755
!
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   756
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   757
length
17736
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   758
    "Return the length of the receiver interpreted as vector 
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   759
     (that is the length of the vector from 0.0 @ 0.0 @ ... @ 0.0
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   760
      to the point in the n-dimensional space represented by the receiver)"
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   761
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   762
    ^ self squaredLength sqrt
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   763
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   764
    "
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   765
     #(10.0 10.0) asFloatArray length                 
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   766
     #(10.0 10.0 10.0) asFloatArray length                 
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   767
    "
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   768
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   769
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   770
max
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   771
    "return the largest element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   772
     redefined for speed"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   773
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   774
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   775
        int _sz = __floatArraySize(self);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   776
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   777
        if (_sz > 0) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   778
            float *_p = __FloatArrayInstPtr(self)->f_element;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   779
            float _max;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   780
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   781
            _max = _p[0];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   782
            if (_sz > 1) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   783
                int _i;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   784
                float _prev, _this;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   785
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   786
                /* how about inline-mmx-asm for this ... */
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   787
                _this = _p[1];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   788
                for (_i=2; _i<_sz; _i++) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   789
                    _prev = _this;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   790
                    _this = _p[_i];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   791
                    if (_prev > _max) _max = _prev;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   792
                }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   793
                if (_this > _max) _max = _this;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   794
            }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   795
            RETURN (__MKFLOAT(_max));
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   796
        }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   797
    }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   798
%}.
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   799
    ^ super max
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   800
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   801
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   802
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   803
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   804
     f1 := (1 to:1000) asFloatArray.
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   805
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 max ] ]
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   806
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   807
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   808
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   809
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   810
     f1 := FloatArray withAll:#(1 2 3 4 5).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   811
     f1 max             
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   812
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   813
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   814
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   815
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   816
     f1 := FloatArray withAll:#(5 4 3 2 1).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   817
     f1 max             
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   818
    "
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   819
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   820
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   821
min
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   822
    "return the largest element;
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   823
     redefined for speed"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   824
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   825
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   826
        int _sz = __floatArraySize(self);
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   827
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   828
        if (_sz > 0) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   829
            float *_p = __FloatArrayInstPtr(self)->f_element;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   830
            float _min;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   831
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   832
            _min = _p[0];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   833
            if (_sz > 1) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   834
                int _i;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   835
                float _prev, _this;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   836
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   837
                /* how about inline-mmx-asm for this ... */
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   838
                _this = _p[1];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   839
                for (_i=2; _i<_sz; _i++) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   840
                    _prev = _this;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   841
                    _this = _p[_i];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   842
                    if (_prev < _min) _min = _prev;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   843
                }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   844
                if (_this < _min) _min = _this;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   845
            }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   846
            RETURN (__MKFLOAT(_min));
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   847
        }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   848
    }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   849
%}.
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   850
    ^ super min
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   851
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   852
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   853
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   854
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   855
     f1 := (1 to:1000) asFloatArray.
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   856
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 min ] ]
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   857
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   858
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   859
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   860
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   861
     f1 := FloatArray withAll:#(1 2 3 4 5).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   862
     f1 min             
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   863
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   864
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   865
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   866
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   867
     f1 := FloatArray withAll:#(5 4 3 2 1).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   868
     f1 min             
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   869
    "
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   870
!
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   871
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   872
minMax
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   873
    "return a Tuple holding the smallest and largest element;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   874
     redefined for speed"
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   875
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   876
    |min max|
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   877
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   878
%{
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 7220
diff changeset
   879
    if (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0)) {
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   880
        int _sz = __floatArraySize(self);
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   881
        if (_sz > 0) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   882
            int _i;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   883
            float *_p = __FloatArrayInstPtr(self)->f_element;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   884
            float _min, _max;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   885
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   886
            _min = _max = _p[0];
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   887
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   888
            if (_sz > 1) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   889
                float _this = _p[1];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   890
                float _prev;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   891
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   892
                /* how about inline-mmx-asm for this ... */
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   893
                for (_i=2; _i<_sz; _i++) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   894
                    _prev = _this;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   895
                    _this = _p[_i];
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   896
                    if (_prev < _min) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   897
                        _min = _prev;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   898
                    } else if (_prev > _max) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   899
                        _max = _prev;
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   900
                    }
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   901
                }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   902
                if (_this < _min) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   903
                    _min = _this;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   904
                } else if (_this > _max) {
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   905
                    _max = _this;
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   906
                }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   907
            }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   908
            min = __MKFLOAT(_min);
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   909
            max = __MKFLOAT(_max);
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   910
            RETURN (__ARRAY_WITH2(min, max));
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   911
        }
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   912
    }
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   913
%}.
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   914
    ^ Array with:(super min) with:(super max)
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   915
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   916
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   917
     |f1|
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   918
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   919
     f1 := (1 to:1000) asFloatArray.
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   920
     Time millisecondsToRun:[ 1000 timesRepeat:[ f1 minMax ] ] 
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   921
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   922
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   923
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   924
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   925
     f1 := FloatArray withAll:#(1 2 3 4 5).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   926
     f1 minMax     
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   927
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   928
    "
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   929
     |f1|
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   930
7220
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   931
     f1 := FloatArray withAll:#(5 4 3 2 1).
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   932
     f1 minMax        
5225d13b2d57 inheritance & documentation
Claus Gittinger <cg@exept.de>
parents: 5816
diff changeset
   933
    "
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   934
!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   935
17736
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   936
numFloats
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   937
    ^ self size
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   938
!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   939
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   940
squaredLength
17736
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   941
    "Return the squared length of the receiver interpreted as vector"
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   942
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   943
    ^ self dot: self
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   944
! !
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   945
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   946
!FloatArray methodsFor:'vector arithmetic'!
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   947
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   948
dot: aFloatVector
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   949
    "Return the dot product of the receiver and the argument.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   950
     Fail if the argument is not of the same size as the receiver."
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   951
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   952
    | mySize result |
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   953
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   954
"/    <primitive:'primitiveDotProduct' module: 'FloatArrayPlugin'>
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   955
%{
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   956
    if (__isFloats(aFloatVector)
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   957
    && (__ClassInstPtr(__qClass(self))->c_ninstvars == __mkSmallInteger(0))
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   958
    && (__ClassInstPtr(__qClass(aFloatVector))->c_ninstvars == __mkSmallInteger(0))) {
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   959
        int __mySize = __floatArraySize(self);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   960
        int __otherSize = __floatArraySize(aFloatVector);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   961
        if (__mySize == __otherSize) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   962
            float *__p1 = __FloatArrayInstPtr(self)->f_element;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   963
            float *__p2 = __FloatArrayInstPtr(aFloatVector)->f_element;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   964
            float __result = 0.0;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   965
            int __i;
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   966
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   967
            /* how about inline-mmx-asm for this ... */
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   968
            for (__i=0; __i<__mySize; __i++) {
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   969
                __result = __result + (__p1[__i] * __p2[__i]);
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   970
            }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   971
            RETURN (__MKFLOAT(__result));
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   972
        }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   973
    }
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   974
%}.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   975
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   976
    mySize := self size.
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   977
    mySize = aFloatVector size ifFalse:[^self error:'Must be of equal size'].
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   978
    result := 0.0.
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   979
    1 to: mySize do:[:i|
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   980
        result := result + ((self at: i) * (aFloatVector at: i)).
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   981
    ].
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   982
    ^result
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   983
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   984
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   985
     |v|
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   986
11212
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   987
     v := #(2.0 2.0 1.0) asFloatArray.
8a6590cc1f4a comments
Claus Gittinger <cg@exept.de>
parents: 10580
diff changeset
   988
     v dot:v.    
10561
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   989
    "
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   990
6987bd25c09d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
   991
    "Created: / 29-05-2007 / 13:13:39 / cg"
5737
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   992
! !
1e4a1b0c294e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
   993
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 603
diff changeset
   994
!FloatArray class methodsFor:'documentation'!
603
72bdeb24ccba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   995
72bdeb24ccba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   996
version
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   997
    ^ '$Id: FloatArray.st 10660 2011-07-18 15:22:09Z vranyj1 $'
17736
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   998
!
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   999
26cfea63471d Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1000
version_CVS
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  1001
    ^ '§Header: /cvs/stx/stx/libbasic/FloatArray.st,v 1.26 2009/12/01 22:11:19 cg Exp §'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
  1002
! !