tensor-compiler / taco

The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs
http://tensor-compiler.org
Other
1.23k stars 185 forks source link

Linear Algebra API #39

Open fredrikbk opened 7 years ago

fredrikbk commented 7 years ago

The tensor algebra compiler supports tensor index notation. Tensor index notation can be used to do linear algebra, but for convenience we ought to have a linear algebra API as well.

This API (linalg.h) can be built on top of the current functionality (tensor.h). It should define types (Scalar, Vector, Matrix), facilities for converting between these types and tensors, and the usual linear algebra operations (addition, subtraction, multiplication with scalars, vectors and matrices). The goal is to provide something roughly as convenient as Eigen.

It should also support blocked linear algebra, where the user can define and compute with blocked vectors and matrices (see also #59).

fredrikbk commented 7 years ago

Something along these lines:

#ifndef TACO_LINALG_H
#define TACO_LINALG_H

#include <string>

#include "taco/tensor.h"

namespace taco {

enum VectorType {
  COLUMN,
  ROW
};

template <typename C, VectorType T=COLUMN>
class Vector : public Tensor<C> {
public:
  Vector(std::string name, std::vector<int> dimensions, Format format);
  Vector(std::vector<int> dimensions, Format format);

  Vector<C,T> operator*=(C) {
    taco_not_supported_yet;
  }

  Vector<C,T> operator+=(const Vector<C,T>&) {
    taco_not_supported_yet;
  }

  Vector<C,T> operator-=(const Vector<C,T>&) {
    taco_not_supported_yet;
  }
};

template <typename C>
class Matrix : public Tensor<C> {
public:
  Matrix(std::string name, std::vector<int> dimensions, Format format);
  Matrix(std::vector<int> dimensions, Format format);

  Matrix<C> operator*=(C) {
    taco_not_supported_yet;
  }

  Matrix<C> operator+=(const Matrix<C>&)  {
    taco_not_supported_yet;
  }

  Matrix<C> operator-=(const Matrix<C>&) {
    taco_not_supported_yet;
  }
};

/// Vector Negation
template <typename C, VectorType T>
Vector<C,T> operator-(const Vector<C,T>&)  {
  taco_not_supported_yet;
}

/// Vector Scale
template <typename C, VectorType T>
Vector<C,T> operator*(const Vector<C,T>&, C) {
  taco_not_supported_yet;
}

template <typename C, VectorType T>
Vector<C,T> operator*(C, const Vector<C,T>&) {
  taco_not_supported_yet;
}

/// Vector Addition
template <typename C, VectorType T>
Vector<C,T> operator+(const Vector<C,T>&, const Vector<C,T>&) {
  taco_not_supported_yet;
}

/// Vector Subtraction
template <typename C, VectorType T>
Vector<C,T> operator-(const Vector<C,T>&, const Vector<C,T>&) {
  taco_not_supported_yet;
}

/// Vector inner product.
template <typename T>
T operator*(const Vector<T,ROW>&, const Vector<T>&) {
  taco_not_supported_yet;
}

/// Vector outer product.
template <typename T>
Matrix<T> operator*(const Vector<T>&, const Vector<T,ROW>&) {
  taco_not_supported_yet;
}

/// Matrix Negation
template <typename C>
Matrix<C> operator-(const Matrix<C>&) {
  taco_not_supported_yet;
}

/// Matrix Scale
template <typename T>
Matrix<T> operator*(const Matrix<T>&, T) {
  taco_not_supported_yet;
}

template <typename T>
Matrix<T> operator*(T, const Matrix<T>&) {
  taco_not_supported_yet;
}

/// Vector-Matrix multiplication.
template <typename T>
Vector<T> operator*(const Vector<T,ROW>&, const Matrix<T>&) {
  taco_not_supported_yet;
}

/// Matrix-Vector multiplication.
template <typename T>
Vector<T> operator*(const Matrix<T>&, const Vector<T>&) {
  taco_not_supported_yet;
}

/// Matrix Addition
template <typename T>
Matrix<T> operator+(const Matrix<T>&, const Matrix<T>&) {
  taco_not_supported_yet;
}

/// Matrix Subtraction
template <typename T>
Matrix<T> operator-(const Matrix<T>&, const Matrix<T>&) {
  taco_not_supported_yet;
}

/// Matrix Multiplication.
template <typename T>
Matrix<T> operator*(const Matrix<T>&, const Matrix<T>&) {
  taco_not_supported_yet;
}

}
#endif