{{alias}}.main( N, x, strideX ) Computes the L2-norm of a single-precision floating-point vector. The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. If `N <= 0`, the function returns `0.0`. Parameters ---------- N: integer Number of indexed elements. x: Float32Array Input array. strideX: integer Index increment for `x`. Returns ------- out: number The L2-norm. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); > var out = {{alias}}.main( x.length, x, 1 ) 3.0 // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > out = {{alias}}.main( 3, x, 2 ) 3.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > out = {{alias}}.main( 3, x1, 2 ) 3.0 {{alias}}.ndarray( N, x, strideX, offsetX ) Computes the L2-norm of a single-precision floating-point vector using alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. Parameters ---------- N: integer Number of indexed elements. x: Float32Array Input array. strideX: integer Index increment for `x`. offsetX: integer Starting index for `x`. Returns ------- out: number The L2-norm. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); > var out = {{alias}}.ndarray( x.length, x, 1, 0 ) 3.0 // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > out = {{alias}}.ndarray( 3, x, 2, 1 ) 3.0 {{alias}}.Module( memory ) Returns a new WebAssembly module wrapper which uses the provided WebAssembly memory instance as its underlying memory. Parameters ---------- memory: Memory WebAssembly memory instance. Returns ------- mod: Module WebAssembly module wrapper. Examples -------- // Create a new memory instance: > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); // Create a new routine: > var mod = new {{alias}}.Module( mem ); // Initialize the routine: > mod.initializeSync(); {{alias}}.Module.prototype.binary Read-only property which returns WebAssembly binary code. Returns ------- out: Uint8Array WebAssembly binary code. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.binary {{alias}}.Module.prototype.memory Read-only property which returns WebAssembly memory. Returns ------- mem: Memory|null WebAssembly memory. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.memory {{alias}}.Module.prototype.buffer Read-only property which returns a WebAssembly memory buffer as a Uint8Array. Returns ------- buf: Uint8Array|null WebAssembly memory buffer. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.buffer {{alias}}.Module.prototype.view Read-only property which returns a WebAsssembly memory buffer as a DataView. Returns ------- view: DataView|null WebAssembly memory view. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.view {{alias}}.Module.prototype.exports Read-only property which returns "raw" WebAssembly module exports. Returns ------- out: Object|null WebAssembly module exports. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.exports {...} {{alias}}.Module.prototype.initialize() Asynchronously initializes a WebAssembly module instance. Returns ------- p: Promise Promise which resolves upon initializing a WebAssembly module instance. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initialize(); {{alias}}.Module.prototype.initializeAsync( clbk ) Asynchronously initializes a WebAssembly module instance. Parameters ---------- clbk: Function Callback to invoke upon initializing a WebAssembly module instance. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > function clbk() { console.log( 'done' ) }; > mod.initializeAsync( clbk ); {{alias}}.Module.prototype.initializeSync() Synchronously initializes a WebAssembly module instance. In web browsers, JavaScript engines may raise an exception when attempting to synchronously compile large WebAssembly binaries due to concerns about blocking the main thread. Hence, to initialize WebAssembly modules having large binaries (e.g., >4KiB), consider using asynchronous initialization methods in browser contexts. Returns ------- mod: Module Module wrapper instance. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); {{alias}}.Module.prototype.realloc( nbytes ) Reallocates the underlying WebAssembly memory instance to a specified number of bytes. WebAssembly memory can only *grow*, not shrink. Hence, if provided a number of bytes which is less than or equal to the size of the current memory, the function does nothing. When non-shared memory is resized, the underlying the `ArrayBuffer` is detached, consequently invalidating any associated typed array views. Before resizing non-shared memory, ensure that associated typed array views no longer need byte access and can be garbage collected. Parameters ---------- nbytes: integer Memory size (in bytes). Returns ------- bool: boolean Boolean indicating whether the resize operation was successful. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.realloc( 100 ) {{alias}}.Module.prototype.hasCapacity( byteOffset, values ) Returns a boolean indicating whether the underlying WebAssembly memory instance has the capacity to store a provided list of values starting from a specified byte offset. Parameters ---------- byteOffset: integer Byte offset at which to start writing values. values: ArrayLikeObject Input array containing values to write. Returns ------- bool: boolean Boolean indicating whether the underlying WebAssembly memory instance has enough capacity. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.realloc( 100 ); > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) true {{alias}}.Module.prototype.isView( values ) Returns a boolean indicating whether a provided list of values is a view of the underlying memory of the WebAssembly module. Parameters ---------- values: ArrayLikeObject Input array. Returns ------- bool: boolean Boolean indicating whether the list is a memory view. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.realloc( 100 ); > mod.isView( [ 1, 2, 3, 4 ] ) false {{alias}}.Module.prototype.write( byteOffset, values ) Writes values to the underlying WebAssembly memory instance. The function infers element size (i.e., number of bytes per element) from the data type of the input array. For example, if provided a Float32Array, the function writes each element as a single-precision floating-point number to the underlying WebAssembly memory instance. In order to write elements as a different data type, you need to perform an explicit cast *before* calling this method. For example, in order to write single-precision floating-point numbers contained in a Float32Array as signed 32-bit integers, you must first convert the Float32Array to an Int32Array before passing the values to this method. If provided an array having an unknown or "generic" data type, elements are written as double-precision floating-point numbers. Parameters ---------- byteOffset: integer Byte offset at which to start writing values. values: ArrayLikeObject Input array containing values to write. Returns ------- mod: Module Module wrapper instance. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.realloc( 100 ); > mod.write( 0, [ 1, 2, 3, 4 ] ); {{alias}}.Module.prototype.read( byteOffset, out ) Reads values from the underlying WebAssembly memory instance. The function infers element size (i.e., number of bytes per element) from the data type of the output array. For example, if provided a Float32Array, the function reads each element as a single-precision floating-point number from the underlying WebAssembly memory instance. In order to read elements as a different data type, you need to perform an explicit cast *after* calling this method. For example, in order to read single-precision floating-point numbers contained in a Float32Array as signed 32-bit integers, you must convert the Float32Array to an Int32Array after reading memory values using this method. If provided an output array having an unknown or "generic" data type, elements are read as double-precision floating-point numbers. Parameters ---------- byteOffset: integer Byte offset at which to start reading values. out: ArrayLikeObject Output array for storing read values. Returns ------- mod: Module Module wrapper instance. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); > mod.realloc( 100 ); > mod.write( 0, [ 1, 2, 3, 4 ] ); > var out = [ 0, 0, 0, 0 ]; > mod.read( 0, out ); > out [ 1, 2, 3, 4 ] {{alias}}.Module.prototype.main( N, xp, sx ) Computes the L2-norm of a single-precision floating-point vector. Parameters ---------- N: integer Number of indexed elements. xp: integer Input array pointer (i.e., byte offset). sx: integer Index increment for `x`. Returns ------- out: number The L2-norm. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); // Define a "pointer" (i.e., byte offset) into module memory: > var xptr = 0; // Write data to module memory: > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float32' ) ); // Perform computation: > var out = mod.main( 5, xptr, 1 ) ~7.42 {{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) Computes the L2-norm of a single-precision floating-point vector using alternative indexing semantics. Parameters ---------- N: integer Number of indexed elements. xp: integer Input array pointer (i.e., byte offset). sx: integer Index increment for `x`. ox: integer Starting index for `x`. Returns ------- out: number The L2-norm. Examples -------- > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); > var mod = new {{alias}}.Module( mem ); > mod.initializeSync(); // Define a "pointer" (i.e., byte offset) into module memory: > var xptr = 0; // Write data to module memory: > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float32' ) ); // Perform computation: > var out = mod.ndarray( 5, xptr, 1, 0 ) ~7.42 See Also --------