Jake Gyllenhaal was almost cast in Ex Machina

Jake Gyllenhaal was almost cast in Alex Garland's 2014 sci-fi thriller Ex Machina.

Garland's directorial debut stars Domhnall Gleeson as a programmer who is chosen to meet his reclusive CEO Nathan - played by Oscar Isaac - and conduct a test on his intelligent humanoid robot Ava, portrayed by Alicia Vikander.

Garland and his longtime producer Andrew Macdonald revealed during a Q&A at the Edinburgh Film Festival in Scotland on Sunday that the money people wanted a bigger name like Gyllenhaal.

"The sales companies wanted us to cast Jake Gyllenhaal because he was bankable and they could sell foreign territories," Macdonald said, reports Deadline. "That would have changed the whole film."

They ultimately had talks with the actor's representatives but the negotiations didn't go very far.

"I remember having a conversation with Jake Gyllenhaal's lawyer about his needs. It was never gonna work," he added.

Macdonald explained that neither Isaac nor Vikander were well known enough at the time to "raise the money through international sales". They eventually decided to partner with Universal studio executives, who had already made films with the two stars and therefore supported their decision to cast them.

"We decided to make the film with Universal International and they had a film with Oscar Isaac, the Coen brothers film (Inside Llewyn Davis), and they believed it would win Oscars, so they thought he was a winner," Macdonald explained. "They also had an Alicia Vikander film that they thought was gonna be a winner as well, so they backed us."

Garland also named Ex Machina as his favourite directorial effort so far. He has since made the films Annihilation, Men and Civil War.