README.md (3731B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # ddot 22 23 > Calculate the dot product of two double-precision floating-point vectors. 24 25 <section class="intro"> 26 27 The [dot product][dot-product] (or scalar product) is defined as 28 29 <!-- <equation class="equation" label="eq:dot_product" align="center" raw="\mathbf{x}\cdot\mathbf{y} = \sum_{i=0}^{N-1} x_i y_i = x_0 y_0 + x_1 y_1 + \ldots + x_{N-1} y_{N-1}" alt="Dot product definition."> --> 30 31 <div class="equation" align="center" data-raw-text="\mathbf{x}\cdot\mathbf{y} = \sum_{i=0}^{N-1} x_i y_i = x_0 y_0 + x_1 y_1 + \ldots + x_{N-1} y_{N-1}" data-equation="eq:dot_product"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d0afc603cdda35b11d5bd1633dd4dddb0d59e117/lib/node_modules/@stdlib/blas/ddot/docs/img/equation_dot_product.svg" alt="Dot product definition."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 </section> 39 40 <!-- /.intro --> 41 42 <section class="usage"> 43 44 ## Usage 45 46 ```javascript 47 var ddot = require( '@stdlib/blas/ddot' ); 48 ``` 49 50 #### ddot( x, y ) 51 52 Calculates the dot product of two double-precision floating-point vectors `x` and `y`. 53 54 ```javascript 55 var Float64Array = require( '@stdlib/array/float64' ); 56 var array = require( '@stdlib/ndarray/array' ); 57 58 var x = array( new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) ); 59 var y = array( new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) ); 60 61 var z = ddot( x, y ); 62 // returns -5.0 63 ``` 64 65 The function has the following parameters: 66 67 - **x**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float64`. 68 - **y**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float64`. 69 70 If provided empty vectors, the function returns `0.0`. 71 72 ```javascript 73 var Float64Array = require( '@stdlib/array/float64' ); 74 var array = require( '@stdlib/ndarray/array' ); 75 76 var x = array( new Float64Array() ); 77 var y = array( new Float64Array() ); 78 79 var z = ddot( x, y ); 80 // returns 0.0 81 ``` 82 83 </section> 84 85 <!-- /.usage --> 86 87 <section class="notes"> 88 89 ## Notes 90 91 - `ddot()` provides a higher-level interface to the [BLAS][blas] level 1 function [`ddot`][@stdlib/blas/base/ddot]. 92 93 </section> 94 95 <!-- /.notes --> 96 97 <section class="examples"> 98 99 ## Examples 100 101 <!-- eslint no-undef: "error" --> 102 103 ```javascript 104 var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); 105 var Float64Array = require( '@stdlib/array/float64' ); 106 var array = require( '@stdlib/ndarray/array' ); 107 var ddot = require( '@stdlib/blas/ddot' ); 108 109 var x = array( new Float64Array( 10 ) ); 110 var y = array( new Float64Array( 10 ) ); 111 112 var rand1 = discreteUniform.factory( 0, 100 ); 113 var rand2 = discreteUniform.factory( 0, 10 ); 114 115 var i; 116 for ( i = 0; i < x.length; i++ ) { 117 x.set( i, rand1() ); 118 y.set( i, rand2() ); 119 } 120 console.log( x.toString() ); 121 console.log( y.toString() ); 122 123 var z = ddot( x, y ); 124 console.log( z ); 125 ``` 126 127 </section> 128 129 <!-- /.examples --> 130 131 <section class="links"> 132 133 [dot-product]: https://en.wikipedia.org/wiki/Dot_product 134 135 [blas]: http://www.netlib.org/blas 136 137 [@stdlib/blas/base/ddot]: https://www.npmjs.com/package/@stdlib/blas/tree/main/base/ddot 138 139 [@stdlib/ndarray/array]: https://www.npmjs.com/package/@stdlib/ndarray-array 140 141 </section> 142 143 <!-- /.links -->