Skip to content

Commit eca7a4e

Browse files
committed
Update add-on example
1 parent a0aa099 commit eca7a4e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/node_modules/@stdlib/strided/common/examples/addon/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ addon.node: $(addon_objects)
231231
# make run
232232
#/
233233
run: addon.node
234-
$(QUIET) $(NODE) -e "var add = require( '$(this_dir)/addon.node' ).add; var x = new Float64Array( [0, 1, 2, 3, 4] ); var y = new Float64Array( [5, 6, 7, 8] ); var z = new Float64Array( x.length ); add( 5, x, 1, y, 1, z, 1 ); console.log( z );"
234+
$(QUIET) $(NODE) -e "var add = require( '$(this_dir)/addon.node' ).add; var x = new Float64Array( [0, 1, 2, 3, 4] ); var y = new Float64Array( [5, 6, 7, 8, 9] ); var z = new Float64Array( x.length ); add( 5, x, 1, y, 1, z, 1 ); console.log( z );"
235235

236236
.PHONY: run
237237

lib/node_modules/@stdlib/strided/common/examples/addon/addon.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,29 @@ namespace addon_strided_add {
108108
// Convert the strides from units of elements to units of bytes...
109109
if ( info[ 1 ]->IsFloat64Array() ) {
110110
byteLength = (uint64_t)( info[ 1 ].As<Float64Array>()->ByteLength() ); // total bytes in view
111+
} else {
112+
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
113+
byteLength = 0;
111114
}
112115
len = (uint64_t)( X.length() ); // number of view elements
113116
bytesPerElement = (uint8_t)( byteLength / len ); // should evenly divide
114117
strides[ 0 ] *= bytesPerElement; // stride in units of bytes
115118

116119
if ( info[ 3 ]->IsFloat64Array() ) {
117120
byteLength = (uint64_t)( info[ 3 ].As<Float64Array>()->ByteLength() );
121+
} else {
122+
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
123+
byteLength = 0;
118124
}
119125
len = (uint64_t)( Y.length() );
120126
bytesPerElement = (uint8_t)( byteLength / len );
121127
strides[ 1 ] *= bytesPerElement;
122128

123129
if ( info[ 5 ]->IsFloat64Array() ) {
124130
byteLength = (uint64_t)( info[ 5 ].As<Float64Array>()->ByteLength() );
131+
} else {
132+
// NOTE: in lieu of handling the various typed arrays, for purposes of this example, set to zero.
133+
byteLength = 0;
125134
}
126135
len = (uint64_t)( Z.length() );
127136
bytesPerElement = (uint8_t)( byteLength / len );
@@ -133,7 +142,8 @@ namespace addon_strided_add {
133142
arrays[ 2 ] = *Z;
134143

135144
// Perform addition:
136-
stdlib_strided_dd_d( arrays, dims, strides, add );
145+
void *f = (void *)add;
146+
stdlib_strided_dd_d( arrays, dims, strides, f );
137147
}
138148

139149
NAN_MODULE_INIT( Init ) {

0 commit comments

Comments
 (0)