romeric / Fastor

A lightweight high performance tensor algebra framework for modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seg Fault when attempting broadcast.

hughack opened this issue · comments

I am trying to add a vector to a matrix, and broadcast the addition across all vectors. I'd like something like this:

Tensor<double,3> vec = {1,2,3};      // a vector
Tensor<double,2,2,3> A(0);           // 3D tensor of all zeros 

A = A + vec

and get

[0,:,:]
[1, 2, 3]
[1, 2, 3]
[1,:,:]
[1, 2, 3]
[1, 2, 3]

I read #108 and saw you mention the only way to do it is with for loops, so i tried this as a naive implementation:

for(int i = 0; i < 2; i++)
    for(int j = 0; j < 2; j++)
        A(i, j, Fastor::all) = vec;

It works in this case. I wanted to see how it performed on a larger matrix, the task i'm trying to work on uses 1000x1000x3. When i run this:

#include <Fastor/Fastor.h>

int main() {
  Fastor::Tensor<double,3> vec = {1,2,3};
  Fastor::Tensor<double,1000,1000,3> A(0);

  for(int i = 0; i < 1000; i++)
    for(int j = 0; j < 1000; j++)
        A(i, j, Fastor::all) = vec;

  return 0;
}

I get a segmentation fault - am i doing it completely wrong or is there some issue going on? Do you have a recommended way of achieving this?

commented

This issue has been covered multiple times in the past. Fastor tensors are stack-allocated (not on heap) and your machine does not have that much stack memory. Fastor is not designed for that big of a tensors.

I would close this.