|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2021 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 | +# Callbacks |
| 22 | + |
| 23 | +> Assign callbacks to binary interfaces according to type [promotion rules][@stdlib/ndarray/promotion-rules]. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var callbacks = require( '@stdlib/strided/base/binary-signature-callbacks' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### callbacks( table, signatures ) |
| 44 | + |
| 45 | +Assigns callbacks to binary interfaces according to type type [promotion rules][@stdlib/ndarray/promotion-rules]. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var signatures = require( '@stdlib/strided/base/binary-dtype-signatures' ); |
| 49 | +var add = require( '@stdlib/math/base/ops/add' ); |
| 50 | +var cadd = require( '@stdlib/math/base/ops/cadd' ); |
| 51 | +var caddf = require( '@stdlib/math/base/ops/caddf' ); |
| 52 | + |
| 53 | +var dtypes = [ |
| 54 | + 'float64', |
| 55 | + 'float32', |
| 56 | + 'int32', |
| 57 | + 'uint8' |
| 58 | +]; |
| 59 | + |
| 60 | +var sigs = signatures( dtypes, dtypes, dtypes ); |
| 61 | +// returns [...] |
| 62 | + |
| 63 | +var table = { |
| 64 | + 'default': add, |
| 65 | + 'complex64': caddf, |
| 66 | + 'complex128': cadd |
| 67 | +}; |
| 68 | + |
| 69 | +var list = callbacks( table, sigs ); |
| 70 | +// returns [...] |
| 71 | +``` |
| 72 | + |
| 73 | +The function accepts the following arguments: |
| 74 | + |
| 75 | +- **table**: callback table. |
| 76 | +- **signatures**: options. |
| 77 | + |
| 78 | +A callback `table` should have the following properties: |
| 79 | + |
| 80 | +- **default**: default callback. |
| 81 | +- **complex64**: callback for single-precision complex floating-point numbers. |
| 82 | +- **complex128**: callback for double-precision complex floating-point numbers. |
| 83 | + |
| 84 | +</section> |
| 85 | + |
| 86 | +<!-- /.usage --> |
| 87 | + |
| 88 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 89 | + |
| 90 | +<section class="notes"> |
| 91 | + |
| 92 | +## Notes |
| 93 | + |
| 94 | +- The function assumes that the provided signature array has the following properties: |
| 95 | + |
| 96 | + - a strided array having a stride length of `3` (i.e., every `3` elements define a binary interface signature). |
| 97 | + - for each signature (i.e., set of three consecutive non-overlapping strided array elements), the first two elements are the input data types and the third element is the return data type. |
| 98 | + - all signatures follow type [promotion rules][@stdlib/ndarray/promotion-rules]. |
| 99 | + |
| 100 | +</section> |
| 101 | + |
| 102 | +<!-- /.notes --> |
| 103 | + |
| 104 | +<!-- Package usage examples. --> |
| 105 | + |
| 106 | +<section class="examples"> |
| 107 | + |
| 108 | +## Examples |
| 109 | + |
| 110 | +<!-- eslint no-undef: "error" --> |
| 111 | + |
| 112 | +```javascript |
| 113 | +var dtypes = require( '@stdlib/strided/dtypes' ); |
| 114 | +var signatures = require( '@stdlib/strided/base/binary-dtype-signatures' ); |
| 115 | +var add = require( '@stdlib/math/base/ops/add' ); |
| 116 | +var cadd = require( '@stdlib/math/base/ops/cadd' ); |
| 117 | +var caddf = require( '@stdlib/math/base/ops/caddf' ); |
| 118 | +var callbacks = require( '@stdlib/strided/base/binary-signature-callbacks' ); |
| 119 | + |
| 120 | +// Get the list of supported strided array data types: |
| 121 | +var dt = dtypes(); |
| 122 | + |
| 123 | +// Generate binary interface signatures: |
| 124 | +var sigs = signatures( dt, dt, dt ); |
| 125 | + |
| 126 | +// Define a callback table: |
| 127 | +var table = { |
| 128 | + 'default': add, |
| 129 | + 'complex64': caddf, |
| 130 | + 'complex128': cadd |
| 131 | +}; |
| 132 | + |
| 133 | +// Generate a list of callbacks according to type promotion rules: |
| 134 | +var clbks = callbacks( table, sigs ); |
| 135 | +// returns [...] |
| 136 | +``` |
| 137 | + |
| 138 | +</section> |
| 139 | + |
| 140 | +<!-- /.examples --> |
| 141 | + |
| 142 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 143 | + |
| 144 | +<section class="references"> |
| 145 | + |
| 146 | +</section> |
| 147 | + |
| 148 | +<!-- /.references --> |
| 149 | + |
| 150 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 151 | + |
| 152 | +<section class="related"> |
| 153 | + |
| 154 | +</section> |
| 155 | + |
| 156 | +<!-- /.related --> |
| 157 | + |
| 158 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 159 | + |
| 160 | +<section class="links"> |
| 161 | + |
| 162 | +[@stdlib/ndarray/promotion-rules]: https://github.com/stdlib-js/stdlib |
| 163 | + |
| 164 | +</section> |
| 165 | + |
| 166 | +<!-- /.links --> |
0 commit comments