Open telegraphic opened 1 year ago
I think having more examples, particularly on the C++ side, is a great idea. I'll see if I can find some time to dig into you questions.
// TODO: What's the deal with check() in Common.hpp?
I'm not sure. It looks to be similar to the BF_CHECK
macro except that it raises an exception on an error rather than just printing a message and passing the return value along.
// TODO: What's the deal with _check in the python wrappers? // Should I be using this in my Python plugins?
_check
in Python either catches some particular kinds of non-BF_STATUS_SUCCESS
return values and converts them to Python exceptions. The exact behavior is determined by whether or not the Python constant __debug__
is True or False.
// Note: Am I using BF_CHECK correctly?
Looks like it. As an alternative you could also use the more C-like:
if( !bfArrayMalloc(&bf_data_y) ) {
printf("bfArrayMalloc failed\n");
}
since BF_STATUS_SUCCESS
is zero.
// Note: looks like BF_ASSERT is more common than BF_CHECK? What's the difference?
BF_ASSERT
throws exceptions in from inside a class method. I think of it as a part of the input validate step in a method, similar to what you would do in Python:
def my_op(input):
assert(input.shape == 2)
input[:,0] += 1
return input
vs.
void my_op(BFarray* input) {
BF_ASSERT(input->ndim == 2, BF_STATUS_INVALID_SHAPE);
for(int i=0; i<input->shape[0]; i++) {
input->data[i*input->shape[1]] += 1;
}
}
(I hope that's the correct syntax there).
BF_CHECK
is meant more for check the return code of a method. My Python example here would be it's like checking the return code on scipy.optimize.leastsq
.
Hi all,
I've been exploring the C++ API a bit recently, and have found it a bit hard going as there's not much documentation (and my C++ needs more time in the dojo).
There is a great little example here already though, on how to use the ring interface: http://ledatelescope.github.io/bifrost/Cpp-Development.html
So I thought we could add a few more examples?
Here's an example code that shows how to use bifrost arrays in C++. The code compiles and does what it's supposed to do, but is simple (on purpose, but if there's 'better' ways lemme know).
I have some questions in the comments, would be good if someone could help fill these in!
(PS: It would also be good if we had these in an
examples
directory/repo, that the user can compile)