Skip to content

Commit

Permalink
Merge pull request #8104 from asi1024/fix-flags
Browse files Browse the repository at this point in the history
Fix Flags not to allow setters
  • Loading branch information
emcastillo committed Jan 24, 2024
2 parents 3ab6976 + 6db6007 commit 710257a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cupy/_core/flags.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
class Flags(object):

def __init__(self, c_contiguous, f_contiguous, owndata):
self.c_contiguous = c_contiguous
self.f_contiguous = f_contiguous
self.owndata = owndata
self._c_contiguous = c_contiguous
self._f_contiguous = f_contiguous
self._owndata = owndata

@property
def c_contiguous(self):
return self._c_contiguous

@property
def f_contiguous(self):
return self._f_contiguous

@property
def owndata(self):
return self._owndata

@property
def fnc(self):
Expand Down
22 changes: 22 additions & 0 deletions tests/cupy_tests/core_tests/test_flags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import unittest

import numpy
import pytest

import cupy
from cupy._core import flags
from cupy import testing

Expand Down Expand Up @@ -65,3 +69,21 @@ def test_f_contiguous(self, xp):
def test_c_contiguous(self, xp):
self.init_flags(xp)
return self.flags.c_contiguous

def test_c_contiguous_setter(self):
for xp in (numpy, cupy):
self.init_flags(xp)
with pytest.raises(AttributeError):
self.flags.c_contiguous = True

def test_f_contiguous_setter(self):
for xp in (numpy, cupy):
self.init_flags(xp)
with pytest.raises(AttributeError):
self.flags.f_contiguous = True

def test_owndata_setter(self):
for xp in (numpy, cupy):
self.init_flags(xp)
with pytest.raises(AttributeError):
self.flags.owndata = True

0 comments on commit 710257a

Please sign in to comment.