Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixerr #2119

Closed
wsmoses opened this issue Nov 24, 2024 · 0 comments
Closed

Mixerr #2119

wsmoses opened this issue Nov 24, 2024 · 0 comments

Comments

@wsmoses
Copy link
Member

wsmoses commented Nov 24, 2024

using Enzyme, Test

Enzyme.API.printall!(true)

concat() = ()
concat(a) = a
concat(a, b) = (a..., b...)
concat(a, b, c...) = concat(concat(a, b), c...)

function make_byref(out, arg)
	res = 0.0
    x = concat(arg...)
    #x = concat(arg[1], arg[2])
	for v in x
		v = v::Tuple{Float64, Vector{Float64}}
		res += v[1]
	end
    out[] = res
	nothing
end

function tupapprox(a, b)
	if a isa Tuple && b isa Tuple
		if length(a) != length(b)
			return false
		end
		for (aa, bb) in zip(a, b)
			if !tupapprox(aa, bb)
				return false
			end
		end
		return true
	end
	if a isa Array && b isa Array
		if size(a) != size(b)
			return false
		end
		for i in length(a)
			if !tupapprox(a[i], b[i])
				return false
			end
		end
		return true
	end
	return a  b
end

    x = [[(2.0, [2.7]), (3.0, [3.14])], [(7.9, [47.0]), (11.2, [56.0])]]

    make_byref(Ref(0.0), x)

    dx = [[(0.0, [0.0]), (0.0, [0.0])], [(0.0, [0.0]), (0.0, [0.0])]]
    dx2 = [[(0.0, [0.0]), (0.0, [0.0])], [(0.0, [0.0]), (0.0, [0.0])]]

    out = Ref(0.0)
    dout = Ref(1.0)
    dout2 = Ref(3.0)
    Enzyme.autodiff(Reverse, make_byref, Const, BatchDuplicatedNoNeed(out, (dout, dout2)), BatchDuplicated(x, (dx, dx2)))
@wsmoses wsmoses closed this as completed Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant