字节和按位运算符

时间:2018-08-19 11:44:06

标签: compiler-errors kotlin byte bitwise-operators

我测试了代码:

val a : Int = 0x01
val b : Int = 0x03
println(a and b)

并得到:

1

但是如果我声明为Byte

val a : Byte = 0x01
val b : Byte = 0x03
println(a and b)

得到错误:

error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@SinceKotlin @InlineOnly public inline infix fun BigInteger.and(other: BigInteger): BigInteger defined in kotlin
println(a and b)
          ^

我发现引用:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.experimental/and.html说:

  

平台和版本要求:Kotlin 1.1

我检查了我的版本:

C:\>kotlinc.bat -version
info: kotlinc-jvm 1.2.30 (JRE 1.8.0_181-b13)

这是什么意思?

1 个答案:

答案 0 :(得分:5)

您缺少导入语句:

import torch 
import torchvision
from torchvision import transforms
from torch.utils.data import DataLoader

import time
import matplotlib.pyplot as plt

def ShowImage(imag):      
    temp=imag.view(3,96,96)
    temp=temp.cpu()
    temp =transforms.functional.to_pil_image(temp)
    plt.imshow(temp)
    plt.show()

path =  '/home/Machine Learning/Datasets'  
start = time.time()

# ToTensor = transforms.Compose([transforms.ToTensor()])
# train_data= torchvision.datasets.STL10(path ,
#                                        split='train'
#                                      ,transform=ToTensor) 
# test_data= torchvision.datasets.STL10(path ,
#                                        split='test'
#                                      ,transform=ToTensor) 
# dataloader_train = DataLoader(train_data,batch_size=1,shuffle=True)
for i,batch in enumerate(dataloader_train):
    imag,label =batch
    ShowImage(imag)
    if(i>10):
        break

end = time.time()
print(end - start)
#output 0.6654326915740967

没有导入,编译器将尝试使用在import kotlin.experimental.and 中找到的and