Skip to content

Commit

Permalink
test: register ndarray and transpose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranavchiku committed Aug 3, 2024
1 parent 75bbf46 commit 57ce29a
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 0 deletions.
103 changes: 103 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/transpose/test/test.ndarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var Float64Array = require( '@stdlib/array/float64' );
var transpose = require( './../lib/ndarray.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof transpose, 'function', 'main export is a function' );
t.end();
});

tape( 'the function has an arity of 10', function test( t ) {
t.strictEqual( transpose.length, 10, 'returns expected value' );
t.end();
});

tape( 'the function supports accessing elements from non contiguous arrangement of rows and columns with defined offset', function test( t ) {
var out;
var A;

/* eslint-disable array-element-newline, no-multi-spaces */

A = new Float64Array([
999, 999, 999, 999, 999, 999,
999, 1, 999, 2, 999, 3,
999, 999, 999, 999, 999, 999,
999, 0, 999, 4, 999, 5,
999, 999, 999, 999, 999, 999,
999, 0, 999, 0, 999, 6,
999, 999, 999, 999, 999, 999,
999, 0, 999, 7, 999, 10
]);

out = new Float64Array([
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999
]);

out = transpose( 4, 6, A, 12, 2, 7, out, 2, 12, 7 );
out = transpose( 6, 4, out, 2, 12, 7, A, 12, 2, 7 );
t.strictEqual( out, A, 'returns expected value' );
t.end();
});

tape( 'the function supports accessing elements in reverse order', function test( t ) {
var out;
var A;

/* eslint-disable array-element-newline, no-multi-spaces */

A = new Float64Array([
999, 999, 999, 999, 999, 999,
999, 1, 999, 2, 999, 3,
999, 999, 999, 999, 999, 999,
999, 0, 999, 4, 999, 5,
999, 999, 999, 999, 999, 999,
999, 0, 999, 0, 999, 6,
999, 999, 999, 999, 999, 999,
999, 0, 999, 7, 999, 10
]);

out = new Float64Array([
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999,
999, 999, 999, 999, 999, 999, 999, 999
]);

out = transpose( 4, 6, A, -12, -2, 47, out, 2, 12, 7 );
out = transpose( 6, 4, out, 2, 12, 7, A, -12, -2, 47 );
t.strictEqual( out, A, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var uniform = require( '@stdlib/random/array/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var transpose = require( './../lib/transpose.js' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof transpose, 'function', 'main export is a function' );
t.end();
});

tape( 'the function has an arity of 7', function test( t ) {
t.strictEqual( transpose.length, 7, 'returns expected value' );
t.end();
});

tape( 'the function throws an error if provided an invalid first argument', function test( t ) {
var values;
var out;
var A;
var i;

values = [
'foo',
'bar',
'beep',
'boop'
];

A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
out = new Float64Array( 4 );

for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
return function badValue() {
transpose( value, 2, 2, A, 2, out, 2 );
};
}
});

tape( 'the function correctly transposes given general matrix', function test( t ) {
var options;
var out;
var A;
var M;
var N;

options = {
'dtype': 'float64'
};

M = 12;
N = 19;
A = uniform( M*N, -10.0, 10.0, options );
out = uniform( N*M, -10.0, 10.0, options );

out = transpose( 'row-major', M, N, A, N, out, M );
out = transpose( 'column-major', N, M, out, M, A, N );
t.strictEqual( out, A, 'returns expected value' );

out = transpose( 'column-major', N, M, A, M, out, N );
out = transpose( 'row-major', M, N, out, N, A, M );
t.strictEqual( out, A, 'returns expected value' );

t.end();
});

0 comments on commit 57ce29a

Please sign in to comment.