juan_gandhi: (Default)
  private def diagonalize[T](f: Int => T): PartialFunction[(Int, Int), T] =
      { case (i, j) if i == j => f(i) }
juan_gandhi: (Default)
  def Unit(size: Int) = new Matrix.OnFunction(size, size, (i, j) => if (i == j) 1.0 else 0.0)
juan_gandhi: (Default)
Джавасприпт, Хаскель и Скала, и, говорят, OCaml, из-за своей компактности, канают в качестве скриптовых языков.

Питон в этом смысле тоже ничо, но там, во-первых, споткнуться можно много где, во-вторых, на уровне компиляции нам ничего не скажут. Это уже на продакшене ебанется. То-то квора, которая на питоне, деплоится по сто раз в час (а тесты потом гоняют, и кодревью тоже). 
juan_gandhi: (Default)
...for running linear algebra stuff on gpu?

github.com/deeplearning4j/nd4j - for Java
github.com/deeplearning4j/nd4s - for Scala

Judging by the title, got a feeling that yes.
juan_gandhi: (Default)
        val counts = ((0 until 3 map (_ -> 0) toMap) /: (0 until something.length.toInt)) {
          case (c, i) => {
            val k = something.at8(i).toInt
            val v = c(k) + 1
            c + (k -> v)

Just counting. It's a piece of a test, so...
juan_gandhi: (Default)
einführen language.ukrainian

об'єкт  Прикладення

  визначити головне(аргументи: массив стрічок): Пусте =
     надрукувати "Привіт, світ" 

juan_gandhi: (Default)
завелся новый член, Хуй Ли.

Мне нравится. 
juan_gandhi: (Default)
Turned out all the delays were caused by two things:
- reading the files in parallel, as opposed to sequential (don't ask, will investigate)
- parallel output to stdout, instead of linearising the output. That was obviously my mistake, have to group the data, not mix them.

Now it's still 3 times faster than FP version. Got a suspicion that in JVM method dispatch is much heavier than plain if/else. It should be. But it's the staple of FP, never use booleans or ifs, but dispatch by the type. So, well... have to investigate.
juan_gandhi: (Default)
    // Set name from main class if not given
    name = Option(name).orElse(Option(mainClass)).orNull
    if (name == null && primaryResource != null) {
      name = Utils.stripDirectory(primaryResource)

Just a chunk of their funny shitty code.

FYI, var name: String = null

I'd rewrite all that crap, but it's not only code, I'm afraid. It's the whole Spark world that needs a doctor.
juan_gandhi: (VP)
case class a(i:Int)
  override def canEqual(a: Any) = a.isInstanceOf[a]

  override def equals(o:Any) = AnyRef.equals(o)

  override def hashCode = AnyRef.hashCode

val aa = new a(1)
aa == aa //false
juan_gandhi: (VP)
You know the difference in Scala between val f: A=>B and def f(a:A): B?

I do.

The first one is a point in BA; the second one is an arrow from A to B. Yes, there's an adjunction, so there's a 1-1 correspondence, thanks to Yoneda lemma; it's basically a special case of currying.
juan_gandhi: (VP)
Categories for Scala Programmers

Pretty primitive, but well, the target audience... just to dispel some myths and clear the people's conscience.


Oct. 15th, 2016 04:23 pm
juan_gandhi: (VP)
Just slapped together a deck of slides, category theory for scala programmers


Comments wholeheartedly welcome
juan_gandhi: (VP)
В документации по спарку увидел
transformer: DataFrame =[transform]=> DataFrame

Ни хрена не мог понять, а потом понял и шибко оценил. Классно же! Жаль, нельзя так по жизни. Очень жаль.
juan_gandhi: (VP)
   * Returns a Seq of the children of this node.
   * Children should not change. Immutability required for containsChild optimization
  def children: Seq[BaseType]

  lazy val containsChild: Set[TreeNode[_]] = children.toSet

Imagine, we override the class, but our children are not to be mutable. Why t.f. then not declare it val?!

Another masterpiece
object CurrentOrigin {
  private val value = new ThreadLocal[Origin]() {
    override def initialValue: Origin = Origin()

  def get: Origin = value.get()
  def set(o: Origin): Unit = value.set(o)

  def reset(): Unit = value.set(Origin())

  def setPosition(line: Int, start: Int): Unit = {
      value.get.copy(line = Some(line), startPosition = Some(start)))

  def withOrigin[A](o: Origin)(f: => A): A = {
    val ret = try f finally { reset() }

So, we have a static object that wants to do something with a context. (See withOrigin.) That's "dependency injection", Fortran style. And we can do without vars, because, well, it's ThreadLocal.

Who wrote all this... could they hire Scala programmers, I wonder...
juan_gandhi: (VP)
scala> class A[T] { var x:T = _ }
defined class A

scala> val aInt = new A[Int]
aInt: A[Int] = A@36f6e879

scala> aInt.x
res2: Int = 0

  Until you take a closer look:

scala> class A[T] { var x:T = _; println(x) }
defined class A

scala> val aInt = new A[Int]
aInt: A[Int] = A@3fee9989

scala> aInt.x
res3: Int = 0

null magically turns into 0.


juan_gandhi: (Default)

May 2017

  1 23 4 5 6
7 89 1011 1213
14 15 1617 18 19 20
21 222324252627


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2017 09:22 pm
Powered by Dreamwidth Studios