-
Notifications
You must be signed in to change notification settings - Fork 7
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
Added a simple function that reads arrays instead of a file #3
base: main
Are you sure you want to change the base?
Conversation
Added array insert instead of file.
Read an arrays instead of a file.
io.go
Outdated
@@ -31,3 +31,16 @@ func ReadSignalFile(path string, sampleRate float64) (*Signal, error) { | |||
} | |||
return &signal, scanner.Err() | |||
} | |||
// Function allows for reading arrays | |||
func ReadArray(dataArray []float64, sampleRate float64) (*Signal, error){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to copy the array or can it be like below?
signal := Signal{
SampleRate: sampleRate,
Signal: dataArray,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah instantiating it would work also!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have to call the type from a different part of the application to update Signal var. I guess totally do able.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! If you make the change then Ill mergar this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure i pushed to the right folder! Been a long week, sorry for the delay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like this should work,
func CreateSignalFromArray(signal []float64, sampleRate float64) *Signal {
return &Signal{
SampleRate: sampleRate,
Signal: signal,
}
}
- Replaced the return with &Signal instead of (&Signal, error) since there isn't any error returned
- You can use the array directly, no need to copy the values.
- Changed to name "signal" since I think the go-lang best practice is not to have type name on variables (like dataArray).
This is using the same array as the one that is inserted, if you want to use a deep copy you can use something like
cpy := make([]float64, len(data))
copy(cpy, data)
Fairly simple. Just figured I add it if someone else wanted it. May not be be the right approach. But, nice library! Cant wait to learn more about it!