FTorch icon indicating copy to clipboard operation
FTorch copied to clipboard

Overload elementary operations

Open joewallwork opened this issue 1 year ago • 3 comments

Closes #138.

joewallwork avatar Jun 21 '24 08:06 joewallwork

This seems sensible, and impressive 😄 What is the argument for making torch_tensor_from_array() no longer return a value but instead operate internally? We can chat over lunch.

jatkinson1000 avatar Jun 21 '24 10:06 jatkinson1000

This seems sensible, and impressive 😄 What is the argument for making torch_tensor_from_array() no longer return a value but instead operate internally? We can chat over lunch.

Thanks!

If you overload the assignment operator then tensor = torch_tensor_from_array(...) will call torch_tensor_from_array with the provided arguments and then call torch_tensor_assign, copying that into tensor. If this and other constructor-type procedures go from being functions to subroutines then we avoid unnecessary data copies.

joewallwork avatar Jun 21 '24 11:06 joewallwork

I created a new branch autograd_toarray off this one and merged in changes from #161. Can confirm the tests pass!

joewallwork avatar Jul 29 '24 11:07 joewallwork

Got round to updating this branch. The simplest thing to do was to merge main into it, so it should be merged with squash.

joewallwork avatar Oct 31 '24 12:10 joewallwork

As discussed in today's meeting, we should check what happens if an operator that hasn't been implemented is used. I switched from Q = 3 * a ** 3 - b ** 2 to Q = 3 * a ** b - b ** 2, i.e., take a tensor to the power of another tensor, rather than to the power of a scalar. I get the following compile error, which seems clear enough:

Scanning dependencies of target autograd
[ 91%] Building Fortran object test/examples/6_Autograd/CMakeFiles/autograd.dir/autograd.f90.o
/home/joe/software/FTorch/src/test/examples/6_Autograd/autograd.f90:54:14:

   54 |   Q = 3 * a ** b - b ** 2
      |              1
Error: Unexpected derived-type entities in binary intrinsic numeric operator ‘**’ at (1)

joewallwork avatar Nov 04 '24 10:11 joewallwork

Merged in the Windows fix from #207.

joewallwork avatar Dec 18 '24 10:12 joewallwork