hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.53k stars 313 forks source link

Error: specializing member ‘hmdf::DataFrame<int, hmdf::HeteroVector<0> >::set_lock’ requires ‘template<>’ syntax| #252

Closed sierret closed 1 year ago

sierret commented 1 year ago

Hi. I'm using this in a multi-threaded environment and was trying to use the locks you built in/included out of the box but I get an error(in the title). I'm also trying to use the lock as a global variable if that makes a difference for access across multiple files if that makes a difference although I doubt it does.

The idea is I'm trying to protect the df in a multi-threaded environment. I'm assuming spinlock is suitable.

Code looks like:

using namespace hmdf; using MyDataFrame = StdDataFrame[int];

SpinLock lock; MyDataFrame::set_lock(&lock); MyDataFrame df;

If column types are needed, df will be populated with columns in order: int(index col),double,float,float,float. Thanks in advance for any assistance.

Additionally, kindly, please consider adding basic SpinLock/SpinGuard/etc lock usage examples to docs so users don't have to dig through source code. That's very user-unfriendly to beginners.

UPDATE: fixed - see comment below

sierret commented 1 year ago

FIXED: moved code inside main. I was using a header file to declare global vars. Still, perhaps you could still look into this undefined behaviour(as I call it), as the docs certainly didn't require a template for set::lock.

Thanks for your time nevertheless.

hosseinmoein commented 1 year ago

If I understand correctly and from your code snippet above

using MyDataFrame = StdDataFrame;

is not a well-defined type, because StdDataFrame requires one mandatory template argument -- index type. So you need something like:

using MyDataFrame = StdDataFrame<long>;

to be will-defined

hosseinmoein commented 1 year ago

I still don't see a type!

sierret commented 1 year ago

I understand.

I used the exact line you typed but I realise now everytime I type it in and hit Comment, the type and the angle brackets gets removed from the posted comment. I don't know why, it may have to do with my Grammarly addon. But I did indeed use the exact like you outlined with the type in the angle brackets and still no dice.

sierret commented 1 year ago

To clarify, I did indeed use

using MyDataFrame = StdDataFrame[int]; //assume [] are angle brackets because I have no idea why Github won't let me comment using that

Yet, I still received this error.

hosseinmoein commented 1 year ago

and how did you fix it? by moving the code from header file to a .cc file?

sierret commented 1 year ago

I moved only the line

`MyDataFrame::set_lock(&lock);

from` header file to main() in .cpp file. The rest of the code above stayed in the header file that I include at the top of the .cpp file.

sierret commented 1 year ago

Also, to clarify, since the set_lock is static, the lock can be set after the MyDataFrame df is declared and also works across all instances of MyDataFrame?

hosseinmoein commented 1 year ago

correct