最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

julia - Implementation of ComplexInt16 type - Stack Overflow

matteradmin8PV0评论

I have a large binary file with interleaved Int16 values representing the real and imaginary parts of each sample. Letting S_i represent the sample number i, the data is arranged as

[Re(S_1), Im(S_1), Re(S_2), Im(S_2), ...]

My thought was to define a custom ComplexInt16 type and operate on that. I produced the code below:

struct ComplexInt16
    re::Int16
    im::Int16
end

filehandle = open("y_baseband.dat")
dh = mmap(filehandle, Vector{ComplexInt16})

The code above functions as expected, but I am unable to use functions that are defined for complex numbers (e.g. real(dh[1]) returns an error.) Is there a way to have my ComplexInt16 type work with the existing Complex functions within Julia?

I have a large binary file with interleaved Int16 values representing the real and imaginary parts of each sample. Letting S_i represent the sample number i, the data is arranged as

[Re(S_1), Im(S_1), Re(S_2), Im(S_2), ...]

My thought was to define a custom ComplexInt16 type and operate on that. I produced the code below:

struct ComplexInt16
    re::Int16
    im::Int16
end

filehandle = open("y_baseband.dat")
dh = mmap(filehandle, Vector{ComplexInt16})

The code above functions as expected, but I am unable to use functions that are defined for complex numbers (e.g. real(dh[1]) returns an error.) Is there a way to have my ComplexInt16 type work with the existing Complex functions within Julia?

Share Improve this question edited Nov 18, 2024 at 12:49 Dawson Beatty asked Nov 18, 2024 at 12:46 Dawson BeattyDawson Beatty 6863 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

why not just use Complex{Int16}?

Post a comment

comment list (0)

  1. No comments so far