Skip to content

Commit 4f1f2dd

Browse files
committed
feat: add array/little-endian-float32
1 parent 0e9ba46 commit 4f1f2dd

File tree

14 files changed

+1932
-0
lines changed

14 files changed

+1932
-0
lines changed

lib/node_modules/@stdlib/array/little-endian-float32/README.md

Lines changed: 438 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 bench = require( '@stdlib/bench' );
24+
var Float32Array = require( '@stdlib/array/float32' );
25+
var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' );
26+
var pkg = require( './../package.json' ).name;
27+
var Float32ArrayLE = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var opts = {
33+
'skip': ( ITERATOR_SYMBOL === null )
34+
};
35+
36+
37+
// MAIN //
38+
39+
bench( pkg+'::typed_array:from', function benchmark( b ) {
40+
var buf;
41+
var arr;
42+
var i;
43+
44+
buf = new Float32Array( 0 );
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
arr = Float32ArrayLE.from( buf );
49+
if ( arr.length !== 0 ) {
50+
b.fail( 'should have length 0' );
51+
}
52+
}
53+
b.toc();
54+
if ( !(arr instanceof Float32ArrayLE) ) {
55+
b.fail( 'should return an instance' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});
60+
61+
bench( pkg+'::typed_array:from:len=5', function benchmark( b ) {
62+
var buf;
63+
var arr;
64+
var i;
65+
66+
buf = new Float32Array( 5 );
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
arr = Float32ArrayLE.from( buf );
71+
if ( arr.length !== 5 ) {
72+
b.fail( 'should have length 5' );
73+
}
74+
}
75+
b.toc();
76+
if ( !(arr instanceof Float32ArrayLE) ) {
77+
b.fail( 'should return an instance' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
});
82+
83+
bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) {
84+
var buf;
85+
var arr;
86+
var i;
87+
88+
buf = new Float32Array( 5 );
89+
90+
b.tic();
91+
for ( i = 0; i < b.iterations; i++ ) {
92+
arr = Float32ArrayLE.from( buf, clbk );
93+
if ( arr.length !== 5 ) {
94+
b.fail( 'should have length 5' );
95+
}
96+
}
97+
b.toc();
98+
if ( !(arr instanceof Float32ArrayLE) ) {
99+
b.fail( 'should return an instance' );
100+
}
101+
b.pass( 'benchmark finished' );
102+
b.end();
103+
104+
function clbk( v ) {
105+
return v * 2.0;
106+
}
107+
});
108+
109+
bench( pkg+'::array:from', function benchmark( b ) {
110+
var buf;
111+
var arr;
112+
var i;
113+
114+
buf = [];
115+
116+
b.tic();
117+
for ( i = 0; i < b.iterations; i++ ) {
118+
arr = Float32ArrayLE.from( buf );
119+
if ( arr.length !== 0 ) {
120+
b.fail( 'should have length 0' );
121+
}
122+
}
123+
b.toc();
124+
if ( !(arr instanceof Float32ArrayLE) ) {
125+
b.fail( 'should return an instance' );
126+
}
127+
b.pass( 'benchmark finished' );
128+
b.end();
129+
});
130+
131+
bench( pkg+'::array:from:len=5', function benchmark( b ) {
132+
var buf;
133+
var arr;
134+
var i;
135+
136+
buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ];
137+
138+
b.tic();
139+
for ( i = 0; i < b.iterations; i++ ) {
140+
arr = Float32ArrayLE.from( buf );
141+
if ( arr.length !== 5 ) {
142+
b.fail( 'should have length 5' );
143+
}
144+
}
145+
b.toc();
146+
if ( !(arr instanceof Float32ArrayLE) ) {
147+
b.fail( 'should return an instance' );
148+
}
149+
b.pass( 'benchmark finished' );
150+
b.end();
151+
});
152+
153+
bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) {
154+
var buf;
155+
var arr;
156+
var i;
157+
158+
buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ];
159+
160+
b.tic();
161+
for ( i = 0; i < b.iterations; i++ ) {
162+
arr = Float32ArrayLE.from( buf, clbk );
163+
if ( arr.length !== 5 ) {
164+
b.fail( 'should have length 5' );
165+
}
166+
}
167+
b.toc();
168+
if ( !(arr instanceof Float32ArrayLE) ) {
169+
b.fail( 'should return an instance' );
170+
}
171+
b.pass( 'benchmark finished' );
172+
b.end();
173+
174+
function clbk( v ) {
175+
return v * 2.0;
176+
}
177+
});
178+
179+
bench( pkg+'::iterable:from', opts, function benchmark( b ) {
180+
var arr;
181+
var i;
182+
183+
b.tic();
184+
for ( i = 0; i < b.iterations; i++ ) {
185+
arr = Float32ArrayLE.from( createIterable() );
186+
if ( arr.length !== 0 ) {
187+
b.fail( 'should have length 0' );
188+
}
189+
}
190+
b.toc();
191+
if ( !(arr instanceof Float32ArrayLE) ) {
192+
b.fail( 'should return an instance' );
193+
}
194+
b.pass( 'benchmark finished' );
195+
b.end();
196+
197+
function createIterable() {
198+
var out = {};
199+
out[ ITERATOR_SYMBOL ] = iterator;
200+
return out;
201+
202+
function iterator() {
203+
return {
204+
'next': next
205+
};
206+
}
207+
208+
function next() {
209+
return {
210+
'done': true
211+
};
212+
}
213+
}
214+
});
215+
216+
bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) {
217+
var arr;
218+
var i;
219+
220+
b.tic();
221+
for ( i = 0; i < b.iterations; i++ ) {
222+
arr = Float32ArrayLE.from( createIterable() );
223+
if ( arr.length !== 5 ) {
224+
b.fail( 'should have length 5' );
225+
}
226+
}
227+
b.toc();
228+
if ( !(arr instanceof Float32ArrayLE) ) {
229+
b.fail( 'should return an instance' );
230+
}
231+
b.pass( 'benchmark finished' );
232+
b.end();
233+
234+
function createIterable() {
235+
var out = {};
236+
out[ ITERATOR_SYMBOL ] = iterator;
237+
return out;
238+
239+
function iterator() {
240+
var it = {
241+
'next': next,
242+
'i': 0,
243+
'N': 5
244+
};
245+
return it;
246+
247+
function next() {
248+
it.i += 1;
249+
if ( it.i <= it.N ) {
250+
return {
251+
'value': 1.0
252+
};
253+
}
254+
return {
255+
'done': true
256+
};
257+
}
258+
}
259+
}
260+
});
261+
262+
bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) {
263+
var arr;
264+
var i;
265+
266+
b.tic();
267+
for ( i = 0; i < b.iterations; i++ ) {
268+
arr = Float32ArrayLE.from( createIterable(), clbk );
269+
if ( arr.length !== 5 ) {
270+
b.fail( 'should have length 5' );
271+
}
272+
}
273+
b.toc();
274+
if ( !(arr instanceof Float32ArrayLE) ) {
275+
b.fail( 'should return an instance' );
276+
}
277+
b.pass( 'benchmark finished' );
278+
b.end();
279+
280+
function createIterable() {
281+
var out = {};
282+
out[ ITERATOR_SYMBOL ] = iterator;
283+
return out;
284+
285+
function iterator() {
286+
var it = {
287+
'next': next,
288+
'i': 0,
289+
'N': 5
290+
};
291+
return it;
292+
293+
function next() {
294+
it.i += 1;
295+
if ( it.i <= it.N ) {
296+
return {
297+
'value': 1.0
298+
};
299+
}
300+
return {
301+
'done': true
302+
};
303+
}
304+
}
305+
}
306+
307+
function clbk( v ) {
308+
return v * 2.0;
309+
}
310+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 bench = require( '@stdlib/bench' );
24+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var Float32ArrayLE = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':get', function benchmark( b ) {
32+
var arr;
33+
var N;
34+
var v;
35+
var i;
36+
37+
arr = [];
38+
for ( i = 0; i < 10; i++ ) {
39+
arr.push( i );
40+
}
41+
arr = new Float32ArrayLE( arr );
42+
N = arr.length;
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
v = arr.get( i%N );
47+
if ( typeof v !== 'number' ) {
48+
b.fail( 'should return a number' );
49+
}
50+
}
51+
b.toc();
52+
if ( !isNumber( v ) ) {
53+
b.fail( 'should return a number' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});

0 commit comments

Comments
 (0)