Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/node_modules/@stdlib/ndarray/data-buffer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ x = zeros( [ 2, 2 ], opts );
buf = data( x );
// returns <Float32Array>

// Create a 'float16' array...
opts = {
'dtype': 'float16'
};
x = zeros( [ 2, 2 ], opts );
// returns <ndarray>

buf = data( x );
// returns <Float16Array>

// Create a 'complex128' array...
opts = {
'dtype': 'complex128'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/// <reference types="@stdlib/types"/>

import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray';
import { typedndarray, genericndarray, float64ndarray, float32ndarray, float16ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray';

/**
* Returns the underlying data buffer of a provided ndarray.
Expand Down Expand Up @@ -58,6 +58,24 @@ declare function data( x: float64ndarray ): float64ndarray[ 'data' ];
*/
declare function data( x: float32ndarray ): float32ndarray[ 'data' ];

/**
* Returns the underlying data buffer of a provided ndarray.
*
* @param x - input ndarray
* @returns underlying data buffer
*
* @example
* var zeros = require( '@stdlib/ndarray/zeros' );
*
* var x = zeros( [ 3, 3, 3 ], {
* 'dtype': 'float16'
* });
*
* var out = data( x );
* // returns <Float16Array>
*/
declare function data( x: float16ndarray ): float16ndarray[ 'data' ];

/**
* Returns the underlying data buffer of a provided ndarray.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import data = require( './index' );
{
data( zeros( [ 3, 2, 1 ], { 'dtype': 'float64' } ) ); // $ExpectType Float64Array
data( zeros( [ 3, 2, 1 ], { 'dtype': 'float32' } ) ); // $ExpectType Float32Array
data( zeros( [ 3, 2, 1 ], { 'dtype': 'float16' } ) ); // $ExpectType Float16ArrayFallback
data( zeros( [ 3, 2, 1 ], { 'dtype': 'int32' } ) ); // $ExpectType Int32Array
data( zeros( [ 3, 2, 1 ], { 'dtype': 'int16' } ) ); // $ExpectType Int16Array
data( zeros( [ 3, 2, 1 ], { 'dtype': 'int8' } ) ); // $ExpectType Int8Array
Expand Down
12 changes: 12 additions & 0 deletions lib/node_modules/@stdlib/ndarray/data-buffer/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ buf = data( x );

console.log( buf );

// Create a 'float16' array...
opts = {
'dtype': 'float16'
};
x = zeros( [ 2, 2 ], opts );
// returns <ndarray>

buf = data( x );
// returns <Float16Array>

console.log( buf );

// Create a 'complex128' array...
opts = {
'dtype': 'complex128'
Expand Down
12 changes: 10 additions & 2 deletions lib/node_modules/@stdlib/ndarray/data-buffer/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ tape( 'the function returns the underlying data buffer of a provided ndarray', f
zeros( [ 3, 3, 3 ], {
'dtype': 'float32'
}),
zeros( [ 2, 2 ], {
'dtype': 'float16'
}),
zeros( [ 1, 1 ], {
'dtype': 'int32'
}),
Expand All @@ -101,7 +104,8 @@ tape( 'the function returns the underlying data buffer of a provided ndarray', f
values[ 2 ].data,
values[ 3 ].data,
values[ 4 ].data,
values[ 5 ].data
values[ 5 ].data,
values[ 6 ].data
];

for ( i = 0; i < values.length; i++ ) {
Expand All @@ -124,6 +128,9 @@ tape( 'the function accepts minimal ndarray-like objects (data)', function test(
{
'data': buffer( 'float32', 10 )
},
{
'data': buffer( 'float16', 10 )
},
{
'data': buffer( 'int32', 10 )
},
Expand All @@ -144,7 +151,8 @@ tape( 'the function accepts minimal ndarray-like objects (data)', function test(
values[ 2 ].data,
values[ 3 ].data,
values[ 4 ].data,
values[ 5 ].data
values[ 5 ].data,
values[ 6 ].data
];

for ( i = 0; i < values.length; i++ ) {
Expand Down
Loading