#include "matmul.h"
#include "../tensor.h"
#include "../utils.h"
#include <torch/torch.h>

namespace TensorOps {

Napi::Value Matmul(Tensor* self, const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();

  if (info.Length() < 1) {
    Napi::TypeError::New(env, "Expected at least 1 argument").ThrowAsJavaScriptException();
    return env.Null();
  }

  if (!info[0].IsObject()) {
    Napi::TypeError::New(env, "Expected Tensor argument").ThrowAsJavaScriptException();
    return env.Null();
  }

  Tensor* other = Napi::ObjectWrap<Tensor>::Unwrap(info[0].As<Napi::Object>());
  torch::Tensor result = self->tensor.matmul(other->tensor);

  return Tensor::NewInstance(env, result);
}

}  // namespace TensorOps
