{"size": 3479, "ext": "js", "max_stars_repo_path": "test/unary.js", "max_stars_repo_name": "kibertoad/cwise", "max_stars_repo_stars_event_min_datetime": "2015-02-03T10:40:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-20T10:06:36.000Z", "max_issues_repo_path": "test/unary.js", "max_issues_repo_name": "kibertoad/cwise", "max_issues_repo_issues_event_min_datetime": "2015-04-10T14:09:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-22T16:14:44.000Z", "max_forks_repo_path": "test/unary.js", "max_forks_repo_name": "kibertoad/cwise", "max_forks_repo_forks_event_min_datetime": "2015-08-14T17:08:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-03T03:13:29.000Z"}
{"max_stars_count": 78, "max_issues_count": 25, "max_forks_count": 24, "avg_line_length": 33.7766990291, "max_line_length": 130, "alphanum_fraction": 0.6151192872}
var cwise = require("cwise")
var ndarray = require("ndarray")

if(typeof test === "undefined") {
  test = require("tape")
}

function DumbStorage(n) {
  this.data = new Int32Array(n)
  this.length = n
}
DumbStorage.prototype.get = function(i) { return this.data[i] }
DumbStorage.prototype.set = function(i, v) { return this.data[i]=v }

test("unary", function(t) {

  var unary = cwise({
    args: ["array"],
    body: function(a) {
      ++a
    }
  })
  
  function testUnary1D(arr, testName) {
    for(var i=0; i<arr.shape[0]; ++i) {
      arr.set(i, i)
    }
    unary(arr)
    for(var i=0; i<arr.shape[0]; ++i) {
      if (!(arr.get(i) === i+1)) {
        t.fail(testName + "; encountered " + arr.get(i) + " instead of " + (i+1) + " at " + i)
        return
      }
    }
    t.pass(testName)
  }
  var simple_zeros = ndarray(new Int32Array(4096))
  
  testUnary1D(simple_zeros.hi(0), "simple_zeros.hi(0)")
  testUnary1D(simple_zeros.hi(1), "simple_zeros.hi(1)")
  testUnary1D(simple_zeros.hi(2), "simple_zeros.hi(2)")
  testUnary1D(simple_zeros, "simple_zeros")
  testUnary1D(simple_zeros.hi(31), "simple_zeros.hi(31)")
  testUnary1D(simple_zeros.hi(32), "simple_zeros.hi(32)")
  testUnary1D(simple_zeros.hi(33), "simple_zeros.hi(33)")
  testUnary1D(simple_zeros.step(-1), "simple_zeros.step(-1)")
  testUnary1D(simple_zeros.step(3), "simple_zeros.step(3)")
  testUnary1D(simple_zeros.step(4), "simple_zeros.step(4)")
  testUnary1D(simple_zeros.step(5).lo(10), "simple_zeros.step(5).lo(10)")
  
  var custom_zeros = ndarray(new DumbStorage(4096))
  
  testUnary1D(custom_zeros.hi(0), "custom_zeros.hi(0)")
  testUnary1D(custom_zeros.hi(1), "custom_zeros.hi(1)")
  testUnary1D(custom_zeros.hi(2), "custom_zeros.hi(2)")
  testUnary1D(custom_zeros, "custom_zeros")
  testUnary1D(custom_zeros.hi(31), "custom_zeros.hi(31)")
  testUnary1D(custom_zeros.hi(32), "custom_zeros.hi(32)")
  testUnary1D(custom_zeros.hi(33), "custom_zeros.hi(33)")
  testUnary1D(custom_zeros.step(-1), "custom_zeros.step(-1)")
  testUnary1D(custom_zeros.step(3), "custom_zeros.step(3)")
  testUnary1D(custom_zeros.step(4), "custom_zeros.step(4)")
  testUnary1D(custom_zeros.step(5).lo(10), "custom_zeros.step(5).lo(10)")
  
  function testUnary2D(arr, testName) {
    for(var i=0; i<arr.shape[0]; ++i) {
      for(var j=0; j<arr.shape[1]; ++j) {
        arr.set(i,j, i+j*arr.shape[0])
      }
    }
    unary(arr)
    for(var i=0; i<arr.shape[0]; ++i) {
      for(var j=0; j<arr.shape[1]; ++j) {
        if (!(arr.get(i,j) === 1+i+j*arr.shape[0])) {
          t.fail(testName + "; encountered " + arr.get(i,j) + " instead of " + (1+i+j*arr.shape[0]) + " at (" + i + "," + j + ")")
          return
        }
      }
    }
    t.pass(testName)
  }
  
  var M = ndarray(new Int32Array(128*128), [128,128])
  testUnary2D(M, "M")
  testUnary2D(M.hi(10, 10), "M.hi(10, 10)")
  testUnary2D(M.lo(100,1), "M.lo(100,1)")
  testUnary2D(M.transpose(1,0), "M.transpose(1,0)")
  testUnary2D(M.step(-1, 1), "M.step(-1, 1)")
  testUnary2D(M.step(-5, -2), "M.step(-5, -2)")
  testUnary2D(M.step(16, 3), "M.step(16, 3)")
  
  M = ndarray(new DumbStorage(128*128), [128,128])
  testUnary2D(M, "DS; M")
  testUnary2D(M.hi(10, 10), "DS; M.hi(10, 10)")
  testUnary2D(M.lo(100,1), "DS; M.lo(100,1)")
  testUnary2D(M.transpose(1,0), "DS; M.transpose(1,0)")
  testUnary2D(M.step(-1, 1), "DS; M.step(-1, 1)")
  testUnary2D(M.step(-5, -2), "DS; M.step(-5, -2)")
  testUnary2D(M.step(16, 3), "DS; M.step(16, 3)")
  
  t.end()
})
