myFM icon indicating copy to clipboard operation
myFM copied to clipboard

Segmentation fault (core dumped)

Open ahojukka5 opened this issue 1 year ago • 1 comments

Trying out toy model from documentation causes segmentation fault.

import myfm
from sklearn.feature_extraction import DictVectorizer
import numpy as np
train = [
    {"user": "1", "item": "5", "age": 19},
    {"user": "2", "item": "43", "age": 33},
    {"user": "3", "item": "20", "age": 55},
    {"user": "4", "item": "10", "age": 20},
]
v = DictVectorizer()

X = v.fit_transform(train)

# Note that X is a sparse matrix
print(X.toarray())

# The target variable to be classified.
y = np.asarray([0, 1, 1, 0])
fm = myfm.MyFMClassifier(rank=4)
print("fit")
fm.fit(X,y)
print("fit done")

# It also supports prediction for new unseen items.
fm.predict_proba(v.transform([{"user": "1", "item": "10", "age": 24}]))
$ python test.py 
[[19.  0.  0.  0.  1.  1.  0.  0.  0.]
 [33.  0.  0.  1.  0.  0.  1.  0.  0.]
 [55.  0.  1.  0.  0.  0.  0.  1.  0.]
 [20.  1.  0.  0.  0.  0.  0.  0.  1.]]
fit
  0%|                                                                                                                                         | 0/100 [00:00<?, ?it/s]Segmentation fault (core dumped)

ahojukka5 avatar Aug 12 '24 15:08 ahojukka5

@ahojukka5 Sorry for the late reply! And thanks for reporting the problem. I was able to reproduce the issue.

It appears that the problem occurs in myFM with numpy version >= 2.0.0. Could you try downgrading numpy to 1.x.x? I will try to solve the problem when I have time.

tohtsky avatar Nov 12 '24 04:11 tohtsky

It took a long time, but myFM 0.4.0, which is numpy 2.0 ABI compatible, has been released!

tohtsky avatar Jul 11 '25 15:07 tohtsky