Skip to content

Instantly share code, notes, and snippets.

View tedsta's full-sized avatar

Theodore DeRego tedsta

View GitHub Profile
@tedsta
tedsta / deeplearn_rs_mnist_graph.rs
Last active May 11, 2016 18:17
Deeplearn-rs mnist graph
let ctx = Rc::new(ga::Context::new());
let ref mut graph = Graph::new(ctx.clone());
let batch_size = 10;
//////////////////////////
// Layer 1
// Input: batch_size samples of rows*columns inputs
let input = graph.add_variable(vec![batch_size, rows*columns], false, 0.0);
@tedsta
tedsta / deep_learn_mat_mul.rs
Created January 15, 2016 03:59
Matrix multiplication operation in deelearn-rs
pub struct MatMul {
a_t: ClMatrix<f32>,
b_t: ClMatrix<f32>,
}
impl MatMul {
pub fn new(ctx: &matrix::Context, a_shape: (u64, u64), b_shape: (u64, u64)) -> Self {
MatMul {
a_t: ClMatrix::new(ctx, a_shape.1 as usize, a_shape.0 as usize, ClMatrixMode::Mut),
b_t: ClMatrix::new(ctx, b_shape.1 as usize, b_shape.0 as usize, ClMatrixMode::Mut),
@tedsta
tedsta / deep_learn_graph.rs
Created January 15, 2016 03:52
Graph class in deeplearn-rs
pub struct Graph {
nodes: Vec<Node>,
node_ops: Vec<Box<Operation>>,
pub var_store: VarStore,
out_var_map: HashMap<VarIndex, (NodeIndex, usize)>, // Maps output variable to it's node and index within node
// Gradients on variables that are inputs to the graph - they have no corresponding node
in_var_grad: HashMap<VarIndex, OutGrad>,
}
impl Graph {
@tedsta
tedsta / deep_learn_node.rs
Created January 15, 2016 03:14
Node struct in deeplearn-rs
pub struct Node {
pub inputs: Vec<VarIndex>,
pub outputs: Vec<VarIndex>,
pub in_grad: Vec<VarIndex>, // gradients on inputs
pub out_grad: Vec<OutGrad>, // gradients on outputs
}
@tedsta
tedsta / deep_learn_xor.rs
Last active February 2, 2016 20:16
Example of untrained xor circuit using deeplearn-rs
extern crate deeplearn;
extern crate matrix;
use deeplearn::Graph;
use deeplearn::op::{MatMul, Relu};
fn main() {
let ctx = matrix::Context::new();
// Setup the graph
import requests
import socket, os
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler
import ssl
from util import text_image, get_random_image_path, get_user_name,\
make_fake_ride_request, get_ride_info, change_ride_status
from pages import success_page
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
@tedsta
tedsta / xdr_decode_nvpairs.rs
Created October 8, 2015 22:32
decoding xdr encoded nvpairs in rust
pub fn decode_nv_list_embedded(xdr: &mut xdr::Xdr) -> xdr::XdrResult<NvList> {
// Decode version and nvflag
let version = try!(xdr.decode_i32());
let nvflag = try!(xdr.decode_u32());
// TODO: Give an actual error
if version != NV_VERSION {
return Err(xdr::XdrError);
}
@tedsta
tedsta / nvs_xdr_nvpair.c
Last active October 9, 2015 04:36
XDR encoded nvpairs sample code
static int
nvs_xdr_nvpair(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
{
XDR *xdr = nvs->nvs_private;
int32_t encode_len, decode_len;
switch (nvs->nvs_op) {
case NVS_OP_ENCODE: {
size_t nvsize;