/**
* @license Apache-2.0
*
* Copyright (c) 2018 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';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var daxpy = require( './../lib' ).wasm();

var xbytes;
var ybytes;
var x;
var y;
var i;

// Allocate space on the heap:
xbytes = daxpy.malloc( 10 * 8 ); // 8 bytes per double
ybytes = daxpy.malloc( 10 * 8 );

// Create Float64Array views:
x = new Float64Array( xbytes.buffer, xbytes.byteOffset, 10 );
y = new Float64Array( ybytes.buffer, ybytes.byteOffset, 10 );

// Set data on the heap...
for ( i = 0; i < x.length; i++ ) {
	x[ i ] = round( randu()*100.0 );
	y[ i ] = round( randu()*10.0 );
}
console.log( x );
console.log( y );

daxpy( x.length, 5.0, xbytes, 1, ybytes, -1 );
console.log( y );

// Free allocated memory:
daxpy.free( xbytes );
daxpy.free( ybytes );

/**
* @license Apache-2.0
*
* Copyright (c) 2018 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';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var factory = require( './../lib' ).wasm;

var xbytes;
var ybytes;
var daxpy;
var x;
var y;
var i;

// Create a new WASM instance:
daxpy = factory();

// Allocate space on the heap:
xbytes = daxpy.malloc( 10 * 8 ); // 8 bytes per double
ybytes = daxpy.malloc( 10 * 8 );

// Create Float64Array views:
x = new Float64Array( xbytes.buffer, xbytes.byteOffset, 10 );
y = new Float64Array( ybytes.buffer, ybytes.byteOffset, 10 );

// Set data on the heap...
for ( i = 0; i < x.length; i++ ) {
	x[ i ] = round( randu()*100.0 );
	y[ i ] = round( randu()*10.0 );
}
console.log( x );
console.log( y );

daxpy( x.length, 5.0, xbytes, 1, ybytes, -1 );
console.log( y );

// Free allocated memory:
daxpy.free( xbytes );
daxpy.free( ybytes );

Update example