Skip to content

Conversation

@milancurcic
Copy link
Member

I attempted to make a generic flatten so that the user doesn't need to do flatten2d. It seems like it will work.

In support of Linear2d (#197)

@milancurcic milancurcic added the enhancement New feature or request label Feb 16, 2025
@milancurcic milancurcic mentioned this pull request Feb 16, 2025
@Riccardo231
Copy link
Collaborator

LGTM


real, allocatable :: gradient(:,:,:)
real, allocatable :: gradient_2d(:,:)
real, allocatable :: gradient_3d(:,:,:)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I thought about that but decided not to make the code even less SOLID

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But here we have a choice between SOLID and less boilerplate, I think I agree that the second one is better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and, most importantly for me, this approach allows for a unified API (only one flatten() for the user).


procedure :: forward_2d
procedure :: forward_3d
generic :: forward => forward_2d, forward_3d
Copy link
Collaborator

@OneAdder OneAdder Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, just make it one method with assumed-rank input?

 pure module subroutine forward(self, input) class(flatten_layer), intent(in out) :: self real, intent(in) :: input(..) select rank(input) rank(2) self % output = pack(input, .true.) rank(3) self % output = pack(input, .true.) rank default error stop "Unsupported rank of input" end select end subroutine forward

It will reduce boilerplate a little

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! If it works, let's do it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@OneAdder
Copy link
Collaborator

Thank you! I'll rebase and test it out!

Copy link
Collaborator

@OneAdder OneAdder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works. Great job!

@milancurcic milancurcic merged commit 4ad75bc into modern-fortran:main Feb 16, 2025
4 checks passed
@milancurcic milancurcic deleted the generic-flatten branch February 16, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

3 participants