@stdlib/math-special-abs 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CITATION.cff +30 -0
- package/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +36 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/lib/index.js +7 -2
- package/lib/main.js +5 -2
- package/lib/native.js +5 -2
- package/lib/table.native.js +7 -4
- package/lib/types.js +103 -0
- package/lib/types.json +1 -65
- package/package.json +37 -37
- package/src/addon.c +43 -7
- package/binding.gyp +0 -170
- package/docs/repl.txt +0 -108
- package/docs/types/test.ts +0 -184
- package/lib/props.js +0 -68
package/docs/types/test.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/// <reference types="@stdlib/types"/>
|
|
20
|
-
|
|
21
|
-
import { ndarray } from '@stdlib/types/ndarray';
|
|
22
|
-
import abs = require( './index' );
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Returns a mock ndarray object.
|
|
26
|
-
*
|
|
27
|
-
* @returns ndarray
|
|
28
|
-
*/
|
|
29
|
-
function array(): ndarray {
|
|
30
|
-
const buf = [ 1, 2, 3, 4 ];
|
|
31
|
-
const x: ndarray = {
|
|
32
|
-
'byteLength': null,
|
|
33
|
-
'BYTES_PER_ELEMENT': null,
|
|
34
|
-
'data': buf,
|
|
35
|
-
'dtype': 'generic',
|
|
36
|
-
'flags': {
|
|
37
|
-
'ROW_MAJOR_CONTIGUOUS': true,
|
|
38
|
-
'COLUMN_MAJOR_CONTIGUOUS': false
|
|
39
|
-
},
|
|
40
|
-
'length': 4,
|
|
41
|
-
'ndims': 1,
|
|
42
|
-
'offset': 0,
|
|
43
|
-
'order': 'row-major',
|
|
44
|
-
'shape': [ 4 ],
|
|
45
|
-
'strides': [ 1 ],
|
|
46
|
-
'get': ( i: number ): number => {
|
|
47
|
-
return buf[ i ];
|
|
48
|
-
},
|
|
49
|
-
'set': ( i: number, v: number ): ndarray => {
|
|
50
|
-
buf[ i ] = v;
|
|
51
|
-
return x;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return x;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// TESTS //
|
|
59
|
-
|
|
60
|
-
// The function returns a number if provided a number...
|
|
61
|
-
{
|
|
62
|
-
abs( 8 ); // $ExpectType number
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// The function returns an array-like object if provided an array-like object...
|
|
66
|
-
{
|
|
67
|
-
const x = new Float64Array( 10 );
|
|
68
|
-
|
|
69
|
-
abs( x ); // $ExpectType ArrayLike<number>
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// The function returns an ndarray if provided an ndarray...
|
|
73
|
-
{
|
|
74
|
-
const x = array();
|
|
75
|
-
|
|
76
|
-
abs( x ); // $ExpectType ndarray
|
|
77
|
-
abs( x, {} ); // $ExpectType ndarray
|
|
78
|
-
abs( x, { 'order': 'row-major' } ); // $ExpectType ndarray
|
|
79
|
-
abs( x, { 'dtype': 'float64' } ); // $ExpectType ndarray
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// The compiler throws an error if the function is provided a first argument which is neither an ndarray, array-like object, nor number...
|
|
83
|
-
{
|
|
84
|
-
abs( '5' ); // $ExpectError
|
|
85
|
-
abs( true ); // $ExpectError
|
|
86
|
-
abs( false ); // $ExpectError
|
|
87
|
-
abs( null ); // $ExpectError
|
|
88
|
-
abs( undefined ); // $ExpectError
|
|
89
|
-
abs( {} ); // $ExpectError
|
|
90
|
-
abs( [ '5' ] ); // $ExpectError
|
|
91
|
-
abs( ( x: number ): number => x ); // $ExpectError
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// The compiler throws an error if the function is provided a second argument which is not a valid options object...
|
|
95
|
-
{
|
|
96
|
-
const x = array();
|
|
97
|
-
|
|
98
|
-
abs( x, '5' ); // $ExpectError
|
|
99
|
-
abs( x, true ); // $ExpectError
|
|
100
|
-
abs( x, false ); // $ExpectError
|
|
101
|
-
abs( x, [ '5' ] ); // $ExpectError
|
|
102
|
-
abs( x, ( x: number ): number => x ); // $ExpectError
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// The compiler throws an error if the function is provided an invalid `order` option...
|
|
106
|
-
{
|
|
107
|
-
const x = array();
|
|
108
|
-
abs( x, { 'order': '5' } ); // $ExpectError
|
|
109
|
-
abs( x, { 'order': true } ); // $ExpectError
|
|
110
|
-
abs( x, { 'order': false } ); // $ExpectError
|
|
111
|
-
abs( x, { 'order': null } ); // $ExpectError
|
|
112
|
-
abs( x, { 'order': {} } ); // $ExpectError
|
|
113
|
-
abs( x, { 'order': [ '5' ] } ); // $ExpectError
|
|
114
|
-
abs( x, { 'order': ( x: number ): number => x } ); // $ExpectError
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// The compiler throws an error if the function is provided an invalid `dtype` option...
|
|
118
|
-
{
|
|
119
|
-
const x = array();
|
|
120
|
-
abs( x, { 'dtype': '5' } ); // $ExpectError
|
|
121
|
-
abs( x, { 'dtype': true } ); // $ExpectError
|
|
122
|
-
abs( x, { 'dtype': false } ); // $ExpectError
|
|
123
|
-
abs( x, { 'dtype': null } ); // $ExpectError
|
|
124
|
-
abs( x, { 'dtype': {} } ); // $ExpectError
|
|
125
|
-
abs( x, { 'dtype': [ '5' ] } ); // $ExpectError
|
|
126
|
-
abs( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// The compiler throws an error if the function is provided insufficient arguments...
|
|
130
|
-
{
|
|
131
|
-
abs(); // $ExpectError
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Attached to the main function is an `assign` method which returns an array-like object if provided an array-like object...
|
|
135
|
-
{
|
|
136
|
-
const x = new Float64Array( 10 );
|
|
137
|
-
const y = new Float64Array( 10 );
|
|
138
|
-
|
|
139
|
-
abs.assign( x, y ); // $ExpectType ArrayLike<number>
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Attached to the main function is an `assign` method which returns an ndarray if provided an ndarray...
|
|
143
|
-
{
|
|
144
|
-
const x = array();
|
|
145
|
-
const y = array();
|
|
146
|
-
|
|
147
|
-
abs.assign( x, y ); // $ExpectType ndarray
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// The compiler throws an error if the `assign` method is provided a first argument which is neither an ndarray nor array-like object...
|
|
151
|
-
{
|
|
152
|
-
const y = array();
|
|
153
|
-
|
|
154
|
-
abs.assign( '5', y ); // $ExpectError
|
|
155
|
-
abs.assign( true, y ); // $ExpectError
|
|
156
|
-
abs.assign( false, y ); // $ExpectError
|
|
157
|
-
abs.assign( null, y ); // $ExpectError
|
|
158
|
-
abs.assign( undefined, y ); // $ExpectError
|
|
159
|
-
abs.assign( {}, y ); // $ExpectError
|
|
160
|
-
abs.assign( ( x: number ): number => x, y ); // $ExpectError
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// The compiler throws an error if the `assign` method is provided a second argument which is neither an ndarray nor array-like object...
|
|
164
|
-
{
|
|
165
|
-
const x = array();
|
|
166
|
-
|
|
167
|
-
abs.assign( x, '5' ); // $ExpectError
|
|
168
|
-
abs.assign( x, true ); // $ExpectError
|
|
169
|
-
abs.assign( x, false ); // $ExpectError
|
|
170
|
-
abs.assign( x, null ); // $ExpectError
|
|
171
|
-
abs.assign( x, undefined ); // $ExpectError
|
|
172
|
-
abs.assign( x, {} ); // $ExpectError
|
|
173
|
-
abs.assign( x, ( x: number ): number => x ); // $ExpectError
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
|
|
177
|
-
{
|
|
178
|
-
const x = array();
|
|
179
|
-
const y = array();
|
|
180
|
-
|
|
181
|
-
abs.assign(); // $ExpectError
|
|
182
|
-
abs.assign( x ); // $ExpectError
|
|
183
|
-
abs.assign( x, y, y ); // $ExpectError
|
|
184
|
-
}
|
package/lib/props.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
// MODULES //
|
|
22
|
-
|
|
23
|
-
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
24
|
-
var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );
|
|
25
|
-
var dtypes2signatures = require( '@stdlib/ndarray-base-dtypes2signatures' );
|
|
26
|
-
var dtypes = require( './types.json' );
|
|
27
|
-
var meta = require( './meta.json' );
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// FUNCTIONS //
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns a list of array interface type signatures.
|
|
34
|
-
*
|
|
35
|
-
* @private
|
|
36
|
-
* @returns {StringArray} list of signatures
|
|
37
|
-
*/
|
|
38
|
-
function types() {
|
|
39
|
-
return dtypes2signatures( dtypes, meta.nin, meta.nout );
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// MAIN //
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Defines properties which expose function meta data.
|
|
47
|
-
*
|
|
48
|
-
* @private
|
|
49
|
-
* @param {Function} fcn - function on which to define properties
|
|
50
|
-
*/
|
|
51
|
-
function setProps( fcn ) {
|
|
52
|
-
// Define the number of input arguments:
|
|
53
|
-
setReadOnly( fcn, 'nargs', meta.nargs );
|
|
54
|
-
|
|
55
|
-
// Define the number of input arrays:
|
|
56
|
-
setReadOnly( fcn, 'nin', meta.nin );
|
|
57
|
-
|
|
58
|
-
// Define the number of output arrays:
|
|
59
|
-
setReadOnly( fcn, 'nout', meta.nout );
|
|
60
|
-
|
|
61
|
-
// Define a read-only accessor for listing a function's supported array data types:
|
|
62
|
-
setReadOnlyAccessor( fcn, 'types', types );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// EXPORTS //
|
|
67
|
-
|
|
68
|
-
module.exports = setProps;
|