text:
import unittest
import numpy as np
import paddle.fluid.core as core
import paddle
import random
import sys

from op_test import OpTest

sys.path.append("./rnn")
from rnn_numpy import LSTM
from convert import get_params_for_net

random.seed(2)
np.set_printoptions(threshold=np.inf)
paddle.enable_static()

class TestRNNOp(OpTest):
    def get_weight_names(self):
        weight_names = []
        for i in range(self.num_layers):
            for j in range(0, 2 * self.direction_num):
                weight_names.append("{}.weight_{}".format(i, j))
        for i in range(self.num_layers):
            for j in range(0, 2 * self.direction_num):
                weight_names.append("{}.bias_{}".format(i, j))
        return weight_names

    def setUp(self):
        self.op_type = "rnn"
        self.dtype = np.float32 if core.is_compiled_with_rocm() else np.float64
        self.sequence_length = (
            None
            if core.is_compiled_with_rocm()
            else np.array([12, 11, 10, 9, 8], dtype=np.int32)
        )
        self.num_layers = 1
        self.is_bidirec = False
        self.mode = "LSTM"
        self.is_test = False
        self.dropout = 0.0
        self.set_attrs()

        self.direction_num = 2 if self.is_bidirec else 1
        direction = "bidirectional" if self.is_bidirec else "forward"
        seq_length = 12
        batch_size = 5
        input_size = 3
        hidden_size = 2

        input = np.random.uniform(
            low=-0.1, high=0.1, size=(seq_length, batch_size, input_size)
        ).astype(self.dtype)
        if self.sequence_length is not None:
            input[11][1:][:] = 0
            input[10][2:][:] = 0
            input[9][3:][:] = 0
            input[8][4:][:] = 0

        rnn1 = LSTM(
            input_size,
            hidden_size,
            num_layers=self.num_layers,
            time_major=True,
            direction=direction,
            dropout=self.dropout,
            dtype=self.dtype,
        )

        flat_w = get_params_for_net(rnn1)
        output, (last_hidden, last_cell) = rnn1(
            input, sequence_length=self.sequence_length
        )

        if core.is_compiled_with_rocm():

            def rocm_rnn_get_place():
                places = [core.CUDAPlace(0)]
                return places

            self._get_places = rocm_rnn_get_place

        init_h = np.zeros(
            (self.num_layers * self.direction_num, batch_size, hidden_size)
        ).astype(self.dtype)
        init_c = np.zeros(
            (self.num_layers * self.direction_num, batch_size, hidden_size)
        ).astype(self.dtype)
        state_out = np.ndarray((300)).astype("uint8")

        self.inputs = {
            'Input': input,
            'WeightList': flat_w,
            'PreState': [('init_h', init_h), ('init_c', init_c)],
            'SequenceLength': self.sequence_length,
        }
        if self.sequence_length is None:
            self.inputs = {
                'Input': input,
                'WeightList': flat_w,
                'PreState': [('init_h', init_h), ('init_c', init_c)],
            }
        self.attrs = {
            'dropout_prob': self.dropout,
            'is_bidirec': self.is_bidirec,
            'input_size': input_size,
            'hidden_size': hidden_size,
            'num_layers': self.num_layers,
            'mode': self.mode,
            'is_test': self.is_test,
        }
        self.outputs = {
            'Out': output,
            "State": [('last_hidden', last_hidden), ('last_cell', last_cell)],
            'Reserve': np.ndarray((400)).astype("uint8"),
            'DropoutState': state_out,
        }

    def test_output(self):
        self.check_output(no_check_set=['Reserve', 'DropoutState'])

    def set_attrs(self):
        pass

    def test_grad(self):
        if not self.is_test:
            var_name_list = self.get_weight_names()
            grad_check_list = ['Input', 'init_h', 'init_c']
            grad_check_list.extend(var_name_list)
            self.check_grad(
                set(grad_check_list), ['Out', 'last_hidden', 'last_cell']
            )

    def test_grad_only_input(self):
        if not self.is_test:
            var_name_list = self.get_weight_names()
            grad_check_list = ['Input']
            grad_check_list.extend(var_name_list)
            self.check_grad(
                set(grad_check_list), ['Out', 'last_hidden', 'last_cell']
            )

    def test_grad_only_h(self):
        if not self.is_test:
            var_name_list = self.get_weight_names()
            grad_check_list = ['init_h']
            grad_check_list.extend(var_name_list)
            self.check_grad(
                set(grad_check_list), ['Out', 'last_hidden', 'last_cell']
            )

    def test_grad_only_c(self):
        if not self.is_test:
            var_name_list = self.get_weight_names()
            grad_check_list = ['init_c']
            grad_check_list.extend(var_name_list)
            self.check_grad(
                set(grad_check_list), ['Out', 'last_hidden', 'last_cell']
            )

