Tuesday, August 27, 2019

Scala ArrowAssoc

https://stackoverflow.com/questions/4980515/scala-maps-operator/4980734

implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)
This will convert any type into an instance of "ArrowAssoc"
class ArrowAssoc[A](x: A) {
    def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y)
}
So when Scala sees 
"a"->1
It says "There is no method named '->' on String. Are there any implicit conversions in scope that can give me a type that has a method named '->'?" Predef.scala is automatically in scope, and offers a conversion to ArrowAssoc, which obviously has the '->' method. Scala then essentially converts the above to
any2ArrowAssoc("a").->(1)
This method returns a Tuple2("a", 1) (often called a Pair). Map has a constructor that thats an array (varargs) of Tuple2s, so we're off to races! No magic in the compiler (besides implicit conversion, which is used extensively and for many different purposes), and no magic in Maps constructor.

Thursday, August 1, 2019

Instructions for the C++ Torch installation modified for the Mac

https://github.com/intel/mkl-dnn/releases
https://github.com/intel/mkl-dnn

https://intel.github.io/mkl-dnn/dev_guide_build.html

Linux/macOS

  • Generate makefile: 
    mkdir -p build && cd build && cmake ..
  • Build the library: 
    make -j
  • Build the documentation: 
    make doc
  • Install the library, headers, and documentation: 
    make install
git clone https://github.com/intel/mkl-dnn.git
cd mkl-dnn/
mkdir -p build && cd build && cmake ..
make -j
make doc
make install

Validate the Build

Run unit tests:
ctest


// add this env var to your .bash_profile file

export Torch_DIR=$USER/libtorch

// HACK ALERT
// https://github.com/pytorch/pytorch/issues/14727#issuecomment-516575929

wget https://github.com/intel/mkl-dnn/releases/download/v0.20-rc/mklml_mac_2019.0.5.20190502.tgz
mv ~/Downloads//mklml_mac_2019.0.5.20190502.tar .
tar xvf mklml_mac_2019.0.5.20190502.tar


wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-macos-latest.zip
unzip libtorch-macos-latest.zip 
cd build/
source ~/.bash_profile
cd ..
mv first_example.cc first_example.cpp
cd build

cmake -DCMAKE_PREFIX_PATH=~/libtorch ..

~/torch/build
./first_example 
 0.9762  0.1762  0.9328
 0.5004  0.3410  0.1637
 0.3285  0.0761  0.6350
[ Variable[CPUFloatType]{3,3} ]
 0.9762  0.1762  0.9328
 0.5004  0.3410  0.1637
 0.3285  0.0761  0.6350

[ Variable[CPUFloatType]{3,3} ]



https://github.com/zdevito/ATen/tree/master/aten/src