Can capital losses in equity incurred as a non resident be set off against capital gains made as a resident

Let's say I sell some US stocks through my brokerage firm this year (2023) as a non-resident alien and incur long term capital losses (LTCL). Now, let's assume that I become a US resident (for tax purposes) in the year 2025, and make some long term capital gains (LTCG) in the same year.

 

Question:  Would I be able to offset the losses incurred in 2023 against these gains made in 2025?

 

PS : There's no tax on capital gains through stocks/mfs/etfs imposed on non-resident aliens. So, I'm not sure how my capital losses in 2023 would be recorded with the IRS.