class TestRNNOp1(TestRNNOp):
    def set_attrs(self):
        self.sequence_length = None

class TestRNNOp2(TestRNNOp):
    def set_attrs(self):
        self.sequence_length = None
        self.is_bidirec = True

class TestRNNOp3(TestRNNOp):
    def set_attrs(self):
        self.is_test = True
        self.sequence_length = None

class TestRNNOp4(TestRNNOp):
    def set_attrs(self):
        self.is_test = True
        self.sequence_length = None
        self.is_bidirec = True

class TestRNNOp5(TestRNNOp):
    def set_attrs(self):
        self.num_layers = 2

class TestRNNOp6(TestRNNOp):
    def set_attrs(self):
        self.num_layers = 2
        self.is_bidirec = True

class TestRNNOp7(TestRNNOp):
    def set_attrs(self):
        self.num_layers = 2
        self.is_bidirec = True
        self.is_test = True

class TestRNNOp8(TestRNNOp):
    def set_attrs(self):
        self.num_layers = 2
        self.is_bidirec = True
        self.sequence_length = None

class TestRNNOp9(TestRNNOp):
    def set_attrs(self):
        self.num_layers = 3

if __name__ == '__main__':
    unittest.main()


text:
PACKAGE_VERSION=3.3.0

echo "Usage: $0 [-v <PACKAGE_VERSION>]"
echo "       PACKAGE_VERSION is an optional paramater whose default value is 3.3.0"

PACKAGE_VERSION="${1:-$PACKAGE_VERSION}"

# install tools and dependent packages
yum -y install git wget gcc-c++ make python2 curl

NODE_VERSION=v12.22.4
#installing nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm install $NODE_VERSION

# clone, build and test specified version

git clone https://github.com/Stuk/jszip
cd jszip
git checkout v$PACKAGE_VERSION
npm install
npm run test-node

redpajama_set_name: RedPajamaGithub


text:
/* TODO:

  hook in all ui stuff

*/

