Skip to content

Instantly share code, notes, and snippets.

View yunjiangster's full-sized avatar

Yunjiang Jiang yunjiangster

  • Yahoo!
  • Sunnyvale
View GitHub Profile
@priyathamkat
priyathamkat / mp_infer.py
Last active June 15, 2024 22:28
Multi GPU inference using `torch.multiprocessing`
import torch
import torch.multiprocessing as mp
from absl import app, flags
from torchvision.models import AlexNet
FLAGS = flags.FLAGS
flags.DEFINE_integer("num_processes", 2, "Number of subprocesses to use")
@caiorss
caiorss / cstr.cpp
Created February 10, 2019 06:19
Python Ctypes wrapper to C++ shared library returning dynamically allocated string buffers
// Compile with:
// $ clang++ cstr.cpp -o cstr.so -std=c++1z -O0 -g -shared -fPIC -std=c++1z
//----------------------------------------------------
#include <iostream>
#include <string>
#include <sstream>
#include <cstring> // std::strncpy
#include <cmath>
#if defined(_WIN32)
@tzachz
tzachz / CombineMaps.scala
Last active January 26, 2023 04:31
Apache Spark UserDefinedAggregateFunction combining maps
import org.apache.spark.SparkContext
import org.apache.spark.sql.expressions.{MutableAggregationBuffer, UserDefinedAggregateFunction}
import org.apache.spark.sql.types._
import org.apache.spark.sql.{Column, Row, SQLContext}
/***
* UDAF combining maps, overriding any duplicate key with "latest" value
* @param keyType DataType of Map key
* @param valueType DataType of Value key
* @param merge function to merge values of identical keys