/* Copyright 2014. The Regents of the University of California.
 * Copyright 2016-2018. Martin Uecker.
 * Copyright 2024-2025. Institute of Biomedical Imaging. TU Graz.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 */

#include <complex.h>

#include "misc/misc.h"

#include "num/flpmath.h"
#include "num/multind.h"

#include "linops/linop.h"

#include "realval.h"


struct rvc_s {

	linop_data_t super;

	int N;
	const long* dims;
};

static DEF_TYPEID(rvc_s);


static void rvc_apply(const linop_data_t* _data, complex float* dst, const complex float* src)
{
	const auto data = CAST_DOWN(rvc_s, _data);

	md_zreal(data->N, data->dims, dst, src);
}

static void rvc_free(const linop_data_t* _data)
{
	const auto data = CAST_DOWN(rvc_s, _data);

	xfree(data->dims);
	xfree(data);
}

struct linop_s* linop_realval_create(int N, const long dims[N])
{
	PTR_ALLOC(struct rvc_s, data);
	SET_TYPEID(rvc_s, data);

	PTR_ALLOC(long[N], dims2);
	md_copy_dims(N, *dims2, dims);

	data->N = N;
	data->dims = *PTR_PASS(dims2);

	return linop_create(N, dims, N, dims, CAST_UP(PTR_PASS(data)), rvc_apply, rvc_apply, rvc_apply, NULL, rvc_free);
}