;(function() {
  'use strict';

  var scriptData = [];
  var updatedImgData = {};

  var currentBoard;
  var updatedImgList;

  var timeoutLayerID;
  var timeoutFlatID;

  var dirty = [0,0];
  var dirtyLayer = [0,0,0,0,0,0,0,0,0,0,0,0];

    if (localStorage.getItem("updatedImgList")) {
      updatedImgList = JSON.parse(localStorage.getItem("updatedImgList"));
    } else {
      updatedImgList = {};
    }

  var checkUpdated = function(filename) {
    if (updatedImgList[filename]) {

      if (updatedImgData[filename]) {
        return updatedImgData[filename];
      } else {
        var value = currentFile.imageUrl(filename + "?" + updatedImgList[filename]);
        return value;
      }
    } else {
      return currentFile.imageUrl(filename);
    }
  };

  var addUpdatedImage = function(filename) {
    updatedImgList[filename] = new Date().getTime().toString();
    localStorage.setItem("updatedImgList", JSON.stringify(updatedImgList));
  };

  var addUpdatedImageData = function(filename, data) {
    updatedImgData[filename] = data;
  }

  $(document).ready(function() {
    $(".drawing-canvas").mousemove(function(){
      if (sketchpane.getEditMode()) {
      }
      else {
        preLoadLayers();
      }
    });
  });

  var preLoadLayers = function(copyAfter) {
    var layerURLs = [];
    for (var i = 0; i < 3; i ++) {
      layerURLs.push(checkUpdated(currentBoard + '-layer-' + i + '.png'));
    }
    sketchpane.loadLayers(layerURLs, currentBoard, copyAfter);
  }

  var saveScript = function(next) {
    currentFile.saveScript(next);
  };

  var setLayerDirty = function(layer) {
    dirty = [1,1];
    dirtyLayer[layer] = 1;
    if (timeoutLayerID) {
    } else {
      timeoutLayerID = window.setTimeout(
        uploadLayer,
        currentFile.settings().AUTO_UPLOAD_LAYER_TIME * 1000);
    }
    if (timeoutFlatID) {
    } else {
      timeoutFlatID = window.setTimeout(
        uploadFlat,
        currentFile.settings().AUTO_UPLOAD_FLAT_TIME * 1000);
    }
  };

  var saveImage = function(filename, imageData, type) {
    // save is a promise
    var save = currentFile.saveImage(filename, imageData, 'image/jpeg');
    save.done(function() {
      addUpdatedImage(filename);
    });
    addUpdatedImageData(filename, imageData);
    return save;
  };

  var uploadLayer = function(force) {
    if (sketchpane.getPenDown() && !force) {
      timeoutLayerID = window.setTimeout(
        uploadLayer,
        currentFile.settings().AUTO_UPLOAD_LAYER_TIME * 1000);
    } else {
      timeoutLayerID = null;
      var saves = [];
      for (var i = 0; i < dirtyLayer.length; i ++) {
        if (dirtyLayer[i]) {
          var filename = currentBoard + "-layer-" + i + ".png";
          var imageData = sketchpane.getLayerImage(i);
          saves.push(saveImage(filename, imageData, 'image/png'));
          dirtyLayer[i] = 0;
        }
      }
      dirty[0] = 0;
      return $.when.apply($, saves);
    }
  };

  var uploadFlat = function(force) {
    if (sketchpane.getPenDown() && !force) {
      timeoutFlatID = window.setTimeout(
        uploadFlat,
        currentFile.settings().AUTO_UPLOAD_FLAT_TIME * 1000);
      return null;
    } else {
      timeoutFlatID = null;
      dirty[1] = 0;
      var flatImages = sketchpane.getFlatImage();

      var filename = currentBoard + "-large.jpeg";
      var imageData = flatImages[0];
      var saveLarge = saveImage(filename, imageData, 'image/jpeg');

      setThumb(flatImages[1]);

      filename = currentBoard + "-small.jpeg";
      imageData = flatImages[1];
      var saveSmall = saveImage(filename, imageData, 'image/jpeg');
      return $.when(saveLarge, saveSmall);
    }
  };

  var getDirty = function getDirty() {
    if (dirty[0] || dirty[1]) {
      return true;
    } else {
      return false;
    }
  };

  var forceSave = function() {
    window.clearTimeout(timeoutLayerID);
    window.clearTimeout(timeoutFlatID);
    timeoutLayerID = null;
    timeoutFlatID = null;
    var uploads = [];
    if (dirty[0]) {
      uploads.push(uploadLayer(true));
    }
    if (dirty[1]) {
      uploads.push(uploadFlat(true));
    }
    return $.when.apply($, uploads);
  };

  var preloadAround = function() {
    var index = scriptData.indexOf(currentBoard);
    for (var i=-1;i<3;i++) {
      if (i !== 0) {
        var ind = index + i;
        ind = Math.max(Math.min(scriptData.length - 1, ind), 0);
        var image = new Image();
        var source = checkUpdated(scriptData[ind] + "-large.jpeg");
        image.src = source;
      }
    }
  };

  var preload = function(id) {
    var image = new Image();
    var source = checkUpdated(id + "-large.jpeg");
    image.src = source;
  };

  var loadFlatBoard = function(id, newboard, caption) {
    forceSave();
    currentBoard = id;
    var index = scriptData.indexOf(currentBoard);

    if (caption) {
      $('.drawing-canvas .caption').html(caption);
      $('.drawing-canvas .caption').show();
    }

    if (newboard) {
      sketchpane.newSketch();
    } else {
      sketchpane.loadFlatImage(checkUpdated(id + "-large.jpeg"));
    }
    $(".boards-list img.selected").removeClass( "selected" );
    $("#" + id).addClass( "selected" );
    fountainManager.preloadAround();
    $('.boards-list').finish();
    // this sometimes/always competes with selectandscroll in fountainmanager
    $('.boards-list').animate({scrollTop: ($('.boards-list div').outerHeight()*(index-2)+100)}, 100);
  };

  var loadLightboxImage = function(id) {
    var url = checkUpdated(id + "-large.jpeg");
    $("#lightbox-image").attr("src", url);
    if (sketchpane.getLighboxMode()) {
      $("#lightbox-image").css("display", "block");
    } else {
      $("#lightbox-image").css("display", "none");
    }
  };

  var clearLightboxImage = function() {
    $("#lightbox-image").attr("src", "");
    $("#lightbox-image").css("display", "none");
  };

  var setThumb = function(img) {
    log("setting thumbnail:" + currentBoard)
    $("#script-image-" + currentBoard).attr('src', img);
  };

  var getScriptData = function() { return scriptData; };

  var getCurrentBoard = function() {
    return currentBoard;
  };

  var storyboardState = window.storyboardState = {
    setLayerDirty: setLayerDirty,
    getDirty: getDirty,
    forceSave: forceSave,
    setThumb: setThumb,
    getScriptData: getScriptData,
    getCurrentBoard: getCurrentBoard,
    checkUpdated: checkUpdated,
    loadFlatBoard: loadFlatBoard,
    saveScript: saveScript,
    preLoadLayers: preLoadLayers,
    loadLightboxImage: loadLightboxImage,
    clearLightboxImage: clearLightboxImage
  };

}).call(this);


