Skip to content

Crashes when passed an Array-backed ndarray #1

Description

@timoxley

When passing an ndarray backed by a vanilla JS Array, translate will crash with an error "TypeError: Cannot read property 'get' of null".

See example below:

var ndarray = require('ndarray')
var zeros = require('zeros')
var ops = require('ops')
var translate = require('ndarray-translate')
var show = require('ndarray-show')

// create with zeros
var points = zeros([5, 5])
points.set(2, 2, 1)

translate(points, [1, 1]) // this works as expected
console.log(show((points))) // whoo

// now define the "same" datastructure using an Array
var points2 = ndarray([
  0, 0, 0, 0, 0,
  0, 0, 0, 0, 0,
  0, 0, 1, 0, 0,
  0, 0, 0, 0, 0,
  0, 0, 0, 0, 0,
], [5, 5])

console.log("equal", ops.equals(points, points2))  // apparently the data is equivalent…

translate(points2, [1, 1]) // …yet translate bombs
console.log(show((points2))) // never gets here
TypeError: Cannot read property 'get' of null
    at assign_cwise_loop_1s0m2ga (eval at generateCWiseOp (/Users/timoxley/Projects/tests/graphing/node_modules/ndarray-ops/node_modules/cwise-compiler/lib/compile.js:351:11), <anonymous>:8:10)
    at assign_cwise_thunk (eval at createThunk (/Users/timoxley/Projects/tests/graphing/node_modules/ndarray-ops/node_modules/cwise-compiler/lib/thunk.js:82:15), <anonymous>:9:59)
    at Object.assign_ndarrayops [as assign] (eval at makeOp (/Users/timoxley/Projects/tests/graphing/node_modules/ndarray-ops/ndarray-ops.js:48:17), <anonymous>:1:43)
    at translateZeroBC (/Users/timoxley/Projects/tests/graphing/node_modules/ndarray-translate/translate.js:47:7)
    at Object.<anonymous> (/Users/timoxley/Projects/tests/graphing/index.js:24:1)
    at Module._compile (module.js:431:26)
    at Object.Module._extensions..js (module.js:449:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:472:10)

Error comes from this line returning null:

pool.malloc(q.size, arr.dtype)

Which seems to occur because arr.dtype is 'array' rather than one of the types listed in https://github.com/mikolalysenko/typedarray-pool#poolmallocn-dtype

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions