Skip to content

Instantly share code, notes, and snippets.

View gist:8b930fbddd4076c536404247ed4a881a
[debug]
[debug] Initial source changes:
[debug] removed:Set()
[debug] added: Set()
[debug] modified: Set(/Users/dlwh/src/breeze/math/src/main/scala/breeze/linalg/operators/DenseMatrixOps.scala)
[debug] Invalidated products: Set()
[debug] External API changes: API Changes: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated classes: Set(breeze.linalg.operators.DenseMatrixMultOps, breeze.linalg.operators.LowPriorityDenseMatrix1.SetDMVOp, breeze.linalg.operators.DenseMatrixFloatMultiplyStuff, breeze.linalg.operators.LowPriorityDenseMatrix.SetMSOp, breeze.linalg.operators.DenseMatrix_OrderingOps, breeze.linalg.operators.DenseMatrixFloatMultiplyStuff.implOpSolveMatrixBy_DMF_DVF_eq_DVF, breeze.linalg.operators.LowPriorityDenseMatrix.SetDMDVOp, breeze.linalg.operators.DenseMatrixFloatMultiplyStuff.implOpMulMatrix_DMF_DVF_eq_DVF, breeze.linalg.operators.DenseMatrixOps, breeze.linalg.operators.DenseMatrixMultiplyStuff.implOpMulMatrix_DMD_DMD_eq_DMD, breeze.linalg.operators.Dense
@dlwh
dlwh / build.sbt
Created Jan 21, 2015
javacl sbt error
View build.sbt
organization := "org.scalanlp"
name := "qqq"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
"com.nativelibs4java" % "javacl" % "1.0-SNAPSHOT"
View scEnrichColl.scala
implicit class scEnrichColl[Coll <: Traversable[(_,_)]](val __this: Coll) extends AnyVal {
def toMultiMap[Result, A, B](implicit view: Coll <:< Traversable[(A, B)], cbf: CanBuildFrom[Coll, B, Result]): Map[A, Result] = {
var result = collection.mutable.Map[A, mutable.Builder[B, Result]]()
result = result.withDefault { a => val r = cbf(__this); result.update(a, r); r}
for((a,b) <- view(__this)) {
result(a) += b
}
result.mapValues(_.result()).toMap
View UpdateSerializedObjects.scala
import java.io._
import java.util.zip.GZIPInputStream
import breeze.util.SerializableLogging
/**
* Class that reads in objects serialized with [[breeze.util.writeObject]], ignoring their serialversionuids,
* and then writes them to the same file.
*
* @author dlwh
View gist:8c9a1ef767a905bb8e98
[info] org.scalanlp:epic_2.10:0.2-SNAPSHOT [S]
[info] +-de.jflex:jflex:1.4.3
[info] +-org.mapdb:mapdb:0.9.2
[info] +-org.scala-lang:scala-library:2.10.2 (evicted by: 2.10.4)
[info] +-org.scala-lang:scala-library:2.10.3 (evicted by: 2.10.4)
[info] +-org.scalanlp:breeze-config_2.10:0.8 (evicted by: 0.8.1-SNAPSHOT)
[info] +-org.scalanlp:breeze-config_2.10:0.8.1-SNAPSHOT [S]
[info] | +-com.thoughtworks.paranamer:paranamer:2.2
[info] | +-org.scala-lang:scala-reflect:2.10.4 [S]
[info] |
View problematic.scala
import breeze.linalg._
import gust.linalg.cuda._
import jcuda.jcublas._
implicit val handle = new cublasHandle()
JCublas2.cublasCreate(handle)
// an extract from a REPL session
val A = CuMatrix.fromDense(DenseMatrix((1.0f, 1.0f, 2.0f, 1.0f), (1.0f, 2.0f, 1.0f, -2.0f), (3.0f, -1.0f, 3.0f, -2.0f), (-2.0f, 3.0f, -1.0f, 1.0f)))
val N = 4
@dlwh
dlwh / NMF.scala
Last active Aug 29, 2015
client code
View NMF.scala
object NMF {
def supervised(W: CuMatrix[Float], X: CuMatrix[Float], iters: Int = 200, eps: Float = 1E-6f) = {
require(W.rows == X.rows)
import W.blas
val n = X.rows
val m = X.cols
val r = W.cols
var H = CuMatrix.ones[Float](r, m)
@dlwh
dlwh / gist:9563285
Created Mar 15, 2014
messing with implicit lookup
View gist:9563285
package foo {
class Bar
object Bar {
implicit val b = new Bar
}
}
import foo.Bar
@dlwh
dlwh / gist:9042715
Last active Aug 29, 2015
Semiring Dense operations
View gist:9042715
implicit def opMulMatrix_DM_DV_Semiring[T:Semiring:ClassTag:DefaultArrayValue]:OpMulMatrix.Impl2[DenseMatrix[T], DenseVector[T], DenseVector[T]] = new OpMulMatrix.Impl2[DenseMatrix[T], DenseVector[T], DenseVector[T]] {
implicit val ring = implicitly[Semiring[T]]
override def apply(a: DenseMatrix[T], b: DenseVector[T]) = {
require(a.cols == b.length)
val res = DenseVector.zeros[T](a.rows)
var c = 0
while(c < a.cols) {
var r = 0
while (r < a.rows) {
val v = a(r, c)
View dense vector expand example.scala
@expand
@expand.exclude(Complex, OpMod)
@expand.exclude(BigInt, OpPow)
@expand.valify
implicit def dv_dv_Op[@expand.args(Int, Double, Float, Long, BigInt, Complex) T,
@expand.args(OpAdd, OpSub, OpMulScalar, OpDiv, OpSet, OpMod, OpPow) Op <: OpType]
(implicit @expand.sequence[Op]({_ + _}, {_ - _}, {_ * _}, {_ / _}, {(a,b) => b}, {_ % _}, {_ pow _})
op: BinaryOp[T, T, Op, T]):BinaryOp[DenseVector[T], DenseVector[T], Op, DenseVector[T]] = {
new BinaryOp[DenseVector[T], DenseVector[T], Op, DenseVector[T]] {
def apply(a: DenseVector[T], b: DenseVector[T]): DenseVector[T] = {