text:
<!doctype html>

  <meta charset="utf-8">
  <title>Bubble Chart - vallandingham.me</title>
  <meta name="description" content="Example Bubble chart implementation in JS. Based on NYT visualization">
  <meta name="author" content="Jim Vallandingham">

  <meta name="viewport" content="width=device-width,initial-scale=1">
  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/bubble_chart.css">

Gates Foundation Educational Spending

      All Grants
      Grants By Year

A demonstration of animated bubble charts in JavaScript and D3.js

Blog Post | Code


text:
"use strict"

var branchCount = 0

var Sakura = function (trunk) {
  this.trunk = new Branch(Math.random() * 10, Math.random() / 10.0, 0, this);
  this.canvas = document.getElementById("the-canvas")
  this.canvas.width = this.canvas.clientWidth
  this.canvas.height = this.canvas.clientHeight
  this.ctx = this.canvas.getContext('2d')
  this.tick = this.tick.bind(this)

};

Sakura.prototype.draw = function () {
  this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
}

Sakura.prototype.tick = function () {
  // requests another animation frame
  // calls tick on tree's trunck
  window.requestAnimationFrame(this.tick)
  var t = new Turtle();
  t.x = this.canvas.width / 2
  t.y = this.canvas.height
  if (branchCount < 4000) {
    this.draw()
    this.trunk.tick(t)
    window.cancelAnimationFrame(this.tick)
  }
};

var Branch = function (length, thickness, angle, tree) {
  this.length = length;
  this.thickness = thickness;
  this.angle = angle;
  this.tree = tree;
  this.children = [];
  branchCount += 1;
  this.depth = 0
  // console.log(branchCount)
}

var randomLength = function () {
  return Math.floor( Math.random() * 5 ) + 1
}

Branch.prototype.draw = function (turtle) {
  // stuff
  this.tree.ctx.beginPath();
  this.tree.ctx.lineWidth = this.thickness;
  this.tree.ctx.strokeStyle = "black";
  // console.log("position", turtle.pos);
  this.tree.ctx.moveTo(turtle.pos[0], turtle.pos[1]);
  turtle.turnRight(this.angle);
  turtle.fwd(this.length);
  this.tree.ctx.lineTo(turtle.pos[0], turtle.pos[1]);
  this.tree.ctx.stroke();
  // console.log("position 2", turtle.pos);

if(this.depth>5 && this.depth<10) {
  if (branchCount > 100) {
    this.tree.ctx.beginPath();
    this.tree.ctx.lineWidth = "4";
    this.tree.ctx.strokeStyle = "green";
    this.tree.ctx.rect(turtle.x, turtle.y, 2, 2);
    this.tree.ctx.stroke();
  }

}
if (this.depth >= 7) {
  if (branchCount > 1000) {
    this.tree.ctx.beginPath();
    this.tree.ctx.lineWidth = "4";
    this.tree.ctx.strokeStyle = "pink";
    this.tree.ctx.rect(turtle.x + 5, turtle.y + 5, 2, 2);
    this.tree.ctx.stroke();
  }

}

}

Branch.prototype.tick = function (turtle) {
  // grows branch by a random amount
  // sprouts new children 0.3% of the time
  // calls tick on all of its children
  this.length +=  Math.random() / 15.0;
  this.thickness += Math.random() / 60.0;
  // if (branchCount > 1000) {
  //   this.angle += (0.001 * this.depth);
  // }
  // this.angle += Math.random() - 0.5; // wobble
  if (Math.random() <= 0.003) {
    var b = new Branch(Math.random() * 15, (Math.random() / 65.0), (Math.random() * 90) - 45, this.tree)
    b.depth = this.depth + 1;
    this.children.push(b)

  };
  var i = this.children.length;
  this.draw(turtle)
    while (--i >= 0) {
      this.children[i].tick(turtle.spawn())
    }
}

var tree1 = new Sakura()
console.log(tree1.tick())