You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -63,25 +63,38 @@ var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) );
63
63
var y =array( newFloat32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) );
64
64
65
65
var z =sdot( x, y );
66
+
// returns <ndarray>
67
+
68
+
var v =z.get();
66
69
// returns -5.0
67
70
```
68
71
69
72
The function has the following parameters:
70
73
71
-
-**x**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`.
72
-
-**y**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`.
74
+
-**x**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `y`.
75
+
-**y**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`.
76
+
-**dim**: dimension for which to compute the dot product. Must be a negative integer. Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. Default: `-1`.
73
77
74
-
If provided empty vectors, the function returns `0.0`.
78
+
If provided at least one input [`ndarray`][@stdlib/ndarray/ctor] having more than one dimension, the input [`ndarrays`][@stdlib/ndarray/ctor] are [broadcasted][@stdlib/ndarray/base/broadcast-shapes] to a common shape. For multi-dimensional input [`ndarrays`][@stdlib/ndarray/ctor], the function performs batched computation, such that the function computes the dot product for each pair of vectors in `x` and `y` according to the specified dimension index.
var x =array( newFloat32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 3.0 ] ), opts );
88
+
var y =array( newFloat32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 2.0 ] ), opts );
82
89
83
90
var z =sdot( x, y );
84
-
// returns 0.0
91
+
// returns <ndarray>
92
+
93
+
var v1 =z.get( 0 );
94
+
// returns 23.0
95
+
96
+
var v2 =z.get( 1 );
97
+
// returns -22.0
85
98
```
86
99
87
100
</section>
@@ -92,6 +105,11 @@ var z = sdot( x, y );
92
105
93
106
## Notes
94
107
108
+
- The size of the contracted dimension must be the same for both input [`ndarrays`][@stdlib/ndarray/ctor].
109
+
- The function resolves the dimension index for which to compute the dot product **before** broadcasting.
110
+
- Negative indices are resolved relative to the last [`ndarray`][@stdlib/ndarray/ctor] dimension, with the last dimension corresponding to `-1`.
111
+
- The output [`ndarray`][@stdlib/ndarray/ctor] has the same data type as the input [`ndarrays`][@stdlib/ndarray/ctor] and has a shape which is determined by broadcasting and excludes the contracted dimension.
112
+
- If provided empty vectors, the dot product is `0`.
95
113
-`sdot()` provides a higher-level interface to the [BLAS][blas] level 1 function [`sdot`][@stdlib/blas/base/sdot].
96
114
97
115
</section>
@@ -105,27 +123,27 @@ var z = sdot( x, y );
105
123
<!-- eslint no-undef: "error" -->
106
124
107
125
```javascript
108
-
var discreteUniform =require( '@stdlib/random/base/discrete-uniform' );
var x =array( discreteUniform( 10, 0, 100, opts ), {
136
+
'shape': [ 5, 2 ]
137
+
});
138
+
console.log( ndarray2array( x ) );
118
139
119
-
var i;
120
-
for ( i =0; i <x.length; i++ ) {
121
-
x.set( i, rand1() );
122
-
y.set( i, rand2() );
123
-
}
124
-
console.log( x.toString() );
125
-
console.log( y.toString() );
140
+
var y =array( discreteUniform( 10, 0, 10, opts ), {
141
+
'shape':x.shape
142
+
});
143
+
console.log( ndarray2array( y ) );
126
144
127
-
var z =sdot( x, y );
128
-
console.log( z );
145
+
var z =sdot( x, y, -1 );
146
+
console.log( ndarray2array( z ) );
129
147
```
130
148
131
149
</section>
@@ -136,14 +154,6 @@ console.log( z );
136
154
137
155
<sectionclass="related">
138
156
139
-
* * *
140
-
141
-
## See Also
142
-
143
-
- <spanclass="package-name">[`@stdlib/blas/base/sdot`][@stdlib/blas/base/sdot]</span><spanclass="delimiter">: </span><spanclass="description">calculate the dot product of two single-precision floating-point vectors.</span>
144
-
- <spanclass="package-name">[`@stdlib/blas/ddot`][@stdlib/blas/ddot]</span><spanclass="delimiter">: </span><spanclass="description">calculate the dot product of two double-precision floating-point vectors.</span>
145
-
- <spanclass="package-name">[`@stdlib/blas/gdot`][@stdlib/blas/gdot]</span><spanclass="delimiter">: </span><spanclass="description">calculate the dot product of two vectors.</span>
0 commit comments