GithubHelp home page GithubHelp logo

ndarray-proxy's Introduction

ndarray-proxy

Creates lazily initialized ndarrays. These give a logical view of a function as an ndarray.

Introduction

Lazy arrays work just like ndarrays, and can be used in all the same ways. However, unlike dense arrays they do not keep any storage and instead use a function to determine the contents of the array. Here is a simple example:

var proxy = require("ndarray-proxy")

//Create a 10x10 lazily initialized ndarray
var x = proxy([10, 10], function(i, j) {
  console.log("Called:", i, j)
  return 10*i + j
})

x.get(1,2)    //Prints out:   Called: 1 2
x.get(7,8)    //Prints out:   Called: 7 8

It is possible to slice the view of a lazy ndarray, just like a regular ndarray:

x.lo(2,3).get(1,1)            //Prints out:  Called: 3 4
x.transpose(1,0).get(3,7)     //Prints out:  Called: 7 3

You can use lazy ndarrays with cwise or any other library that works with ndarrays.

It is also possible to add a setter to the lazy ndarray to implement custom assignment operations. For example:

var y = proxy([10,10],
    function(i,j) { return 10*i+j; }, 
    function(i,j,v) {
      console.log("SET:", i, j, "=", v)
    })

y.set(2,3,10) //Prints:  SET: 2 3 = 10

If a setter isn't specified, then writing to the array throws an error.

Install

You can install the library using npm:

npm install ndarray-lazy

And like all ndarray modules it should work in a browser that supports typed arrays using browserify.

API

require("ndarray-proxy")(shape, get_func[, set_func])

Creates a wrapper for an ndarray

  • shape is the shape of the wrapped ndarray
  • get_func(i0,i1,...) implements access to the ndarray
  • set_func(i0,i1,...,v) implements writing to the ndarray

Returns A proxy view of the functions.

Credits

(c) 2013 Mikola Lysenko. MIT License

ndarray-proxy's People

Contributors

mikolalysenko avatar shama avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.